3 * @copyright Copyright (C) 2010-2022, the Friendica project
5 * @license GNU AGPL version 3 or any later version
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.
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.
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/>.
22 namespace Friendica\Profile\ProfileField\Entity;
24 use Friendica\BaseEntity;
25 use Friendica\Network\HTTPException\InternalServerErrorException;
26 use Friendica\Profile\ProfileField\Exception\ProfileFieldNotFoundException;
27 use Friendica\Security\PermissionSet\Entity\PermissionSet;
30 * Custom profile field entity class.
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.
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
44 class ProfileField extends BaseEntity
48 /** @var PermissionSet */
49 protected $permissionSet;
63 public function __construct(int $uid, int $order, string $label, string $value, \DateTime $created, \DateTime $edited, PermissionSet $permissionSet, int $id = null)
65 $this->permissionSet = $permissionSet;
67 $this->order = $order;
68 $this->label = $label;
69 $this->value = $value;
70 $this->created = $created;
71 $this->edited = $edited;
76 * @throws ProfileFieldNotFoundException
78 public function __get($name)
81 return parent::__get($name);
82 } catch (InternalServerErrorException $exception) {
83 throw new ProfileFieldNotFoundException($exception->getMessage());
88 * Updates a ProfileField
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
94 public function update(string $value, int $order, PermissionSet $permissionSet)
96 $this->value = $value;
97 $this->order = $order;
98 $this->permissionSet = $permissionSet;
99 $this->edited = new \DateTime('now', new \DateTimeZone('UTC'));
103 * Sets the order of the ProfileField
107 public function setOrder(int $order)
109 $this->order = $order;
110 $this->edited = new \DateTime('now', new \DateTimeZone('UTC'));