/** * logic to get the categories * * @access public * @return void */ function getCategories() { $user =& JFactory::getUser(); $elsettings =& ELHelper::config(); $userid = (int) $user->get('id'); $gid = (int) $user->get('aid'); $superuser = ELUser::superuser(); $where = ' WHERE c.published = 1 AND c.access <= ' . $gid; //only check for maintainers if we don't have an edit action if (!$this->_id) { //get the ids of the categories the user maintaines $query = 'SELECT g.group_id' . ' FROM #__eventlist_groupmembers AS g' . ' WHERE g.member = ' . $userid; $this->_db->setQuery($query); $catids = $this->_db->loadResultArray(); $categories = implode(' OR c.groupid = ', $catids); //build ids query if ($categories) { //check if user is allowed to submit events in general, if yes allow to submit into categories //which aren't assigned to a group. Otherwise restrict submission into maintained categories only if (ELUser::validate_user($elsettings->evdelrec, $elsettings->delivereventsyes)) { $where .= ' AND c.groupid = 0 OR c.groupid = ' . $categories; } else { $where .= ' AND c.groupid = ' . $categories; } } else { $where .= ' AND c.groupid = 0'; } } //administrators or superadministrators have access to all categories, also maintained ones if ($superuser) { $where = ' WHERE c.published = 1'; } //get the maintained categories and the categories whithout any group //or just get all if somebody have edit rights $query = 'SELECT c.*' . ' FROM #__eventlist_categories AS c' . $where . ' ORDER BY c.ordering'; $this->_db->setQuery($query); // $this->_category = array(); // $this->_category[] = JHTML::_('select.option', '0', JText::_( 'SELECT CATEGORY' ) ); // $this->_categories = array_merge( $this->_category, $this->_db->loadObjectList() ); $rows = $this->_db->loadObjectList(); //set depth limit $levellimit = 10; //get children $children = array(); 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 $this->_categories = eventlist_cats::treerecurse(0, '', array(), $children, true, max(0, $levellimit - 1)); return $this->_categories; }
/** * Method to get categories item data * * @access public * @return array */ function getData() { $app =& JFactory::getApplication(); static $items; if (isset($items)) { return $items; } $limit = $app->getUserStateFromRequest('com_eventlist.limit', 'limit', $app->getCfg('list_limit'), 'int'); $limitstart = $app->getUserStateFromRequest('com_eventlist.limitstart', 'limitstart', 0, 'int'); $filter_order = $app->getUserStateFromRequest('com_eventlist.categories.filter_order', 'filter_order', 'c.ordering', 'cmd'); $filter_order_Dir = $app->getUserStateFromRequest('com_eventlist.categories.filter_order_Dir', 'filter_order_Dir', '', 'word'); $filter_state = $app->getUserStateFromRequest('com_eventlist.categories.filter_state', 'filter_state', '', 'word'); $search = $app->getUserStateFromRequest('com_eventlist.categories.search', 'search', '', 'string'); $search = $this->_db->getEscaped(trim(JString::strtolower($search))); $filter_order = JFilterInput::clean($filter_order, 'cmd'); $filter_order_Dir = JFilterInput::clean($filter_order_Dir, 'word'); $orderby = ' ORDER BY ' . $filter_order . ' ' . $filter_order_Dir . ', c.ordering'; $where = array(); if ($filter_state) { if ($filter_state == 'P') { $where[] = 'c.published = 1'; } else { if ($filter_state == 'U') { $where[] = 'c.published = 0'; } } } $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 c.id' . ' FROM #__eventlist_categories AS c' . ' WHERE LOWER(c.catname) LIKE ' . $this->_db->Quote('%' . $this->_db->getEscaped($search, true) . '%', false) . $where; $this->_db->setQuery($query); $search_rows = $this->_db->loadResultArray(); } $query = 'SELECT c.*, c.catname AS name, c.parent_id AS parent, u.name AS editor, g.name AS groupname, gr.name AS catgroup' . ' FROM #__eventlist_categories AS c' . ' LEFT JOIN #__groups AS g ON g.id = c.access' . ' LEFT JOIN #__users AS u ON u.id = c.checked_out' . ' LEFT JOIN #__eventlist_groups AS gr ON gr.id = c.groupid' . $where . $orderby; $this->_db->setQuery($query); $rows = $this->_db->loadObjectList(); //establish the hierarchy of the categories $children = array(); //set depth limit $levellimit = 10; //first pass - collect children foreach ($rows as $child) { $parent = $child->parent_id; $list = @$children[$parent] ? $children[$parent] : array(); array_push($list, $child); $children[$parent] = $list; } //second pass - get an indent list of the items $list = eventlist_cats::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 $list = array_slice($list, $this->_pagination->limitstart, $this->_pagination->limit); foreach ($list as $category) { $category->assignedevents = $this->_countcatevents($category->id); } return $list; }
/** * Get the categorie 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->catname; } else { $txt = $pre . $v->catname; } } 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 = eventlist_cats::treerecurse($id, $indent . $spacer, $list, $children, $title, $maxlevel, $level + 1, $type); } } return $list; }
/** * logic to get the categories * * @access public * @return void */ function getCategoryTree() { $app =& JFactory::getApplication(); // Get the paramaters of the active menu item $params =& $app->getParams('com_eventlist'); $top_id = $params->get('top_category', 0); $user =& JFactory::getUser(); $elsettings =& ELHelper::config(); $userid = (int) $user->get('id'); $gid = (int) $user->get('aid'); $superuser = ELUser::superuser(); $where = ' WHERE c.published = 1 AND c.access <= ' . $gid; //get the maintained categories and the categories whithout any group //or just get all if somebody have edit rights $query = 'SELECT c.*' . ' FROM #__eventlist_categories AS c' . $where . ' ORDER BY c.ordering'; $this->_db->setQuery($query); $rows = $this->_db->loadObjectList(); //set depth limit $levellimit = 10; //get children $children = array(); 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 return eventlist_cats::treerecurse($top_id, '', array(), $children, true, max(0, $levellimit - 1)); }