/** * Get nodes selection * * $params * depth int - depth of the selection. will be usefull for * AXIS_DESCENDANT, AXIS_ANCESTOR selects * * slice1 int, * slice2 int -select data slice, will be usefull for * AXIS_DESCENDANT, AXIS_ANCESTOR selects * * @param int $contextId * @param int $axis axis of the selection. see AXIS_* consts * @param array $params * @return Axis_NSTree_NodeSet * @throws Axis_NSTree_Exception */ public function select($contextId, $axis = self::AXIS_SELF, $params = array()) { $select = $this->_table->makeSelect($contextId, $axis, $params); if ($this->_2tables) { $info = $this->_table2->info(); $cols = array(); foreach (array_values($info['cols']) as $column) { $cols[] = new Zend_Db_Expr("d.{$column} AS {$column}"); } $select->from(array("d" => $this->_tableName2), $cols); $select->where("s1.{$this->_dataForeign} = d.{$this->_dataPrimary}"); } $fetched = $this->_db->fetchAll($select->__toString()); $data = array(); $structure = array(); foreach ($fetched as $row) { $dataRow = $this->_2tables ? array_diff_key($row, $this->_systemColumns) : $row; $structRow = array(); foreach ($this->_systemColumns as $name => $title) { $structRow[$title] = $row[$name]; } $structure[] = $structRow; $data[] = $dataRow; } /** * Convert data */ $pseudoRoot = new stdClass(); $pseudoRoot->children = array(); if (sizeof($structure)) { $levels = array(); $levels[$structure[0]['level'] - 1] = $pseudoRoot; foreach ($structure as $i => $nodeStruct) { $node = new stdClass(); $node->struct = $nodeStruct; $node->data = $data[$i]; $node->children = array(); $parent = $levels[$nodeStruct['level'] - 1]; $parent->children[] = $node; $levels[$nodeStruct['level']] = $node; } } return new Axis_NSTree_Nodeset(array('db' => $this->_db, 'table' => $this->_dataTable, 'nodes' => $pseudoRoot->children)); }