addModulePermissions() public static method

Add module permissions
public static addModulePermissions ( array $modulePermissions )
$modulePermissions array
Example #1
0
 /**
  * Update the permissions
  *
  * @param \SpoonFormElement[] $actionPermissions The action permissions.
  * @param array $bundledActionPermissions The bundled action permissions.
  */
 private function updatePermissions($actionPermissions, $bundledActionPermissions)
 {
     $modulesDenied = array();
     $modulesGranted = array();
     $actionsDenied = array();
     $actionsGranted = array();
     $checkedModules = array();
     $uncheckedModules = array();
     // loop through action permissions
     foreach ($actionPermissions as $permission) {
         // get bits
         $bits = explode('_', $permission->getName());
         // convert camelcasing to underscore notation
         $module = $bits[1];
         $action = $bits[2];
         // permission checked?
         if ($permission->getChecked()) {
             // add to granted
             $actionsGranted[] = array('group_id' => $this->id, 'module' => $module, 'action' => $action, 'level' => ACTION_RIGHTS_LEVEL);
             // if not yet present, add to checked modules
             if (!in_array($module, $checkedModules)) {
                 $checkedModules[] = $module;
             }
         } else {
             // add to denied
             $actionsDenied[] = array('group_id' => $this->id, 'module' => $module, 'action' => $action, 'level' => ACTION_RIGHTS_LEVEL);
             // if not yet present add to unchecked modules
             if (!in_array($module, $uncheckedModules)) {
                 $uncheckedModules[] = $module;
             }
         }
     }
     // loop through bundled action permissions
     foreach ($bundledActionPermissions as $permission) {
         // get bits
         $bits = explode('_', $permission->getName());
         // convert camelcasing to underscore notation
         $module = $bits[1];
         $group = $bits[3];
         // create new item
         $moduleItem = array('group_id' => $this->id, 'module' => $module);
         // loop through actions
         foreach ($this->actions[$module] as $moduleAction) {
             // permission checked?
             if ($permission->getChecked()) {
                 // add to granted if in the right group
                 if (in_array($group, $moduleAction)) {
                     $actionsGranted[] = array('group_id' => $this->id, 'module' => $module, 'action' => $moduleAction['value'], 'level' => ACTION_RIGHTS_LEVEL);
                 }
                 // if not yet present, add to checked modules
                 if (!in_array($module, $checkedModules)) {
                     $checkedModules[] = $module;
                 }
             } else {
                 // add to denied
                 if (in_array($group, $moduleAction)) {
                     $actionsDenied[] = array('group_id' => $this->id, 'module' => $module, 'action' => $moduleAction['value'], 'level' => ACTION_RIGHTS_LEVEL);
                 }
                 // if not yet present add to unchecked modules
                 if (!in_array($module, $uncheckedModules)) {
                     $uncheckedModules[] = $module;
                 }
             }
         }
     }
     // loop through granted modules and add to array
     foreach ($checkedModules as $module) {
         $modulesGranted[] = array('group_id' => $this->id, 'module' => $module);
     }
     // loop through denied modules and add to array
     foreach (array_diff($uncheckedModules, $checkedModules) as $module) {
         $modulesDenied[] = array('group_id' => $this->id, 'module' => $module);
     }
     // add granted permissions
     BackendGroupsModel::addModulePermissions($modulesGranted);
     BackendGroupsModel::addActionPermissions($actionsGranted);
     // delete denied permissions
     BackendGroupsModel::deleteModulePermissions($modulesDenied);
     BackendGroupsModel::deleteActionPermissions($actionsDenied);
 }