예제 #1
0
 /**
  * Save the permission
  * @param $id
  */
 public static function SaveAll($data, $id = null)
 {
     if (!empty($data) && is_array($data)) {
         if (is_numeric($id)) {
             $role = Doctrine::getTable('AdminRoles')->find($id);
         } else {
             $role = new AdminRoles();
         }
         // Save the role label
         if (!empty($data['name'])) {
             $role['name'] = Shineisp_Commons_UrlRewrites::format($data['name']);
             $role->save();
         }
         // Set the new Role ID to the users selected
         if (!empty($data['users'])) {
             foreach ($data['users'] as $user) {
                 AdminUser::setUserRoleID($user, $id);
             }
         }
         // Clear old permissions
         AdminPermissions::clearPermissionByRoleID($id);
         if (!empty($data['resources'])) {
             // Explode the string into an array
             $resources = explode("/", $data['resources']);
             // Add the new permissions
             foreach ($resources as $resource) {
                 list($module, $controller) = explode(':', $resource);
                 AdminPermissions::addPermission($id, $module, $controller);
             }
         }
         return $role;
     }
     return false;
 }