]> git.mxchange.org Git - friendica.git/blob - src/Repository/ProfileField.php
Create new ProfileField classes
[friendica.git] / src / Repository / ProfileField.php
1 <?php
2
3 namespace Friendica\Repository;
4
5 use Friendica\BaseModel;
6 use Friendica\BaseRepository;
7 use Friendica\Collection;
8 use Friendica\Model;
9 use Friendica\Model\PermissionSet;
10 use Friendica\Util\DateTimeFormat;
11
12 class ProfileField extends BaseRepository
13 {
14         protected static $table_name = 'profile_field';
15
16         protected static $model_class = Model\ProfileField::class;
17
18         protected static $collection_class = Collection\ProfileFields::class;
19
20         /**
21          * @param array $data
22          * @return Model\ProfileField
23          */
24         protected function create(array $data)
25         {
26                 return new Model\ProfileField($this->dba, $this->logger, $data);
27         }
28
29         /**
30          * @param array $condition
31          * @return Model\ProfileField
32          * @throws \Friendica\Network\HTTPException\NotFoundException
33          */
34         public function selectFirst(array $condition)
35         {
36                 return parent::selectFirst($condition);
37         }
38
39         /**
40          * @param array $condition
41          * @param array $params
42          * @return Collection\ProfileFields
43          * @throws \Exception
44          */
45         public function select(array $condition = [], array $params = [])
46         {
47                 return parent::select($condition, $params);
48         }
49
50         /**
51          * @param array $condition
52          * @param array $params
53          * @param int|null $max_id
54          * @param int|null $since_id
55          * @param int $limit
56          * @return Collection\ProfileFields
57          * @throws \Exception
58          */
59         public function selectByBoundaries(array $condition = [], array $params = [], int $max_id = null, int $since_id = null, int $limit = self::LIMIT)
60         {
61                 return parent::selectByBoundaries($condition, $params, $max_id, $since_id, $limit);
62         }
63
64         /**
65          * @param int $uid Field owner user Id
66          * @return Collection\ProfileFields
67          * @throws \Exception
68          */
69         public function selectByUserId(int $uid)
70         {
71                 return $this->select(
72                         ['uid' => $uid],
73                         ['order' => ['order']]
74                 );
75         }
76
77         /**
78          * Retrieve all custom profile field a given contact is able to access to, including public profile fields.
79          *
80          * @param int $cid Private contact id, must be owned by $uid
81          * @param int $uid Field owner user id
82          * @return Collection\ProfileFields
83          * @throws \Exception
84          */
85         public function selectByContactId(int $cid, int $uid)
86         {
87                 $psids = PermissionSet::get($uid, $cid);
88
89                 // Includes public custom fields
90                 $psids[] = 0;
91
92                 return $this->select(
93                         ['uid' => $uid, 'psid' => $psids],
94                         ['order' => ['order']]
95                 );
96         }
97
98         /**
99          * @param array $fields
100          * @return Model\ProfileField|bool
101          * @throws \Exception
102          */
103         public function insert(array $fields)
104         {
105                 $fields['created'] = DateTimeFormat::utcNow();
106                 $fields['edited']  = DateTimeFormat::utcNow();
107
108                 return parent::insert($fields);
109         }
110
111         /**
112          * @param Model\ProfileField $model
113          * @return bool
114          * @throws \Exception
115          */
116         public function update(BaseModel $model)
117         {
118                 $model->edited = DateTimeFormat::utcNow();
119
120                 return parent::update($model);
121         }
122 }