/** * logic to get the categories * * @access public * @return void */ function getCategoryTree() { $app = JFactory::getApplication(); $db = JFactory::getDBO(); // Get the paramaters of the active menu item $params = $app->getParams('com_jem'); $top_id = $params->get('top_category', 1); $user = JFactory::getUser(); // Support Joomla access levels instead of single group id $levels = $user->getAuthorisedViewLevels(); $where = ' WHERE c.published = 1 AND c.access IN (' . implode(',', $levels) . ')'; //get the maintained categories and the categories whithout any group //or just get all if somebody have edit rights $query = 'SELECT c.*' . ' FROM #__jem_categories AS c' . $where . ' ORDER BY c.ordering'; $db->setQuery($query); $mitems = $db->loadObjectList(); // Check for a database error. if ($db->getErrorNum()) { JError::raiseNotice(500, $db->getErrorMsg()); } if (!$mitems) { $mitems = array(); $children = array(); $parentid = $mitems; } else { $mitems_temp = $mitems; $children = array(); // First pass - collect children foreach ($mitems as $v) { $pt = $v->parent_id; $list = @$children[$pt] ? $children[$pt] : array(); array_push($list, $v); $children[$pt] = $list; } $parentid = intval($mitems[0]->parent_id); } //get list of the items $list = JEMCategories::treerecurse($top_id, '', array(), $children, 9999, 0, 0); return $list; }
/** * Method to get categories item data * * @access public * @return array */ function getData() { $app = JFactory::getApplication(); $db = JFactory::getDBO(); $itemid = $app->input->getInt('id', 0) . ':' . $app->input->getInt('Itemid', 0); static $items; if (isset($items)) { return $items; } $limit = $app->getUserStateFromRequest('com_jem.limit', 'limit', $app->getCfg('list_limit'), 'int'); $limitstart = $app->getUserStateFromRequest('com_jem.limitstart', 'limitstart', 0, 'int'); $limitstart = $limit ? (int)(floor($limitstart / $limit) * $limit) : 0; $filter_order = $app->getUserStateFromRequest('com_jem.categoryelement.filter_order', 'filter_order', 'c.lft', 'cmd'); $filter_order_Dir = $app->getUserStateFromRequest('com_jem.categoryelement.filter_order_Dir', 'filter_order_Dir', '', 'word'); $filter_state = $app->getUserStateFromRequest('com_jem.categoryelement.'.$itemid.'.filter_state', 'filter_state', '', 'string'); $search = $app->getUserStateFromRequest('com_jem.categoryelement.'.$itemid.'.filter_search', 'filter_search', '', 'string'); $search = $db->escape(trim(JString::strtolower($search))); $filter_order = JFilterInput::getinstance()->clean($filter_order, 'cmd'); $filter_order_Dir = JFilterInput::getinstance()->clean($filter_order_Dir, 'word'); $orderby = ' ORDER BY ' . $filter_order . ' ' . $filter_order_Dir; $state = array(1); if (is_numeric($filter_state)) { $where = ' WHERE c.published = '.(int) $filter_state; } else { $where = ' WHERE c.published IN (' . implode(',', $state) . ')'; //$where .= ' AND c.alias NOT LIKE "root"'; } $where2 = ' AND c.published IN (' . implode(',', $state) . ')'; //$where2 .= ' AND c.alias NOT LIKE "root"'; // select the records // note, since this is a tree we have to do the limits code-side if ($search) { $query = 'SELECT c.id FROM #__jem_categories AS c' . ' WHERE LOWER(c.catname) LIKE ' . $db->Quote('%' . $this->_db->escape($search, true) . '%', false) . $where2; $db->setQuery($query); $search_rows = $db->loadColumn(); } $query = 'SELECT c.*, u.name AS editor, g.title AS groupname, gr.name AS catgroup' . ' FROM #__jem_categories AS c' . ' LEFT JOIN #__viewlevels AS g ON g.id = c.access' . ' LEFT JOIN #__users AS u ON u.id = c.checked_out' . ' LEFT JOIN #__jem_groups AS gr ON gr.id = c.groupid' . $where // . ' ORDER BY c.parent_id, c.ordering'; . $orderby; $db->setQuery($query); $mitems = $db->loadObjectList(); // Check for a database error. if ($db->getErrorNum()) { JError::raiseNotice(500, $db->getErrorMsg()); } if (! $mitems) { $mitems = array(); $children = array(); $parentid = $mitems; } else { $children = array(); // First pass - collect children foreach ($mitems as $v) { $pt = $v->parent_id; $list = @$children[$pt] ? $children[$pt] : array(); array_push($list, $v); $children[$pt] = $list; } // list childs of "root" which has no parent and normally id 1 $parentid = intval(@isset($children[0][0]->id) ? $children[0][0]->id : 1); } // get list of the items $list = JEMCategories::treerecurse($parentid, '', array(), $children, 9999, 0, 0); // 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 $list = array_slice($list, $this->_pagination->limitstart, $this->_pagination->limit); return $list; }
/** * logic to get the categories * * @return void */ public function getCategories() { // @todo alter function $db = JFactory::getDBO(); $where = ' WHERE c.published = 1'; $query = 'SELECT c.* FROM #__jem_categories AS c' . $where . ' ORDER BY parent_id, c.lft'; $db->setQuery($query); $mitems = $db->loadObjectList(); // Check for a database error. if ($db->getErrorNum()){ JError::raiseNotice(500, $db->getErrorMsg()); } if (!$mitems) { $children = array(); $mitems = array(); $parentid = 0; } else { $children = array(); // First pass - collect children foreach ($mitems as $v) { $pt = $v->parent_id; $list = @$children[$pt] ? $children[$pt] : array(); array_push($list, $v); $children[$pt] = $list; } // list childs of "root" which has no parent and normally id 1 $parentid = intval(@isset($children[0][0]->id) ? $children[0][0]->id : 1); } //get list of the items $list = JEMCategories::treerecurse($parentid, '', array(), $children, 9999, 0, 0); return $list; }
/** * Get the categorie tree * based on the joomla 1.0 treerecurse * * @access public * @return array */ static function treerecurse($id, $indent, $list, &$children, $maxlevel = 9999, $level = 0, $type = 1) { if (@$children[$id] && $level <= $maxlevel) { if ($type) { $pre = '<sup>|_</sup> '; $spacer = '. '; } else { $pre = '- '; $spacer = '- '; } foreach ($children[$id] as $v) { $id = $v->id; if ($level == 0) { $txt = $v->catname; } else { $txt = $pre . $v->catname; } $pt = $v->parent_id; $list[$id] = $v; $list[$id]->treename = $indent . $txt; $list[$id]->children = count(@$children[$id]); $list = JEMCategories::treerecurse($id, ($level ? $indent . $spacer : $indent), $list, $children, $maxlevel, $level+1, $type); } } return $list; }
/** * logic to get the categories * * @access public * @return void */ function getCategories($id) { $db = JFactory::getDbo(); $user = JemFactory::getUser(); $userid = (int) $user->get('id'); if (empty($id)) { // for new events also show all categories user is allowed to see, disable non-useable categories // (to show same list in both cases, and allow "unusable" parents for structuring) $mitems = $user->getJemCategories('add', 'event', array('use_disable' => true)); } else { $query = $db->getQuery(true); $query = 'SELECT COUNT(*)' . ' FROM #__jem_events AS e' . ' WHERE e.id = ' . $db->quote($id) . ' AND e.created_by = ' . $db->quote($userid); $db->setQuery($query); $owner = $db->loadResult(); // on edit show all categories user is allowed to see, disable non-useable categories $mitems = $user->getJemCategories(array('add', 'edit'), 'event', array('use_disable' => true, 'owner' => $owner)); } if (!$mitems) { $mitems = array(); $children = array(); $parentid = 0; } else { $children = array(); // First pass - collect children foreach ($mitems as $v) { $pt = $v->parent_id; $list = @$children[$pt] ? $children[$pt] : array(); array_push($list, $v); $children[$pt] = $list; } // list childs of "root" which has no parent and normally id 1 $parentid = intval(@isset($children[0][0]->id) ? $children[0][0]->id : 1); } //get list of the items $list = JEMCategories::treerecurse($parentid, '', array(), $children, 9999, 0, 0); // append orphaned categories if (count($mitems) > count($list)) { foreach ($children as $k => $v) { if (($k > 1) && !array_key_exists($k, $list)) { $list = JEMCategories::treerecurse($k, '? ', $list, $children, 999, 0, 0); } } } return $list; }