]> git.mxchange.org Git - friendica.git/commitdiff
Add new ACL::getContactListByUserId and ACL::getGroupListByUserId methods
authorHypolite Petovan <hypolite@mrpetovan.com>
Thu, 28 Nov 2019 17:33:00 +0000 (12:33 -0500)
committerHypolite Petovan <hypolite@mrpetovan.com>
Thu, 28 Nov 2019 17:33:00 +0000 (12:33 -0500)
src/Core/ACL.php

index df2f86e2b7a296288f41fd6814eba8fb146dd6ce..ccc2b34d5d2d8a86d907db4b8d3bb13d8f5acb46 100644 (file)
@@ -13,6 +13,7 @@ use Friendica\Model\Contact;
 use Friendica\Model\GContact;
 use Friendica\Core\Session;
 use Friendica\Util\Network;
+use Friendica\Model\Group;
 
 /**
  * Handle ACL management and display
@@ -251,6 +252,63 @@ class ACL extends BaseObject
                ];
        }
 
+       /**
+        * Returns the ACL list of contacts for a given user id
+        *
+        * @param int $user_id
+        * @return array
+        * @throws \Exception
+        */
+       public static function getContactListByUserId(int $user_id)
+       {
+               $acl_contacts = Contact::selectToArray(
+                       ['id', 'name', 'addr', 'micro'],
+                       ['uid' => $user_id, 'pending' => false, 'rel' => [Contact::FOLLOWER, Contact::FRIEND]]
+               );
+               array_walk($acl_contacts, function (&$value) {
+                       $value['type'] = 'contact';
+               });
+
+               return $acl_contacts;
+       }
+
+       /**
+        * Returns the ACL list of groups (including meta-groups) for a given user id
+        *
+        * @param int $user_id
+        * @return array
+        */
+       public static function getGroupListByUserId(int $user_id)
+       {
+               $acl_groups = [
+                       [
+                               'id' => Group::FOLLOWERS,
+                               'name' => L10n::t('Followers'),
+                               'addr' => '',
+                               'micro' => 'images/twopeople.png',
+                               'type' => 'group',
+                       ],
+                       [
+                               'id' => Group::MUTUALS,
+                               'name' => L10n::t('Mutuals'),
+                               'addr' => '',
+                               'micro' => 'images/twopeople.png',
+                               'type' => 'group',
+                       ]
+               ];
+               foreach (Group::getByUserId($user_id) as $group) {
+                       $acl_groups[] = [
+                               'id' => $group['id'],
+                               'name' => $group['name'],
+                               'addr' => '',
+                               'micro' => 'images/twopeople.png',
+                               'type' => 'group',
+                       ];
+               }
+
+               return $acl_groups;
+       }
+
        /**
         * Return the full jot ACL selector HTML
         *