/**
  * check if a valid action Id is given. if not throw an exception
  *
  * @access private
  * @throws Exception if no valid id is given
  * @return int the Id
  */
 private function checkActionIdParam()
 {
     $id = $this->getRequest()->getParam('id');
     if ($id === NULL || is_numeric($id) === FALSE || $this->dbAction->find($id)->count() === 0) {
         throw new Admin_Model_Acl_Exception('Invalid or no Id Parameter given');
     }
     return (int) $id;
 }
 /**
  * Change the Status of a controller (enabled/disabled)
  *
  * @view views/scripts/controller/status.phtml
  * @access public
  */
 public function statusAction()
 {
     $ctrlRow = new Admin_Model_DbRow_Controller($this->dbCtrl->find($this->checkControllerIdParam()));
     $ctrlRow->set('enabled', $ctrlRow->get('enabled') == 1 ? 0 : 1);
     $this->dbCtrl->update($ctrlRow->toDbArray(array('enabled')), $ctrlRow->get('id'));
     // disabled all actions too, they are relevant in the ACL
     if ($ctrlRow->get('enabled') === 0) {
         $actionRow = new Admin_Model_DbRow_Action(array('enabled' => 0));
         $actionDbModel = new Admin_Model_DbTable_Acl_Action();
         $actionDbModel->updateWithControllerId($actionRow->toDbArray(array('enabled')), $ctrlRow->get('id'));
     }
     $this->_redirect('admin/controller/index');
 }
 /**
  * Save the Permission for an action
  *
  * @return array
  */
 public function saveActionPermissionsAction()
 {
     $ruleModel = new Admin_Model_DbTable_Acl_Rule();
     $roleModel = new Admin_Model_DbTable_Acl_Role();
     $actionModel = new Admin_Model_DbTable_Acl_Action();
     $data = Zend_Json::decode($this->request->getParam('permissions', array()));
     $return = array();
     if (!is_array($data) || !empty($data['aId'])) {
         // if we have no array or the controller id is directly in the array
         // we nest the array in an array to get the foreach to work
         // extjs is sending object if only 1 row has changed and an array of object
         // if multiple changes occure
         $data = array($data);
     }
     foreach ($data as $el) {
         $role = $roleModel->find($el['roleId']);
         $action = $actionModel->find($el['aId']);
         // not an action provided or multiple controller found
         if ($action->count() !== 1) {
             continue;
         }
         // not a roleId provided or multiple roles found
         if ($role->count() !== 1) {
             continue;
         }
         $action = new Admin_Model_DbRow_Action($action->current());
         $role = new Admin_Model_DbRow_Role($role->current());
         if ($el['rule'] == Admin_Model_DbTable_Acl_Rule::RULE_DENY) {
             $rule = Admin_Model_DbTable_Acl_Rule::RULE_DB_DENY;
         } elseif ($el['rule'] == Admin_Model_DbTable_Acl_Rule::RULE_ALLOW) {
             $rule = Admin_Model_DbTable_Acl_Rule::RULE_DB_ALLOW;
         } else {
             $rule = NULL;
         }
         $ruleModel->deleteWithActionRole($action->get('id'), $role->get('id'));
         if ($rule !== NULL) {
             $permission = new Admin_Model_DbRow_Rule(array('mcId' => $action->get('mcId'), 'aId' => $action->get('id'), 'roleId' => $role->get('id'), 'rule' => $rule));
             $ruleModel->insert($permission->toDbArray());
         }
         $return[] = array('ident' => join("_", array($role->get('id'), $action->get('mcId'), $action->get('id'))), 'mcId' => $action->get('mcId'), 'aId' => $action->get('id'), 'roleName' => $role->get('name'), 'roleId' => $role->get('id'), 'rule' => $rule);
     }
     return $this->responseSuccess(array('permissions' => $return));
 }