Example #1
0
 /**
  *
  * @return DalQuery
  */
 private function _baseQuery()
 {
     $q = DAL::query()->select('_tree.*')->from($this->getTableName(false) . ' _tree');
     //\hat\dbg::alert($q->getRootAlias(), true);
     return $q;
 }
Example #2
0
 private function _extract_nestedset_vars($destination = null, $for_move = true)
 {
     $behavior_name = 'nestedset';
     $lft_key = $this->getFieldName($behavior_name, 'lft');
     $rgt_key = $this->getFieldName($behavior_name, 'rgt');
     $level_key = $this->getFieldName($behavior_name, 'level');
     $root_id_key = $this->getFieldName($behavior_name, 'root_id');
     //      \hat\dbg::alert($this->_for_save);
     $delta = 2;
     // for insert
     if ($this->_table->get('idExists')) {
         $id = $this->_table->get('id');
     }
     if ($this->_table->isInTree()) {
         if ($this->_table->get($root_id_key . 'Exists')) {
             $root_id = $this->_table->get($root_id_key);
         } else {
             throw new \Exception("Missing node {$lft_key} column.");
             return false;
         }
         if ($this->_table->get($lft_key . 'Exists')) {
             $lft = $this->_table->get($lft_key);
         } else {
             throw new \Exception("Missing node {$lft_key} column.");
             return false;
         }
         if ($this->_table->get($rgt_key . 'Exists')) {
             $rgt = $this->_table->get($rgt_key);
         } else {
             throw new \Exception("Missing node {$rgt_key} column.");
             return false;
         }
         if ($this->_table->get($level_key . 'Exists')) {
             $level = $this->_table->get($level_key);
         } else {
             throw new \Exception("Missing node {$level_key} column.");
             return false;
         }
         $delta = $rgt - $lft + 1;
     }
     if ($destination) {
         $dest_root_id = $destination->getBehavior()->getRootId();
         $dest_lft = $destination->get($lft_key);
         $dest_rgt = $destination->get($rgt_key);
         $dest_level = $destination->get($level_key);
     }
     //\hat\dbg::alert(array($dest_root_id, $root_id), true);
     if ($destination && $for_move) {
         if ($root_id != $dest_root_id) {
             throw new \Exception("node and destination not in the same tree.");
             return false;
         }
         $move_to_the_left = $lft > $dest_lft ? true : false;
     }
     $err_msg = '';
     $model_name = $this->_table->getTableName(false);
     $query = DAL::query();
     $this->_table->setQuery($query);
     $vars = \compact(array('lft_key', 'rgt_key', 'level_key', 'root_id_key', 'dest_root_id', 'dest_lft', 'dest_rgt', 'dest_level', 'id', 'root_id', 'lft', 'rgt', 'level', 'delta', 'move_to_the_left', 'model_name', 'query', 'err_msg'));
     $this->_bv[$behavior_name] = $vars;
     return true;
 }