/** * Method to get item data * * @access public * @return object */ function getData() { // Lets load the Items if it doesn't already exist if (empty($this->_data)) { $query = $this->_buildQuery(); $this->_db->setQuery($query); $rows = $this->_db->loadObjectList(); //establish the hierarchy of the categories $children = array(); //set depth limit $levellimit = 10; foreach ($rows as $child) { $parent = $child->parent_id; $list = @$children[$parent] ? $children[$parent] : array(); array_push($list, $child); $children[$parent] = $list; } //get list of the items $list = hotelguide_rooms::treerecurse(0, '', array(), $children, false, max(0, $levellimit - 1)); $total = count($list); jimport('joomla.html.pagination'); $this->_pagination = new JPagination($total, $this->getState('limitstart'), $this->getState('limit')); $this->_data = array_slice($list, $this->_pagination->limitstart, $this->_pagination->limit); } return $this->_data; }
/** * Get the room tree * based on the joomla 1.0 treerecurse * * @access public * @return array */ function treerecurse($id, $indent, $list, &$children, $title, $maxlevel = 9999, $level = 0, $type = 1) { if (@$children[$id] && $level <= $maxlevel) { foreach ($children[$id] as $v) { $id = $v->id; if ($type) { $pre = '<sup>|_</sup> '; $spacer = '. '; } else { $pre = '- '; $spacer = ' '; } if ($title) { if ($v->parent_id == 0) { $txt = '' . $v->title; } else { $txt = $pre . $v->title; } } else { if ($v->parent_id == 0) { $txt = ''; } else { $txt = $pre; } } $pt = $v->parent_id; $list[$id] = $v; $list[$id]->treename = "{$indent}{$txt}"; $list[$id]->children = count(@$children[$id]); $list = hotelguide_rooms::treerecurse($id, $indent . $spacer, $list, $children, $title, $maxlevel, $level + 1, $type); } } return $list; }