]> git.mxchange.org Git - friendica.git/blob - src/Profile/ProfileField/Entity/ProfileField.php
Added comment
[friendica.git] / src / Profile / ProfileField / Entity / ProfileField.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2022, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Profile\ProfileField\Entity;
23
24 use Friendica\BaseEntity;
25 use Friendica\Network\HTTPException\InternalServerErrorException;
26 use Friendica\Profile\ProfileField\Exception\ProfileFieldNotFoundException;
27 use Friendica\Security\PermissionSet\Entity\PermissionSet;
28
29 /**
30  * Custom profile field entity class.
31  *
32  * Custom profile fields are user-created arbitrary profile fields that can be assigned a permission set to restrict its
33  * display to specific Friendica contacts as it requires magic authentication to work.
34  *
35  * @property-read int|null  $id
36  * @property-read int       $uid
37  * @property-read int       $order
38  * @property-read string    $label
39  * @property-read string    $value
40  * @property-read \DateTime $created
41  * @property-read \DateTime $edited
42  * @property PermissionSet  $permissionSet
43  */
44 class ProfileField extends BaseEntity
45 {
46         /** @var int|null */
47         protected $id;
48         /** @var PermissionSet */
49         protected $permissionSet;
50         /** @var int */
51         protected $uid;
52         /** @var int */
53         protected $order;
54         /** @var string */
55         protected $label;
56         /** @var string */
57         protected $value;
58         /** @var \DateTime */
59         protected $created;
60         /** @var \DateTime */
61         protected $edited;
62
63         public function __construct(int $uid, int $order, string $label, string $value, \DateTime $created, \DateTime $edited, PermissionSet $permissionSet, int $id = null)
64         {
65                 $this->permissionSet = $permissionSet;
66                 $this->uid           = $uid;
67                 $this->order         = $order;
68                 $this->label         = $label;
69                 $this->value         = $value;
70                 $this->created       = $created;
71                 $this->edited        = $edited;
72                 $this->id            = $id;
73         }
74
75         /**
76          * @throws ProfileFieldNotFoundException
77          */
78         public function __get($name)
79         {
80                 try {
81                         return parent::__get($name);
82                 } catch (InternalServerErrorException $exception) {
83                         throw new ProfileFieldNotFoundException($exception->getMessage());
84                 }
85         }
86
87         /**
88          * Updates a ProfileField
89          *
90          * @param string        $value         The current or changed value
91          * @param int           $order         The current or changed order
92          * @param PermissionSet $permissionSet The current or changed PermissionSet
93          */
94         public function update(string $value, int $order, PermissionSet $permissionSet)
95         {
96                 $this->value         = $value;
97                 $this->order         = $order;
98                 $this->permissionSet = $permissionSet;
99                 $this->edited        = new \DateTime('now', new \DateTimeZone('UTC'));
100         }
101
102         /**
103          * Sets the order of the ProfileField
104          *
105          * @param int $order
106          */
107         public function setOrder(int $order)
108         {
109                 $this->order  = $order;
110                 $this->edited = new \DateTime('now', new \DateTimeZone('UTC'));
111         }
112 }