public function getDefaultOrderColumns()
    {
        /* @var $model ActiveRecord */
        $model = new $this->modelClass;
        $columns = $model->getTableSchema()->columns;
        try {
            $indexes = $model->getDb()->getSchema()->findUniqueIndexes($model->getTableSchema());
            $unique = empty($indexes) ? [] : array_flip(call_user_func_array('array_merge', $indexes));
        } catch (NotSupportedException $e) {
            $unique = null;
        }
        $order = [];
        $modelAttributes = array_flip($model->attributes());
        foreach ($model->getBehaviors() as $name => $behavior) {
            if ($behavior instanceof SortableBehavior) {
                $attributes = [$behavior->attribute];
            } elseif ($behavior instanceof LabelsBehavior) {
                if ($behavior->attributes === null) {
                    continue;
                }
                $attributes = $behavior->attributes;
            } else {
                continue;
            }

            foreach ($attributes as $attribute) {
                if (!isset($modelAttributes[$attribute])) {
                    continue;
                }
                $order[$attribute] = SORT_ASC;
                if ($unique !== null && isset($unique[$attribute]) && isset($columns[$attribute])
                    && !$columns[$attribute]->allowNull
                ) {
                    return $order;
                }
            }
        }

        $order = array_merge($order, array_fill_keys($model->primaryKey(), SORT_ASC));

        return $order;
    }
public function getDefaultOrderColumns()
    {
        /* @var $model ActiveRecord */
        $model = new $this->modelClass;
        $columns = $model->getTableSchema()->columns;
        try {
            $indexes = $model->getDb()->getSchema()->findUniqueIndexes($model->getTableSchema());
            $unique = empty($indexes) ? [] : array_flip(call_user_func_array('array_merge', $indexes));
        } catch (NotSupportedException $e) {
            $unique = null;
        }
        $order = [];
        $modelAttributes = array_flip($model->attributes());
        foreach ($model->getBehaviors() as $name => $behavior) {
            if ($behavior instanceof SortableBehavior) {
                $attributes = [$behavior->attribute];
            } elseif ($behavior instanceof LabelsBehavior) {
                if ($behavior->attributes === null) {
                    continue;
                }
                $attributes = $behavior->attributes;
            } else {
                continue;
            }

            foreach ($attributes as $attribute) {
                if (!isset($modelAttributes[$attribute])) {
                    continue;
                }
                $order[$attribute] = SORT_ASC;
                if ($unique !== null && isset($unique[$attribute]) && isset($columns[$attribute])
                    && !$columns[$attribute]->allowNull
                ) {
                    return $order;
                }
            }
        }

        $order = array_merge($order, array_fill_keys($model->primaryKey(), SORT_ASC));

        return $order;
    }
public function getDefaultOrderColumns ( ) { /* @var $model ActiveRecord */ $ model = new $ this -> modelClass ; $ columns = $ model -> getTableSchema ( ) -> columns ; try { $ indexes = $ model -> getDb ( ) -> getSchema ( ) -> findUniqueIndexes ( $ model -> getTableSchema ( ) ) ; $ unique = empty ( $ indexes ) ? [ ] : array_flip ( call_user_func_array ( 'array_merge' , $ indexes ) ) ; } catch ( NotSupportedException $ e ) { $ unique = null ; } $ order = [ ] ; $ modelAttributes = array_flip ( $ model -> attributes ( ) ) ; foreach ( $ model -> getBehaviors ( ) as $ name => $ behavior ) { if ( $ behavior instanceof SortableBehavior ) { $ attributes = [ $ behavior -> attribute ] ; } elseif ( $ behavior instanceof LabelsBehavior ) { if ( $ behavior -> attributes === null ) { continue ; } $ attributes = $ behavior -> attributes ; } else { continue ; } foreach ( $ attributes as $ attribute ) { if ( ! isset ( $ modelAttributes [ $ attribute ] ) ) { continue ; } $ order [ $ attribute ] = SORT_ASC ; if ( $ unique !== null && isset ( $ unique [ $ attribute ] ) && isset ( $ columns [ $ attribute ] ) && ! $ columns [ $ attribute ] -> allowNull ) { return $ order ; } } } $ order = array_merge ( $ order , array_fill_keys ( $ model -> primaryKey ( ) , SORT_ASC ) ) ; return $ order ; }
Returns an array with default order columns, indexed by column name and with direction as value.
@return array column name => order direction
Returns an array with default order columns indexed by column name and with direction as value .