Update copyright
[friendica.git/.git] / src / Model / PermissionSet.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2021, 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\Model;
23
24 use Friendica\BaseModel;
25 use Friendica\DI;
26
27 /**
28  * functions for interacting with the permission set of an object (item, photo, event, ...)
29  *
30  * @property int uid
31  * @property string allow_cid
32  * @property string allow_gid
33  * @property string deny_cid
34  * @property string deny_gid
35  */
36 class PermissionSet extends BaseModel
37 {
38         /**
39          * Fetch the id of a given permission set. Generate a new one when needed
40          *
41          * @param int         $uid
42          * @param string|null $allow_cid Allowed contact IDs    - empty = everyone
43          * @param string|null $allow_gid Allowed group IDs      - empty = everyone
44          * @param string|null $deny_cid  Disallowed contact IDs - empty = no one
45          * @param string|null $deny_gid  Disallowed group IDs   - empty = no one
46          * @return int id
47          * @throws \Exception
48          * @deprecated since 2020.03, use Repository\PermissionSet instead
49          * @see \Friendica\Repository\PermissionSet->getIdFromACL
50          */
51         public static function getIdFromACL(
52                 int $uid,
53                 string $allow_cid = null,
54                 string $allow_gid = null,
55                 string $deny_cid = null,
56                 string $deny_gid = null
57         ) {
58                 return DI::permissionSet()->getIdFromACL($uid, $allow_cid, $allow_gid, $deny_cid, $deny_gid);
59         }
60
61         /**
62          * Returns a permission set for a given contact
63          *
64          * @param integer $uid        User id whom the items belong
65          * @param integer $contact_id Contact id of the visitor
66          *
67          * @return array of permission set ids.
68          * @throws \Exception
69          * @deprecated since 2020.03, use Repository\PermissionSet instead
70          * @see \Friendica\Repository\PermissionSet->selectByContactId
71          */
72         public static function get($uid, $contact_id)
73         {
74                 $permissionSets = DI::permissionSet()->selectByContactId($contact_id, $uid);
75
76                 return $permissionSets->column('id');
77         }
78 }