diff --git a/src/Collection/ProfileFields.php b/src/Collection/ProfileFields.php index e171b839b2..223c3ec148 100644 --- a/src/Collection/ProfileFields.php +++ b/src/Collection/ProfileFields.php @@ -6,5 +6,12 @@ use Friendica\BaseCollection; class ProfileFields extends BaseCollection { - + /** + * @param callable $callback + * @return ProfileFields + */ + public function map(callable $callback) + { + return parent::map($callback); + } } diff --git a/src/Model/ProfileField.php b/src/Model/ProfileField.php index 51b43e33c8..e4192a9809 100644 --- a/src/Model/ProfileField.php +++ b/src/Model/ProfileField.php @@ -3,6 +3,9 @@ namespace Friendica\Model; use Friendica\BaseModel; +use Friendica\Database\Database; +use Friendica\Network\HTTPException; +use Psr\Log\LoggerInterface; /** * Custom profile field model class. @@ -17,8 +20,40 @@ use Friendica\BaseModel; * @property string value * @property string created * @property string edited + * @property PermissionSet permissionset */ class ProfileField extends BaseModel { + /** @var PermissionSet */ + private $permissionset; + /** @var \Friendica\Repository\PermissionSet */ + private $permissionSetRepository; + + public function __construct(Database $dba, LoggerInterface $logger, \Friendica\Repository\PermissionSet $permissionSetRepository, array $data = []) + { + parent::__construct($dba, $logger, $data); + + $this->permissionSetRepository = $permissionSetRepository; + } + + public function __get($name) + { + $this->checkValid(); + + switch ($name) { + case 'permissionset': + $this->permissionset = + $this->permissionset ?? + $this->permissionSetRepository->selectFirst(['id' => $this->psid, 'uid' => $this->uid]); + + $return = $this->permissionset; + break; + default: + $return = parent::__get($name); + break; + } + + return $return; + } } diff --git a/src/Repository/ProfileField.php b/src/Repository/ProfileField.php index 21fd2da7c8..d04104898a 100644 --- a/src/Repository/ProfileField.php +++ b/src/Repository/ProfileField.php @@ -5,9 +5,10 @@ namespace Friendica\Repository; use Friendica\BaseModel; use Friendica\BaseRepository; use Friendica\Collection; +use Friendica\Database\Database; use Friendica\Model; -use Friendica\Model\PermissionSet; use Friendica\Util\DateTimeFormat; +use Psr\Log\LoggerInterface; class ProfileField extends BaseRepository { @@ -17,13 +18,23 @@ class ProfileField extends BaseRepository protected static $collection_class = Collection\ProfileFields::class; + /** @var PermissionSet */ + private $permissionSet; + + public function __construct(Database $dba, LoggerInterface $logger, PermissionSet $permissionSet) + { + parent::__construct($dba, $logger); + + $this->permissionSet = $permissionSet; + } + /** * @param array $data * @return Model\ProfileField */ protected function create(array $data) { - return new Model\ProfileField($this->dba, $this->logger, $data); + return new Model\ProfileField($this->dba, $this->logger, $this->permissionSet, $data); } /** @@ -84,7 +95,9 @@ class ProfileField extends BaseRepository */ public function selectByContactId(int $cid, int $uid) { - $psids = PermissionSet::get($uid, $cid); + $permissionSets = $this->permissionSet->selectByContactId($cid, $uid); + + $psids = $permissionSets->column('id'); // Includes public custom fields $psids[] = 0;