Example #1
0
 function displayDefault()
 {
     global $mainframe, $hgconf;
     //Load pane behavior
     jimport('joomla.html.pane');
     //initialise variables
     $editor =& JFactory::getEditor();
     $document =& JFactory::getDocument();
     $user =& JFactory::getUser();
     $lang =& JFactory::getLanguage();
     $db =& JFactory::getDBO();
     //get vars
     $cid = JRequest::getVar('cid');
     //create the toolbar
     if ($cid) {
         JToolBarHelper::title(JText::_('HG_EDIT_EVENT'), 'event');
     } else {
         JToolBarHelper::title(JText::_('HG_NEW_EVENT'), 'event');
     }
     JToolBarHelper::apply();
     JToolBarHelper::save();
     JToolBarHelper::custom('saveandnew', 'savenew.png', 'savenew.png', 'HG_SAVE_AND_NEW', false);
     JToolBarHelper::cancel();
     //Get data from the model
     $model =& $this->getModel();
     $row =& $this->get('Event');
     $events = hotelguide_events::getEventsTree(0);
     //remove the current category to prevent selection as parent for itself
     foreach ($events as $event) {
         if ($event->id == $row->id) {
             unset($events[$event->id]);
         }
     }
     //fail if checked out not by 'me'
     if ($row->id) {
         if ($model->isCheckedOut($user->get('id'))) {
             JError::raiseWarning('SOME_ERROR_CODE', $row->title . ' ' . JText::_('HG_EDITED_BY_ANOTHER_ADMIN'));
             $mainframe->redirect('index.php?option=com_hotelguide&view=events');
         }
     }
     //clean data
     JFilterOutput::objectHTMLSafe($row, ENT_QUOTES, 'text');
     $Lists['parent_id'] = hotelguide_events::buildeventselect($events, 'parent_id', $row->parent_id, true);
     //assign vars to view
     $this->assignRef('hgconf', $hgconf);
     $this->assignRef('Lists', $Lists);
     $this->assignRef('row', $row);
     $this->assignRef('editor', $editor);
 }
 /**
  * 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;
 }