Ejemplo n.º 1
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;
 }
Ejemplo n.º 2
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'));
 }
Ejemplo n.º 3
0
 /**
  * Method to auto-populate the model state.
  *
  * Note. Calling getState in this method will result in recursion.
  *
  * @return	void
  */
 protected function populateState($ordering = 'ordering', $direction = 'ASC')
 {
     global $jlistConfig;
     $app = JFactory::getApplication();
     $jinput = JFactory::getApplication()->input;
     $type = JRequest::getString('type', '');
     if ($type == 'uncategorised') {
         $this->setState('only_uncategorised', true);
     } else {
         $this->setState('only_uncategorised', false);
     }
     // 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();
     $listOrderNew = false;
     // Create a new query object.
     $db = $this->getDbo();
     $query = $db->getQuery(true);
     $groups = implode(',', $user->getAuthorisedViewLevels());
     $menu_params = $this->state->params;
     if (!$user->authorise('core.edit.state', 'com_jdownloads') && !$user->authorise('core.edit', 'com_jdownloads')) {
         // limit to published for people who can't edit or edit.state.
         $this->setState('filter.published', 1);
         // Filter by start and end dates.
         $nullDate = $db->Quote($db->getNullDate());
         $nowDate = $db->Quote(JFactory::getDate()->toSql());
         // True to return the date string in the local time zone, false to return it in GMT.
         $query->where('(a.publish_from = ' . $nullDate . ' OR a.publish_from <= ' . $nowDate . ')');
         $query->where('(a.publish_to = ' . $nullDate . ' OR a.publish_to >= ' . $nowDate . ')');
     } else {
         $this->setState('filter.published', array(0, 1, 2));
     }
     // process show_noauth parameter
     if (!$params->get('show_noauth')) {
         $this->setState('filter.access', true);
     } else {
         $this->setState('filter.access', false);
     }
     // Optional filter text
     $this->setState('list.filter', JRequest::getString('filter-search'));
     // filter.order
     $orderCol = $app->getUserStateFromRequest('com_jdownloads.downloads.filter_order', 'filter_order', '', 'string');
     if (!in_array($orderCol, $this->filter_fields) || $orderCol == '') {
         // use default sort order or menu order settings
         if ($menu_params->get('orderby_sec') == '') {
             // use config settings
             switch ($jlistConfig['files.order']) {
                 case '0':
                     // files ordering field
                     $orderCol = 'a.ordering';
                     $listOrderNew = 'ASC';
                     break;
                 case '1':
                     // files date_added desc
                     $orderCol = 'a.date_added';
                     // desc
                     $listOrderNew = 'DESC';
                     break;
                 case '2':
                     // files date_added asc
                     $orderCol = 'a.date_added';
                     // asc
                     $listOrderNew = 'ASC';
                     break;
                 case '3':
                     // files title field asc
                     $orderCol = 'a.file_title';
                     $listOrderNew = 'ASC';
                     break;
                 case '4':
                     // files title field desc
                     $orderCol = 'a.file_title';
                     $listOrderNew = 'DESC';
                     break;
                 case '5':
                     // files hits/downloads field desc
                     $orderCol = 'a.downloads';
                     $listOrderNew = 'DESC';
                     break;
                 case '6':
                     // files hits/downloads field asc
                     $orderCol = 'a.downloads';
                     $listOrderNew = 'ASC';
                     break;
                 case '7':
                     // author title field asc
                     $orderCol = 'a.author';
                     $listOrderNew = 'ASC';
                     break;
                 case '8':
                     // author title field desc
                     $orderCol = 'a.author';
                     $listOrderNew = 'DESC';
                     break;
             }
         } else {
             // use order from menu settings
             $filesOrderby = $params->get('orderby_sec', 'order');
             $orderCol = JDContentHelperQuery::orderbySecondary($filesOrderby) . ' ';
             $order_array = explode(' ', $orderCol);
             if (count($order_array > 2)) {
                 $orderCol = $order_array[0];
                 $listOrderNew = $order_array[1];
             }
         }
     }
     $this->setState('list.ordering', $orderCol);
     $listOrder = $app->getUserStateFromRequest('com_jdownloads.downloads.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->input->get('limit', false, 'uint');
     if ($limit === false) {
         if ((int) $menu_params->get('display_num') > 0) {
             $limit = (int) $menu_params->get('display_num');
         } else {
             $limit = (int) $jlistConfig['files.per.side'];
         }
     }
     $this->setState('list.limit', $limit);
     $this->setState('filter.language', $app->getLanguageFilter());
     $this->setState('layout', $jinput->get('layout'));
 }
Ejemplo n.º 4
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;
 }