public function generateBehaviors($table)
    {
        $available = [
            [
                'name' => 'blameable',
                'attributes' => ['author_id', 'created_by', 'created_id'],
                'class' => \netis\crud\db\BlameableBehavior::className(),
                'optionName' => 'createdByAttribute',
            ],
            [
                'name' => 'blameable',
                'attributes' => ['editor_id', 'edited_by', 'updated_by', 'updated_id', 'last_editor_id'],
                'class' => \netis\crud\db\BlameableBehavior::className(),
                'optionName' => 'updatedByAttribute',
            ],
            [
                'name' => 'blameable',
                'attributes' => ['update_reason'],
                'class' => \netis\crud\db\BlameableBehavior::className(),
                'optionName' => 'updateNotesAttribute',
            ],
            [
                'name' => 'timestamp',
                'attributes' => ['created_on', 'created_at', 'create_at', 'created_date', 'date_created'],
                'class' => \netis\crud\db\TimestampBehavior::className(),
                'optionName' => 'createdAtAttribute',
            ],
            [
                'name' => 'timestamp',
                'attributes' => ['updated_on', 'updated_at', 'update_at', 'updated_date', 'date_updated'],
                'class' => \netis\crud\db\TimestampBehavior::className(),
                'optionName' => 'updatedAtAttribute',
            ],
            [
                'name' => 'toggable',
                'attributes' => [
                    'is_disabled', 'disabled', 'is_deleted', 'deleted', 'is_removed', 'removed', 'is_hidden', 'hidden',
                ],
                'class' => \netis\crud\db\ToggableBehavior::className(),
                'optionName' => 'disabledAttribute',
            ],
            [
                'name' => 'toggable',
                'attributes' => ['is_enabled', 'enabled', 'is_active', 'active', 'is_visible', 'visible'],
                'class' => \netis\crud\db\ToggableBehavior::className(),
                'optionName' => 'enabledAttribute',
            ],
            [
                'name' => 'sortable',
                'attributes' => ['display_order', 'sort_order'],
                'class' => \netis\crud\db\SortableBehavior::className(),
                'optionName' => 'attribute',
            ],
            [
                'name' => 'versioned',
                'attributes' => ['version'],
                // invalid behavior: doesn't have a class or optionName,
                // has to be turned into a method in the model template
            ],
        ];
        $behaviors = [
            'labels' => [
                'class' => \netis\crud\db\LabelsBehavior::className(),
                'options' => [
                    'attributes' => [$this->getLabelAttribute($table)],
                ],
            ],
        ];
        foreach ($table->columns as $column) {
            foreach ($available as $options) {
                if (in_array($column->name, $options['attributes'])) {
                    if (isset($options['class'])) {
                        $behaviors[$options['name']]['class']                           = $options['class'];
                        $behaviors[$options['name']]['options'][$options['optionName']] = $column->name;
                    } else {
                        $behaviors[$options['name']] = $column->name;
                    }
                    break;
                }
            }
        }
        return $behaviors;
    }
public function generateBehaviors($table)
    {
        $available = [
            [
                'name' => 'blameable',
                'attributes' => ['author_id', 'created_by', 'created_id'],
                'class' => \netis\crud\db\BlameableBehavior::className(),
                'optionName' => 'createdByAttribute',
            ],
            [
                'name' => 'blameable',
                'attributes' => ['editor_id', 'edited_by', 'updated_by', 'updated_id', 'last_editor_id'],
                'class' => \netis\crud\db\BlameableBehavior::className(),
                'optionName' => 'updatedByAttribute',
            ],
            [
                'name' => 'blameable',
                'attributes' => ['update_reason'],
                'class' => \netis\crud\db\BlameableBehavior::className(),
                'optionName' => 'updateNotesAttribute',
            ],
            [
                'name' => 'timestamp',
                'attributes' => ['created_on', 'created_at', 'create_at', 'created_date', 'date_created'],
                'class' => \netis\crud\db\TimestampBehavior::className(),
                'optionName' => 'createdAtAttribute',
            ],
            [
                'name' => 'timestamp',
                'attributes' => ['updated_on', 'updated_at', 'update_at', 'updated_date', 'date_updated'],
                'class' => \netis\crud\db\TimestampBehavior::className(),
                'optionName' => 'updatedAtAttribute',
            ],
            [
                'name' => 'toggable',
                'attributes' => [
                    'is_disabled', 'disabled', 'is_deleted', 'deleted', 'is_removed', 'removed', 'is_hidden', 'hidden',
                ],
                'class' => \netis\crud\db\ToggableBehavior::className(),
                'optionName' => 'disabledAttribute',
            ],
            [
                'name' => 'toggable',
                'attributes' => ['is_enabled', 'enabled', 'is_active', 'active', 'is_visible', 'visible'],
                'class' => \netis\crud\db\ToggableBehavior::className(),
                'optionName' => 'enabledAttribute',
            ],
            [
                'name' => 'sortable',
                'attributes' => ['display_order', 'sort_order'],
                'class' => \netis\crud\db\SortableBehavior::className(),
                'optionName' => 'attribute',
            ],
            [
                'name' => 'versioned',
                'attributes' => ['version'],
                // invalid behavior: doesn't have a class or optionName,
                // has to be turned into a method in the model template
            ],
        ];
        $behaviors = [
            'labels' => [
                'class' => \netis\crud\db\LabelsBehavior::className(),
                'options' => [
                    'attributes' => [$this->getLabelAttribute($table)],
                ],
            ],
        ];
        foreach ($table->columns as $column) {
            foreach ($available as $options) {
                if (in_array($column->name, $options['attributes'])) {
                    if (isset($options['class'])) {
                        $behaviors[$options['name']]['class']                           = $options['class'];
                        $behaviors[$options['name']]['options'][$options['optionName']] = $column->name;
                    } else {
                        $behaviors[$options['name']] = $column->name;
                    }
                    break;
                }
            }
        }
        return $behaviors;
    }
public function generateBehaviors ( $ table ) { $ available = [ [ 'name' => 'blameable' , 'attributes' => [ 'author_id' , 'created_by' , 'created_id' ] , 'class' => \ netis \ crud \ db \ BlameableBehavior :: className ( ) , 'optionName' => 'createdByAttribute' , ] , [ 'name' => 'blameable' , 'attributes' => [ 'editor_id' , 'edited_by' , 'updated_by' , 'updated_id' , 'last_editor_id' ] , 'class' => \ netis \ crud \ db \ BlameableBehavior :: className ( ) , 'optionName' => 'updatedByAttribute' , ] , [ 'name' => 'blameable' , 'attributes' => [ 'update_reason' ] , 'class' => \ netis \ crud \ db \ BlameableBehavior :: className ( ) , 'optionName' => 'updateNotesAttribute' , ] , [ 'name' => 'timestamp' , 'attributes' => [ 'created_on' , 'created_at' , 'create_at' , 'created_date' , 'date_created' ] , 'class' => \ netis \ crud \ db \ TimestampBehavior :: className ( ) , 'optionName' => 'createdAtAttribute' , ] , [ 'name' => 'timestamp' , 'attributes' => [ 'updated_on' , 'updated_at' , 'update_at' , 'updated_date' , 'date_updated' ] , 'class' => \ netis \ crud \ db \ TimestampBehavior :: className ( ) , 'optionName' => 'updatedAtAttribute' , ] , [ 'name' => 'toggable' , 'attributes' => [ 'is_disabled' , 'disabled' , 'is_deleted' , 'deleted' , 'is_removed' , 'removed' , 'is_hidden' , 'hidden' , ] , 'class' => \ netis \ crud \ db \ ToggableBehavior :: className ( ) , 'optionName' => 'disabledAttribute' , ] , [ 'name' => 'toggable' , 'attributes' => [ 'is_enabled' , 'enabled' , 'is_active' , 'active' , 'is_visible' , 'visible' ] , 'class' => \ netis \ crud \ db \ ToggableBehavior :: className ( ) , 'optionName' => 'enabledAttribute' , ] , [ 'name' => 'sortable' , 'attributes' => [ 'display_order' , 'sort_order' ] , 'class' => \ netis \ crud \ db \ SortableBehavior :: className ( ) , 'optionName' => 'attribute' , ] , [ 'name' => 'versioned' , 'attributes' => [ 'version' ] , // invalid behavior: doesn't have a class or optionName, // has to be turned into a method in the model template ] , ] ; $ behaviors = [ 'labels' => [ 'class' => \ netis \ crud \ db \ LabelsBehavior :: className ( ) , 'options' => [ 'attributes' => [ $ this -> getLabelAttribute ( $ table ) ] , ] , ] , ] ; foreach ( $ table -> columns as $ column ) { foreach ( $ available as $ options ) { if ( in_array ( $ column -> name , $ options [ 'attributes' ] ) ) { if ( isset ( $ options [ 'class' ] ) ) { $ behaviors [ $ options [ 'name' ] ] [ 'class' ] = $ options [ 'class' ] ; $ behaviors [ $ options [ 'name' ] ] [ 'options' ] [ $ options [ 'optionName' ] ] = $ column -> name ; } else { $ behaviors [ $ options [ 'name' ] ] = $ column -> name ; } break ; } } } return $ behaviors ; }
Generates behaviors for the specified table, detecting special columns.
@param \yii\db\TableSchema $table the table schema
@return array the generated behaviors as name => options
Generates behaviors for the specified table detecting special columns .