Browse Source

get all permissions for a user

tags/0.1.0
Robin Thoni 9 years ago
parent
commit
d450cc9c57

+ 2
- 0
src/Auth/Business/LuticateBusiness.php View File

@@ -119,6 +119,8 @@ class LuticateBusiness
119 119
 
120 120
         $route->post("$prefix/permissions/user/$user_id/$permission_name", "${ns}LuticatePermissionsUsersController",
121 121
             "get", LuticatePermissions::PERM_USER_GET);
122
+        $route->post("$prefix/permissions/user/$user_id", "${ns}LuticatePermissionsUsersController",
123
+            "getAllByUser", LuticatePermissions::PERM_USER_GET);
122 124
         $route->post("$prefix/permissions/user/$user_id/add/$permission_name/$permission_value",
123 125
             "${ns}LuticatePermissionsUsersController", "add", array(LuticatePermissions::PERM_USER_ADD,
124 126
                 LuticatePermissions::PERM_USER_GET));

+ 15
- 0
src/Auth/Business/LuticatePermissionsUsersBusiness.php View File

@@ -2,9 +2,11 @@
2 2
 
3 3
 namespace Luticate\Auth\Business;
4 4
 
5
+use Luticate\Auth\DBO\LuticatePermissionsDbo;
5 6
 use Luticate\Utils\LuBusiness;
6 7
 use Luticate\Auth\DataAccess\LuticatePermissionsUsersDataAccess;
7 8
 use Luticate\Auth\DBO\LuticatePermissionsUsersDbo;
9
+use Luticate\Utils\LuMultipleDbo;
8 10
 
9 11
 class LuticatePermissionsUsersBusiness extends LuBusiness {
10 12
     protected static function getDataAccess()
@@ -19,6 +21,19 @@ class LuticatePermissionsUsersBusiness extends LuBusiness {
19 21
         return LuticatePermissionsUsersDataAccess::getByName($user_id, $permission_name);
20 22
     }
21 23
 
24
+    public static function getAllByUser($user_id, $page = 0, $perPage = PHP_INT_MAX)
25
+    {
26
+        $values = LuticatePermissionsUsersDataAccess::getAllByUser($user_id, $page, $perPage);
27
+        $dbos = [];
28
+        foreach ($values->getData() as $value) {
29
+            $dbo = new LuticatePermissionsDbo();
30
+            $dbo->setValue($value->getValue());
31
+            $dbo->setName($value->getName());
32
+            $dbos[] = $dbo;
33
+        }
34
+        return new LuMultipleDbo($values->getCount(), $dbos);
35
+    }
36
+
22 37
     public static function get($user_id, $permission_name)
23 38
     {
24 39
         return LuticatePermissionsUsersDataAccess::getByName($user_id, $permission_name);

+ 12
- 0
src/Auth/Controller/LuticatePermissionsUsersController.php View File

@@ -12,6 +12,18 @@ class LuticatePermissionsUsersController extends LuController {
12 12
         return new LuticatePermissionsUsersBusiness();
13 13
     }
14 14
 
15
+    /**
16
+     * Get all permissions for a user
17
+     * @param $user_id int The user id
18
+     * @param int $page The page number, 0 based
19
+     * @param int $perPage The number of items per page
20
+     * @return \Luticate\Utils\LuMultipleDbo
21
+     */
22
+    public function getAllByUser($user_id, $page = 0, $perPage = PHP_INT_MAX)
23
+    {
24
+        return LuticatePermissionsUsersBusiness::getAllByUser($user_id, $page, $perPage);
25
+    }
26
+
15 27
     /**
16 28
      * Get a permission for a user
17 29
      * @param $user_id int The user id

+ 5
- 0
src/Auth/DataAccess/LuticatePermissionsUsersDataAccess.php View File

@@ -26,6 +26,11 @@ class LuticatePermissionsUsersDataAccess extends LuDataAccess {
26 26
         return $perm->toDbo();
27 27
     }
28 28
 
29
+    public static function getAllByUser($user_id, $page = 0, $perPage = PHP_INT_MAX)
30
+    {
31
+        return self::getMultiple(array(array('user_id', '=', $user_id)), array(array("name", "ASC")), $page, $perPage);
32
+    }
33
+
29 34
     public static function delete($user_id, $permission_name)
30 35
     {
31 36
         $perm = self::getModelByName($user_id, $permission_name);

Loading…
Cancel
Save