Exemplo n.º 1
0
 /**
  * Process ordering query.
  *
  * @param JDatabaseQuery $query     The query object.
  * @param string         $ordering  The ordering string.
  * @param string         $direction ASC or DESC.
  *
  * @return  void
  */
 protected function processOrdering(JDatabaseQuery $query, $ordering = null, $direction = null)
 {
     $ordering = $ordering ?: $this->get('list.ordering');
     // If no ordering set, ignore this function.
     if (!$ordering) {
         return;
     }
     $direction = $direction ?: $this->get('list.direction', 'ASC');
     $ordering = explode(',', $ordering);
     // Add quote
     foreach ($ordering as $key => &$value) {
         // Remove extra spaces
         preg_replace('/\\s+/', ' ', trim($value));
         $value = StringHelper::explode(' ', $value);
         if (!$this->filterField($value[0])) {
             unset($ordering[$key]);
             continue;
         }
         $value[0] = $this->mapField($value[0]);
         // Ignore expression
         if (!empty($value[0]) && $value[0][strlen($value[0]) - 1] != ')') {
             $value[0] = $query->quoteName($value[0]);
         }
         $value = implode(' ', $value);
     }
     $ordering = implode(', ', $ordering);
     if (!$ordering) {
         return;
     }
     $query->order($ordering . ' ' . $direction);
 }