/**
  * THe ordering handler.
  *
  * @param array     $value        The ordering value.
  * @param array     $orderConfig  Ordering and direction array.
  * @param ListModel $model        The List model.
  *
  * @return array The handled ordering and direction array.
  */
 public static function handleFullordering($value, $orderConfig, ListModel $model)
 {
     if (!$orderConfig) {
         $orderConfig = array('ordering' => null, 'direction' => null);
     }
     $orderingParts = explode(',', $value);
     $ordering = array();
     foreach ($orderingParts as $order) {
         $order = explode(' ', trim($order));
         if (count($order) == 2) {
             list($col, $dir) = $order;
         } else {
             $col = $order[0];
             $dir = '';
         }
         if ($model->filterField($col)) {
             $ordering[] = $dir ? $col . ' ' . strtoupper($dir) : $col;
         }
     }
     if (!count($ordering)) {
         return $orderConfig;
     }
     $last = array_pop($ordering);
     $last = explode(' ', $last);
     if (isset($last[1]) && in_array(strtoupper($last[1]), array('ASC', 'DESC'))) {
         $orderConfig['direction'] = $last[1];
     }
     $ordering[] = $last[0];
     $orderConfig['ordering'] = implode(', ', $ordering);
     return $orderConfig;
 }
Ejemplo n.º 2
0
 /**
  * Process the query filters.
  *
  * @param JDatabaseQuery $query   The query object.
  * @param array          $filters The filters values.
  *
  * @return  JDatabaseQuery The db query object.
  */
 protected function processFilters(\JDatabaseQuery $query, $filters = array())
 {
     return parent::processFilters($query, $filters);
 }
Ejemplo n.º 3
0
 /**
  * Process the query filters.
  *
  * @param JDatabaseQuery $query   The query object.
  * @param array          $filters The filters values.
  *
  * @return  JDatabaseQuery The db query object.
  */
 protected function processFilters(\JDatabaseQuery $query, $filters = array())
 {
     $user = $this->container->get('user');
     $db = $this->container->get('db');
     $date = $this->container->get('date');
     // If no state filter, set published >= 0
     if (!isset($filters['user.state']) && property_exists($this->getTable(), 'state')) {
         $query->where($query->quoteName('user.state') . ' >= 0');
     }
     // Category
     // =====================================================================================
     $category = $this->getCategory();
     if ($category->id != 1 && in_array('category.lft', $this->filterFields) && in_array('category.rgt', $this->filterFields)) {
         $query->where($query->format('(%n >= %a AND %n <= %a)', 'category.lft', $category->lft, 'category.rgt', $category->rgt));
     }
     // Max Level
     // =====================================================================================
     $maxLevel = $this->state->get('filter.max_category_levels', -1);
     if ($maxLevel > 0) {
         $query->where($query->quoteName('category.level') . " <= " . $maxLevel);
     }
     // Edit Access
     // =====================================================================================
     if ($this->state->get('filter.unpublished')) {
         $query->where('user.state >= 0');
     } else {
         $query->where('user.state > 0');
         $nullDate = $query->Quote($db->getNullDate());
         $nowDate = $query->Quote($date->toSQL(true));
         if (in_array('user.publish_up', $this->filterFields) && in_array('user.publish_down', $this->filterFields)) {
             $query->where('(user.publish_up = ' . $nullDate . ' OR user.publish_up <= ' . $nowDate . ')');
             $query->where('(user.publish_down = ' . $nullDate . ' OR user.publish_down >= ' . $nowDate . ')');
         }
     }
     // View Level
     // =====================================================================================
     if ($access = $this->state->get('filter.access') && in_array('user.access', $this->filterFields)) {
         $query->where(new InCompare('user.access', $user->getAuthorisedViewLevels()));
     }
     // Language
     // =====================================================================================
     if ($this->state->get('filter.language') && in_array('a.language', $this->filterFields)) {
         $lang_code = $db->quote(JFactory::getLanguage()->getTag());
         $query->where("a.language IN ('{$lang_code}', '*')");
     }
     return parent::processFilters($query, $filters);
 }
Ejemplo n.º 4
0
 /**
  * Process the query filters.
  *
  * @param JDatabaseQuery $query   The query object.
  * @param array          $filters The filters values.
  *
  * @return  JDatabaseQuery The db query object.
  */
 protected function processFilters(\JDatabaseQuery $query, $filters = array())
 {
     // If no state filter, set published >= 0
     if (!isset($filters['list.state']) && property_exists($this->getTable(), 'state')) {
         $query->where($query->quoteName('list.state') . ' >= 0');
     }
     return parent::processFilters($query, $filters);
 }
 /**
  * Method to test removeTable().
  *
  * @return void
  *
  * @covers Windwalker\Model\ListModel::removeTable
  */
 public function testRemoveTable()
 {
     $config = array('prefix' => 'foo', 'name' => 'bar');
     $listModel = new ListModel($config);
     $mock = $this->getMockBuilder('\\Windwalker\\Model\\Helper\\QueryHelper')->setMethods(array('removeTable'))->getMock();
     $listModel->setQueryHelper($mock);
     $mock->expects($this->once())->method('removeTable')->with('alias');
     $listModel->removeTable('alias');
 }
Ejemplo n.º 6
0
 /**
  * Method to auto-populate the model state.
  *
  * This method will only called in constructor. Using `ignore_request` to ignore this method.
  *
  * @param   string  $ordering   An optional ordering field.
  * @param   string  $direction  An optional direction (asc|desc).
  *
  * @return  void
  */
 protected function populateState($ordering = null, $direction = 'ASC')
 {
     parent::populateState($ordering, $direction);
     $this->state->set('import_num', $this->getUserStateFromRequest('import_num', 'import_num', 50));
 }
Ejemplo n.º 7
0
 /**
  * Process the query filters.
  *
  * @param JDatabaseQuery $query   The query object.
  * @param array          $filters The filters values.
  *
  * @return  JDatabaseQuery The db query object.
  */
 protected function processFilters(\JDatabaseQuery $query, $filters = array())
 {
     $filters = $filters ?: $this->state->get('filter', array());
     if (!isset($filters['module.client_id'])) {
         $query->where('module.client_id = "0"');
     }
     return parent::processFilters($query, $filters);
 }
Ejemplo n.º 8
0
 /**
  * Process the query filters.
  *
  * @param JDatabaseQuery $query   The query object.
  * @param array          $filters The filters values.
  *
  * @return  JDatabaseQuery The db query object.
  */
 protected function processFilters(\JDatabaseQuery $query, $filters = array())
 {
     // If no state filter, set published >= 0
     if (!isset($filters['icon.published'])) {
         $query->where($query->quoteName('icon.published') . ' >= 0');
     }
     return parent::processFilters($query, $filters);
 }