public function buildSort(Fetcher $fetcher)
 {
     $sorts = array();
     $_sorts = $fetcher->getSorts();
     foreach ($_sorts as $column => $sort) {
         $sorts[$column] = $sort === Fetcher::SORT_ASC ? 1 : -1;
     }
     if (count($sorts) < 1) {
         $sorts['_id'] = 1;
     }
     return $sorts;
 }
 public function buildSort(Fetcher $fetcher)
 {
     $sorts = array();
     $_sorts = $fetcher->getSorts();
     foreach ($_sorts as $column => $sort) {
         $sorts[] = $column . ' ' . $sort;
     }
     if (count($sorts) < 1) {
         $sorts[] = "id ASC";
     }
     return implode(", ", $sorts);
 }
 /**
  * @param Fetcher $fetcher
  * @param string  $mainTableAlias
  * @return string[]
  */
 protected function getQueryParameters(Fetcher $fetcher = null, $mainTableAlias = 'ref')
 {
     $select = '';
     $from = '';
     if ($fetcher != null) {
         $selectedColumns = array();
         $selectedJoins = array();
         $columns = $fetcher->getFilterColumns();
         foreach ($columns as $column) {
             list($selectedColumns, $selectedJoins) = $this->getSelectedColumnsJoins($column, $mainTableAlias, $selectedColumns, $selectedJoins);
         }
         $sorts = $fetcher->getSorts();
         foreach ($sorts as $column => $sortOrder) {
             list($selectedColumns, $selectedJoins) = $this->getSelectedColumnsJoins($column, $mainTableAlias, $selectedColumns, $selectedJoins);
         }
         $toUse = array();
         foreach ($selectedColumns as $key => $value) {
             if ($mainTableAlias . '.id' !== $value) {
                 $toUse[$key] = $value;
             }
         }
         if (!empty($toUse)) {
             $select = ', ' . implode(', ', $toUse);
         }
         if (!empty($selectedJoins)) {
             $joins = $this->getJoins();
             $selectedJoinsSql = array_intersect_key($joins, $selectedJoins);
             $from = implode(' ', $selectedJoinsSql);
         }
     }
     return array($select, $from);
 }