Esempio n. 1
0
 /**
  * Method to auto-populate the model state.
  *
  * Note. Calling getState in this method will result in recursion.
  *
  */
 protected function populateState($ordering = null, $direction = null)
 {
     global $jlistConfig;
     $app = JFactory::getApplication();
     $jinput = JFactory::getApplication()->input;
     // Load the parameters. Merge Global and Menu Item params into new object
     $params = $app->getParams();
     $menuParams = new JRegistry();
     if ($menu = $app->getMenu()->getActive()) {
         $menuParams->loadString($menu->params);
     }
     $mergedParams = clone $menuParams;
     $mergedParams->merge($params);
     $this->setState('params', $mergedParams);
     $user = JFactory::getUser();
     // Create a new query object.
     $db = $this->getDbo();
     $query = $db->getQuery(true);
     $groups = implode(',', $user->getAuthorisedViewLevels());
     $menu_params = $this->state->params;
     $this->setState('filter.published', 1);
     $this->setState('filter.access', true);
     // filter.order
     $orderCol = $app->getUserStateFromRequest('com_jdownloads.categories.filter_order', 'filter_order', '', 'string');
     if ($orderCol == '') {
         // use default sort order or menu order settings
         if ($menu_params->get('orderby_pri') == '') {
             // use config settings
             switch ($jlistConfig['cats.order']) {
                 case '1':
                     // files title field asc
                     $orderCol = 'c.title';
                     $listOrderNew = 'ASC';
                     break;
                 case '2':
                     // files title field desc
                     $orderCol = 'c.title';
                     $listOrderNew = 'DESC';
                     break;
                 default:
                     // files ordering field
                     $orderCol = 'c.ordering';
                     $listOrderNew = 'ASC';
                     break;
             }
         } else {
             // use order from menu settings
             $categoryOrderby = $params->def('orderby_pri', $jlistConfig['cats.order']);
             $orderCol = str_replace(', ', '', JDContentHelperQuery::orderbyPrimary($categoryOrderby));
         }
     }
     $this->setState('list.ordering', $orderCol);
     $listOrder = $app->getUserStateFromRequest('com_jdownloads.categories.filter_order_Dir', 'filter_order_Dir', '', 'cmd');
     if (!in_array(strtoupper($listOrder), array('ASC', 'DESC', ''))) {
         $listOrder = 'ASC';
     }
     if (!$listOrderNew) {
         $this->setState('list.direction', $listOrder);
     } else {
         $this->setState('list.direction', $listOrderNew);
     }
     $this->setState('list.start', JRequest::getUInt('limitstart', 0));
     $limit = $app->getUserStateFromRequest('com_jdownloads.categories.limit', 'limit', '', 'uint');
     if (!$limit) {
         if ((int) $menu_params->get('display_num') > 0) {
             $limit = (int) $menu_params->get('display_num');
         } else {
             $limit = (int) $jlistConfig['categories.per.side'];
         }
     }
     $this->setState('list.limit', $limit);
     $this->setState('filter.language', $app->getLanguageFilter());
     $this->setState('layout', $jinput->get('layout'));
 }
Esempio n. 2
0
 /**
  * Build the orderby for the query
  *
  * @return	string	$orderby portion of query
  * @since	1.5
  */
 protected function _buildContentOrderBy()
 {
     global $jlistConfig;
     $app = JFactory::getApplication('site');
     $db = $this->getDbo();
     $params = $this->state->params;
     $itemid = JRequest::getInt('catid', 0) . ':' . JRequest::getInt('Itemid', 0);
     $orderCol = $app->getUserStateFromRequest('com_jdownloads.category.' . $itemid . '.filter_order', 'filter_order', '', 'string');
     if ($orderCol == '') {
         $orderCol = $this->state->get('list.ordering');
     }
     $orderDirn = $app->getUserStateFromRequest('com_jdownloads.category.' . $itemid . '.filter_order_Dir', 'filter_order_Dir', '', 'cmd');
     if ($orderDirn == '') {
         $orderDirn = $this->state->get('list.direction');
     }
     $orderby = ' ';
     if (!in_array($orderCol, $this->filter_fields)) {
         $orderCol = null;
     }
     if (!in_array(strtoupper($orderDirn), array('ASC', 'DESC', ''))) {
         $orderDirn = '';
     }
     /* if ($orderCol && $orderDirn) {
     			$orderby .= $db->escape($orderCol) . ' ' . $db->escape($orderDirn) . ' ';
     		} else {
                 $orderby .= $db->escape($orderCol) .' ';
                 
             } */
     $filesOrderby = $params->get('orderby_sec', '');
     // we have uses in the jD configuration the old numerical values (to be compatible) so we must correct it here at first
     $config_cats_order = JDHelper::getCorrectedOrderbyValues('primary', $jlistConfig['cats.order']);
     $categoryOrderby = $params->def('orderby_pri', $config_cats_order);
     if ($filesOrderby) {
         $secondary = JDContentHelperQuery::orderbySecondary($filesOrderby) . ' ';
     } else {
         $secondary = JDContentHelperQuery::orderbySecondary($orderCol) . ' ';
     }
     $primary = JDContentHelperQuery::orderbyPrimary($categoryOrderby);
     $orderby .= $db->escape($primary) . ' ' . $db->escape($secondary) . ' ';
     // a.created ';
     return $orderby;
 }
Esempio n. 3
0
 /**
  * Returns an array of the categories 
  *
  * @param   boolean     $show_empty_categories  the selected value in menu item or configuration
  *          string      $orderby_pri            the primary sort order
  *
  * @return  array
  *
  */
 public static function getCategoriesList($show_empty_categories, $orderby_pri = '')
 {
     global $jlistConfig;
     // use default sort order or menu order settings
     if (empty($orderby_pri) || !isset($orderby_pri)) {
         // use config settings
         switch ($jlistConfig['cats.order']) {
             case '1':
                 // files title field asc
                 $orderCol = 'c.title ';
                 $categoryOrderby = 'alpha';
                 break;
             case '2':
                 // files title field desc
                 $orderCol = 'c.title DESC ';
                 $categoryOrderby = 'ralpha';
                 break;
             default:
                 // files ordering field
                 $orderCol = 'c.lft ';
                 $categoryOrderby = '';
                 break;
         }
     } else {
         // use order from menu settings
         $categoryOrderby = $orderby_pri;
         $orderCol = str_replace(', ', '', JDContentHelperQuery::orderbyPrimary($categoryOrderby));
     }
     $user = JFactory::getUser();
     $db = JFactory::getDbo();
     $query = $db->getQuery(true);
     $query->select('c.*, c.parent_id AS parent');
     $query->from('#__jdownloads_categories AS c');
     $query->where('c.parent_id > 0');
     $query->where('c.published = 1');
     $query->where('c.access IN (' . implode(',', $user->getAuthorisedViewLevels()) . ')');
     // The number of child category levels
     $levels = (int) $jlistConfig['show.header.catlist.levels'];
     if ($levels > 0) {
         $query->where('c.level BETWEEN 1 AND ' . $levels);
     }
     $query->leftJoin($db->quoteName('#__jdownloads_files') . ' AS files ON files.cat_id = c.id AND files.published = 1');
     $query->select('COUNT(files.' . $db->quoteName('file_id') . ') as numitems ');
     $query->group('c.id, c.title, c.cat_dir_parent');
     if ($categoryOrderby == 'alpha') {
         $query->order('c.level ASC, c.parent_id ASC, c.title ASC');
     } elseif ($categoryOrderby == 'ralpha') {
         $query->order('c.level ASC, c.parent_id ASC, c.title DESC');
     } else {
         $query->order('c.lft');
     }
     $db->setQuery($query);
     $rows = $db->loadObjectList();
     // use selected value for 'view empty category' option
     if (!$show_empty_categories) {
         foreach ($rows as &$row) {
             if ($row->numitems > 0) {
                 $cats[] = $row;
             }
         }
     } else {
         $cats = $rows;
     }
     // Order subcategories
     if (count($cats)) {
         if ($categoryOrderby == 'alpha' || $categoryOrderby == 'ralpha') {
             $i = 0;
             $depth = 0;
             $parent_id = 0;
             $parents = array();
             foreach ($cats as $cat) {
                 if ($depth < $cat->level || $parent_id < $cat->parent_id) {
                     $i = @$parents["{$cat->parent_id}"] + 1;
                 }
                 $tree[$i] = $cat;
                 $parents["{$cat->id}"] = $i;
                 $depth = $cat->level;
                 $parent_id = $cat->parent_id;
                 $i += ($cat->rgt - $cat->lft - 1) / 2 + 1;
             }
             ksort($tree);
             $cats = $tree;
         }
     }
     foreach ($cats as &$cat) {
         $repeat = $cat->level - 1 >= 0 ? $cat->level - 1 : 0;
         $cat->title = str_repeat('- ', $repeat) . $cat->title;
     }
     return $cats;
 }