/**
  * Method to get categories item data
  *
  * @access public
  * @return array
  */
 function getData()
 {
     global $mainframe;
     $limit = $mainframe->getUserStateFromRequest('com_hotelguide.limit', 'limit', $mainframe->getCfg('list_limit'), 'int');
     $limitstart = $mainframe->getUserStateFromRequest('com_hotelguide.limitstart', 'limitstart', 0, 'int');
     $search = $mainframe->getUserStateFromRequest('com_hotelguide.event.search', 'search', '', 'string');
     $search = $this->_db->getEscaped(trim(JString::strtolower($search)));
     $orderby = ' ORDER BY e.title';
     $where = array();
     $where[] = 'e.published = 1';
     $where = count($where) ? ' WHERE ' . implode(' AND ', $where) : '';
     //select the records
     //note, since this is a tree we have to do the limits code-side
     if ($search) {
         $query = 'SELECT e.id' . ' FROM #__hg_events AS e' . ' WHERE LOWER(e.title) LIKE ' . $this->_db->Quote('%' . $this->_db->getEscaped($search, true) . '%', false) . $where;
         $this->_db->setQuery($query);
         $search_rows = $this->_db->loadResultArray();
     }
     $query = 'SELECT e.*' . ' FROM #__hg_events AS e' . $where;
     $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_events::treerecurse(0, '', array(), $children, false, max(0, $levellimit - 1));
     //eventually only pick out the searched items.
     if ($search) {
         $list1 = array();
         foreach ($search_rows as $sid) {
             foreach ($list as $item) {
                 if ($item->id == $sid) {
                     $list1[] = $item;
                 }
             }
         }
         // replace full list with found items
         $list = $list1;
     }
     $total = count($list);
     jimport('joomla.html.pagination');
     $this->_pagination = new JPagination($total, $limitstart, $limit);
     // slice out elements based on limits
     $rows = array_slice($list, $this->_pagination->limitstart, $this->_pagination->limit);
     return $rows;
 }
 /**
  * Get the events 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>&nbsp;';
                 $spacer = '.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
             } else {
                 $pre = '- ';
                 $spacer = '&nbsp;&nbsp;';
             }
             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_events::treerecurse($id, $indent . $spacer, $list, $children, $title, $maxlevel, $level + 1, $type);
         }
     }
     return $list;
 }