mirror of
https://github.com/friendica/friendica
synced 2024-11-19 23:03:41 +00:00
Move ProfileField::selectByContactId() and ProfileField::selectByUserId()
This commit is contained in:
parent
a9981c792e
commit
6f692b857b
5 changed files with 49 additions and 44 deletions
|
@ -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) {
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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']]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue