Esempio n. 1
0
 /**
  * Compiles an array of ORDER BY statements into an SQL partial.
  *
  * @param   object  $db       Alt_Database instance
  * @param   array   $columns  sorting columns
  * @return  string
  */
 protected function _compile_order_by(Alt_Database $db, array $columns)
 {
     $sort = array();
     foreach ($columns as $group) {
         list($column, $direction) = $group;
         if (is_array($column)) {
             // Use the column alias
             $column = $db->quote_identifier(end($column));
         } else {
             // Apply proper quoting to the column
             $column = $db->quote_column($column);
         }
         if ($direction) {
             // Make the direction uppercase
             $direction = ' ' . strtoupper($direction);
         }
         $sort[] = $column . $direction;
     }
     return 'ORDER BY ' . implode(', ', $sort);
 }