/** * Singleton * @return Application_Model_AclClassesMapper */ public static function i() { if (self::$_instance == null) { self::$_instance = new self(); } return self::$_instance; }
/** * Get all availables classes registered * @return array[Application_Model_AclClass] */ public function getClasses() { if (!count($this->classesCache)) { $this->classesCache = Application_Model_AclClassesMapper::i()->fetchAll(); } return $this->classesCache; }
function saveAction() { $type = $this->getRequest()->getParam('type', false); if (!$type || !$this->getRequest()->isPost()) { $this->_helper->flashMessenger(array('type' => 'error', 'text' => X_Env::_('p_auth_err_invalidrequest'))); $this->_helper->redirector('index', 'acl'); return; } if ($type == 'resource') { $form = new Application_Form_AclResource(); $_classes = X_VlcShares_Plugins::helpers()->acl()->getClasses(); $classes = array(); foreach ($_classes as $perm) { /* @var $perm Application_Model_AclClass */ $classes[$perm->getName()] = "{$perm->getName()}"; } $form->class->setMultiOptions($classes); $form->setDefault('class', Application_Model_AclClass::CLASS_BROWSE); $_plugins = X_VlcShares_Plugins::broker()->getPlugins(); $plugins = array(); foreach ($_plugins as $id => $plugin) { $plugins[$id] = $id == 'auth' ? 'CORE' : $id; } $form->generator->setMultiOptions($plugins); $form->setDefault('generator', 'auth'); } else { $type = 'class'; $form = new Application_Form_AclClass(); } if ($form->isValid($this->getRequest()->getPost())) { if ($type == 'resource') { $key = $form->getValue('key'); $key = "default/{$key}"; $model = new Application_Model_AclResource(); $mapper = Application_Model_AclResourcesMapper::i(); $mapper->find($key, $model); if ($model->isNew()) { $model->setKey($key); $model->setGenerator($form->getValue('generator')); $model->setClass($form->getValue('class')); X_Debug::i("Adding resource {key: {$model->getKey()}, class: {$model->getClass()}, generator: {$model->getGenerator()}}"); } else { throw new Exception("This resource key already exists {{$key}}"); } } elseif ($type == 'class') { $model = new Application_Model_AclClass(); $mapper = Application_Model_AclClassesMapper::i(); $mapper->find($form->getValue('name'), $model); if ($model->isNew()) { $model->setName($form->getValue('name')); $model->setDescription($form->getValue('description')); X_Debug::i("Adding class {name: {$model->getName()}}"); } else { throw new Exception("This class already exists {{$form->getValue('name')}}"); } } else { throw new Exception("Invalid type {{$type}}"); } try { $mapper->save($model); $this->_helper->flashMessenger(array('type' => 'success', 'text' => X_Env::_('p_auth_acl_datasaved'))); $this->_helper->redirector('index', 'acl'); } catch (Exception $e) { $this->_helper->flashMessenger(array('type' => 'error', 'text' => X_Env::_('p_auth_dberror', $e->getMessage()))); $this->_helper->redirector('index', 'acl'); } } else { $form->setAction($this->_helper->url('save', 'acl', 'default', array('type' => $type))); $form->setDefaults($this->getRequest()->getPost()); $this->view->type = $type; $this->view->form = $form; $this->_helper->viewRenderer->setScriptAction('add'); } }