From 6f692b857b06fb9f5ef05db9bb3d5f272632986b Mon Sep 17 00:00:00 2001 From: Philipp Date: Fri, 8 Oct 2021 20:01:09 +0200 Subject: [PATCH] Move ProfileField::selectByContactId() and ProfileField::selectByUserId() --- src/Module/Profile/Profile.php | 4 +- src/Module/Settings/Profile/Index.php | 4 +- .../ProfileField/Depository/ProfileField.php | 47 +++++++++++++++++-- src/Protocol/ActivityPub/Transmitter.php | 2 +- src/Repository/ProfileField.php | 36 -------------- 5 files changed, 49 insertions(+), 44 deletions(-) diff --git a/src/Module/Profile/Profile.php b/src/Module/Profile/Profile.php index 25b6eccc9a..1b8ca34357 100644 --- a/src/Module/Profile/Profile.php +++ b/src/Module/Profile/Profile.php @@ -213,9 +213,9 @@ class Profile extends BaseProfile $contact_id = $view_as_contact_id ?: $remote_contact_id ?: 0; if ($is_owner && $contact_id === 0) { - $profile_fields = DI::profileField()->selectByUserId($profile['uid']); + $profile_fields = DI::profileFieldNew()->selectByUserId($profile['uid']); } else { - $profile_fields = DI::profileField()->selectByContactId($contact_id, $profile['uid']); + $profile_fields = DI::profileFieldNew()->selectByContactId($contact_id, $profile['uid']); } foreach ($profile_fields as $profile_field) { diff --git a/src/Module/Settings/Profile/Index.php b/src/Module/Settings/Profile/Index.php index a7b71851df..1ab3e32fc2 100644 --- a/src/Module/Settings/Profile/Index.php +++ b/src/Module/Settings/Profile/Index.php @@ -100,7 +100,7 @@ class Index extends BaseSettings $homepage = 'http://' . $homepage; } - $profileFields = DI::profileField()->selectByUserId(local_user()); + $profileFields = DI::profileFieldNew()->selectByUserId(local_user()); $profileFields = DI::profileField()->updateCollectionFromForm( local_user(), @@ -159,7 +159,7 @@ class Index extends BaseSettings $custom_fields = []; - $profileFields = DI::profileField()->selectByUserId(local_user()); + $profileFields = DI::profileFieldNew()->selectByUserId(local_user()); foreach ($profileFields as $profileField) { /** @var ProfileField $profileField */ $defaultPermissions = $profileField->permissionSet->withAllowedContacts( diff --git a/src/Profile/ProfileField/Depository/ProfileField.php b/src/Profile/ProfileField/Depository/ProfileField.php index 47abcbd145..9ec2d4fb45 100644 --- a/src/Profile/ProfileField/Depository/ProfileField.php +++ b/src/Profile/ProfileField/Depository/ProfileField.php @@ -8,7 +8,7 @@ use Friendica\Network\HTTPException\NotFoundException; use Friendica\Profile\ProfileField\Factory; use Friendica\Profile\ProfileField\Entity; use Friendica\Profile\ProfileField\Collection; -use Friendica\Security\PermissionSet\Depository\PermissionSet; +use Friendica\Security\PermissionSet\Depository\PermissionSet as PermissionSetDepository; use Psr\Log\LoggerInterface; class ProfileField extends BaseDepository @@ -18,9 +18,14 @@ class ProfileField extends BaseDepository protected static $table_name = 'profile_field'; - public function __construct(Database $database, LoggerInterface $logger, Factory\ProfileField $factory) + /** @var PermissionSetDepository */ + protected $permissionSetDepository; + + public function __construct(Database $database, LoggerInterface $logger, Factory\ProfileField $factory, PermissionSetDepository $permissionSetDepository) { parent::__construct($database, $logger, $factory); + + $this->permissionSetDepository = $this->permissionSetDepository; } /** @@ -50,7 +55,43 @@ class ProfileField extends BaseDepository { return $this->select([ 'uid' => $uid, - 'psid' => PermissionSet::PUBLIC, + 'psid' => PermissionSetDepository::PUBLIC, ]); } + + /** + * @param int $uid Field owner user Id + * + * @throws \Exception + */ + public function selectByUserId(int $uid): Collection\ProfileFields + { + return $this->select( + ['uid' => $uid], + ['order' => ['order']] + ); + } + + /** + * Retrieve all custom profile field a given contact is able to access to, including public profile fields. + * + * @param int $cid Private contact id, must be owned by $uid + * @param int $uid Field owner user id + * + * @throws \Exception + */ + public function selectByContactId(int $cid, int $uid): Collection\ProfileFields + { + $permissionSets = $this->permissionSetDepository->selectByContactId($cid, $uid); + + $permissionSetIds = $permissionSets->column('id'); + + // Includes public custom fields + $permissionSetIds[] = PermissionSetDepository::PUBLIC; + + return $this->select( + ['uid' => $uid, 'psid' => $permissionSetIds], + ['order' => ['order']] + ); + } } diff --git a/src/Protocol/ActivityPub/Transmitter.php b/src/Protocol/ActivityPub/Transmitter.php index e741789dad..462460350e 100644 --- a/src/Protocol/ActivityPub/Transmitter.php +++ b/src/Protocol/ActivityPub/Transmitter.php @@ -381,7 +381,7 @@ class Transmitter $custom_fields = []; - foreach (DI::profileField()->selectByContactId(0, $uid) as $profile_field) { + foreach (DI::profileFieldNew()->selectByContactId(0, $uid) as $profile_field) { $custom_fields[] = [ 'type' => 'PropertyValue', 'name' => $profile_field->label, diff --git a/src/Repository/ProfileField.php b/src/Repository/ProfileField.php index 878c6b2b4b..c7fe74ea1a 100644 --- a/src/Repository/ProfileField.php +++ b/src/Repository/ProfileField.php @@ -103,43 +103,7 @@ class ProfileField extends BaseRepository return parent::selectByBoundaries($condition, $params, $min_id, $max_id, $limit); } - /** - * @param int $uid Field owner user Id - * - * @return \Friendica\Profile\ProfileField\Collection\ProfileFields - * @throws \Exception - */ - public function selectByUserId(int $uid) - { - return $this->select( - ['uid' => $uid], - ['order' => ['order']] - ); - } - /** - * Retrieve all custom profile field a given contact is able to access to, including public profile fields. - * - * @param int $cid Private contact id, must be owned by $uid - * @param int $uid Field owner user id - * - * @return \Friendica\Profile\ProfileField\Collection\ProfileFields - * @throws \Exception - */ - public function selectByContactId(int $cid, int $uid) - { - $permissionSets = $this->permissionSet->selectByContactId($cid, $uid); - - $psids = $permissionSets->column('id'); - - // Includes public custom fields - $psids[] = 0; - - return $this->select( - ['uid' => $uid, 'psid' => $psids], - ['order' => ['order']] - ); - } /** * @param array $fields