3 namespace Friendica\Repository;
5 use Friendica\BaseModel;
6 use Friendica\BaseRepository;
7 use Friendica\Collection;
8 use Friendica\Database\Database;
10 use Friendica\Util\DateTimeFormat;
11 use Psr\Log\LoggerInterface;
13 class ProfileField extends BaseRepository
15 protected static $table_name = 'profile_field';
17 protected static $model_class = Model\ProfileField::class;
19 protected static $collection_class = Collection\ProfileFields::class;
21 /** @var PermissionSet */
22 private $permissionSet;
24 public function __construct(Database $dba, LoggerInterface $logger, PermissionSet $permissionSet)
26 parent::__construct($dba, $logger);
28 $this->permissionSet = $permissionSet;
33 * @return Model\ProfileField
35 protected function create(array $data)
37 return new Model\ProfileField($this->dba, $this->logger, $this->permissionSet, $data);
41 * @param array $condition
42 * @return Model\ProfileField
43 * @throws \Friendica\Network\HTTPException\NotFoundException
45 public function selectFirst(array $condition)
47 return parent::selectFirst($condition);
51 * @param array $condition
52 * @param array $params
53 * @return Collection\ProfileFields
56 public function select(array $condition = [], array $params = [])
58 return parent::select($condition, $params);
62 * @param array $condition
63 * @param array $params
64 * @param int|null $max_id
65 * @param int|null $since_id
67 * @return Collection\ProfileFields
70 public function selectByBoundaries(array $condition = [], array $params = [], int $max_id = null, int $since_id = null, int $limit = self::LIMIT)
72 return parent::selectByBoundaries($condition, $params, $max_id, $since_id, $limit);
76 * @param int $uid Field owner user Id
77 * @return Collection\ProfileFields
80 public function selectByUserId(int $uid)
84 ['order' => ['order']]
89 * Retrieve all custom profile field a given contact is able to access to, including public profile fields.
91 * @param int $cid Private contact id, must be owned by $uid
92 * @param int $uid Field owner user id
93 * @return Collection\ProfileFields
96 public function selectByContactId(int $cid, int $uid)
98 $permissionSets = $this->permissionSet->selectByContactId($cid, $uid);
100 $psids = $permissionSets->column('id');
102 // Includes public custom fields
105 return $this->select(
106 ['uid' => $uid, 'psid' => $psids],
107 ['order' => ['order']]
112 * @param array $fields
113 * @return Model\ProfileField|bool
116 public function insert(array $fields)
118 $fields['created'] = DateTimeFormat::utcNow();
119 $fields['edited'] = DateTimeFormat::utcNow();
121 return parent::insert($fields);
125 * @param Model\ProfileField $model
129 public function update(BaseModel $model)
131 $model->edited = DateTimeFormat::utcNow();
133 return parent::update($model);