/** * 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; }
/** * 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')); }