Exemplo n.º 1
0
 /**
  * Creates a Sort object configuration using query default order.
  * @param \yii\db\ActiveQuery $query
  * @param array $attributes
  * @return array
  */
 public function getSortConfig(\yii\db\ActiveQuery $query, array $attributes)
 {
     $defaults = $query instanceof ActiveQuery ? $query->getDefaultOrderColumns() : [];
     $sort = ['enableMultiSort' => true, 'attributes' => [], 'defaultOrder' => $defaults];
     /** @var TableSchema $tableSchema */
     $tableSchema = $this->getTableSchema();
     foreach ($attributes as $attribute) {
         if ($tableSchema->getColumn($attribute) === null) {
             continue;
         }
         $sort['attributes'][$attribute] = ['asc' => array_merge([$attribute => SORT_ASC], $defaults), 'desc' => array_merge([$attribute => SORT_DESC], $defaults)];
     }
     return $sort;
 }