Move ProfileField::selectByContactId() and ProfileField::selectByUserId()

This commit is contained in:
Philipp Holzer 2021-10-08 20:01:09 +02:00
parent a9981c792e
commit 6f692b857b
Signed by: nupplaPhil
GPG key ID: 24A7501396EB5432
5 changed files with 49 additions and 44 deletions

View file

@ -213,9 +213,9 @@ class Profile extends BaseProfile
$contact_id = $view_as_contact_id ?: $remote_contact_id ?: 0; $contact_id = $view_as_contact_id ?: $remote_contact_id ?: 0;
if ($is_owner && $contact_id === 0) { if ($is_owner && $contact_id === 0) {
$profile_fields = DI::profileField()->selectByUserId($profile['uid']); $profile_fields = DI::profileFieldNew()->selectByUserId($profile['uid']);
} else { } 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) { foreach ($profile_fields as $profile_field) {

View file

@ -100,7 +100,7 @@ class Index extends BaseSettings
$homepage = 'http://' . $homepage; $homepage = 'http://' . $homepage;
} }
$profileFields = DI::profileField()->selectByUserId(local_user()); $profileFields = DI::profileFieldNew()->selectByUserId(local_user());
$profileFields = DI::profileField()->updateCollectionFromForm( $profileFields = DI::profileField()->updateCollectionFromForm(
local_user(), local_user(),
@ -159,7 +159,7 @@ class Index extends BaseSettings
$custom_fields = []; $custom_fields = [];
$profileFields = DI::profileField()->selectByUserId(local_user()); $profileFields = DI::profileFieldNew()->selectByUserId(local_user());
foreach ($profileFields as $profileField) { foreach ($profileFields as $profileField) {
/** @var ProfileField $profileField */ /** @var ProfileField $profileField */
$defaultPermissions = $profileField->permissionSet->withAllowedContacts( $defaultPermissions = $profileField->permissionSet->withAllowedContacts(

View file

@ -8,7 +8,7 @@ use Friendica\Network\HTTPException\NotFoundException;
use Friendica\Profile\ProfileField\Factory; use Friendica\Profile\ProfileField\Factory;
use Friendica\Profile\ProfileField\Entity; use Friendica\Profile\ProfileField\Entity;
use Friendica\Profile\ProfileField\Collection; use Friendica\Profile\ProfileField\Collection;
use Friendica\Security\PermissionSet\Depository\PermissionSet; use Friendica\Security\PermissionSet\Depository\PermissionSet as PermissionSetDepository;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
class ProfileField extends BaseDepository class ProfileField extends BaseDepository
@ -18,9 +18,14 @@ class ProfileField extends BaseDepository
protected static $table_name = 'profile_field'; 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); parent::__construct($database, $logger, $factory);
$this->permissionSetDepository = $this->permissionSetDepository;
} }
/** /**
@ -50,7 +55,43 @@ class ProfileField extends BaseDepository
{ {
return $this->select([ return $this->select([
'uid' => $uid, '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']]
);
}
} }

View file

@ -381,7 +381,7 @@ class Transmitter
$custom_fields = []; $custom_fields = [];
foreach (DI::profileField()->selectByContactId(0, $uid) as $profile_field) { foreach (DI::profileFieldNew()->selectByContactId(0, $uid) as $profile_field) {
$custom_fields[] = [ $custom_fields[] = [
'type' => 'PropertyValue', 'type' => 'PropertyValue',
'name' => $profile_field->label, 'name' => $profile_field->label,

View file

@ -103,43 +103,7 @@ class ProfileField extends BaseRepository
return parent::selectByBoundaries($condition, $params, $min_id, $max_id, $limit); 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 * @param array $fields