Example #1
0
 /**
  * Admin edit
  *
  * @param integer $id
  * @return void
  * @access public
  */
 public function admin_edit($id = null)
 {
     // Protect against administrator edit
     if ($id == null || $id < 4) {
         $this->Session->setFlash(__('Invalid request.'), 'flash_message_error');
         $this->redirect(array('action' => 'index'));
     }
     $errors = null;
     if (!empty($this->request->data)) {
         $this->request->data['Aro']['model'] = '';
         // update alias with user data
         if ($this->request->data['Aro']['foreign_key'] != '') {
             $this->request->data['Aro']['model'] = 'User';
             $this->request->data['Aro']['alias'] = $this->User->field('Name', array('id' => $this->request->data['Aro']['foreign_key']));
         }
         $this->Node->recursive = -1;
         $this->request->data = array_merge($this->Node->read(null, $id), $this->request->data);
         // alias must be unique
         $this->Node->validate = array('alias' => array('rule' => 'isUnique', 'message' => __('Group / User name must be unique!!')));
         if ($this->Node->save($this->request->data)) {
             $this->Session->setFlash(__('Saved with success.'), 'flash_message_info');
             $this->redirect(array('action' => 'index'));
         } else {
             $this->Session->setFlash(__('Could not be saved. Please, try again.'), 'flash_message_error');
         }
     }
     if (empty($this->request->data)) {
         $this->request->data = $this->Node->read(null, $id);
     }
     $parents[0] = "[ " . __('Root') . " ]";
     $nodelist = $this->Node->generateTreeList(null, '{n}.Aro.id', '{n}.Aro.alias', ' - ', '-1');
     $acolist = $this->Acl->Aco->generateTreeList(null, '{n}.Aco.id', '{n}.Aco.alias', ' - ', '-1');
     $acoAccessList = $this->Acl->Aco->generateTreeList(null, '{n}.Aco.id', '{n}.Aco.alias', '', '-1');
     $acoAliasList = $acoAccessList;
     foreach ($acoAccessList as $key => $value) {
         $alias = "";
         $path = $this->Acl->Aco->getPath($key);
         foreach ($path as $pathAlias) {
             if ($alias != '') {
                 $alias = $alias . '/';
             }
             $alias = $alias . $pathAlias['Aco']['alias'];
         }
         $acoAliasList[$key] = $alias;
         $acoAccessList[$key] = $this->Acl->check($this->request->data['Aro']['alias'], $alias);
         #value
     }
     if ($nodelist) {
         foreach ($nodelist as $key => $value) {
             $parents[$key] = $value;
         }
     }
     $foreignKeys = array();
     // if node is group type ( without foreignKey ) do no show available users
     if ($this->Node->field('foreign_key')) {
         $usersOnAro = $this->Node->find('list', array('fields' => array('Aro.foreign_key'), 'conditions' => array('Aro.foreign_key <>' => null, 'Aro.id <>' => $id)));
         $foreignKeys = $this->User->find('list', array('conditions' => array('User.active' => '1', 'NOT' => array('User.id' => $usersOnAro))));
     }
     $this->set(compact('parents', 'acolist', 'foreignKeys', 'acoAccessList', 'acoAliasList'));
 }
Example #2
0
 /**
  * Admin edit
  *
  * @param integer $id
  * @return void
  * @access public
  */
 public function admin_edit($id = null)
 {
     if ($id == null || $id < 3) {
         $this->Session->setFlash(__('Invalid request.'), 'flash_message_error');
         $this->redirect(array('action' => 'index'));
     }
     if (!empty($this->request->data)) {
         if ($this->Node->save($this->request->data)) {
             $this->Session->setFlash(__('Saved with success.'), 'flash_message_info');
             $this->redirect(array('action' => 'index'));
         } else {
             $this->Session->setFlash(__('Could not be saved. Please, try again.'), 'flash_message_error');
         }
     } else {
         $this->request->data = $this->Node->read(null, $id);
     }
     $parents[0] = "[ No Parent ]";
     $nodelist = $this->Node->generateTreeList(null, '{n}.Aco.id', '{n}.Aco.alias', ' - ', '-1');
     if ($nodelist) {
         foreach ($nodelist as $key => $value) {
             $parents[$key] = $value;
         }
     }
     $this->set(compact('parents'));
 }
Example #3
0
 /**
  * @brief get the root node of a model according to some condition
  *
  * This method is handy if you use a wrapper for the MPTT data that acts
  * as the sole root record.
  *
  * @access public
  *
  * @param object $Model the model doing the find
  * @param array $conditions any conditions for the find
  *
  * @return mixed the string/int id of the root record or false on error
  */
 public function getRootNode($Model, $conditions = array())
 {
     if (!is_callable(array($Model, 'generateTreeList'))) {
         return false;
     }
     $data = $Model->generateTreeList($conditions, null, null, '@', -1);
     $roots = array();
     foreach ($data as $id => $name) {
         if (substr($name, 0, 1) != '@') {
             $roots[] = $id;
         }
     }
     unset($data);
     if (count($roots) != 1) {
         return false;
     }
     return $roots[0];
 }