Skip to content

Commit

Permalink
update settings grid, update migration
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Chepurnoy committed Aug 3, 2016
1 parent 3e56203 commit 7ffce37
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 14 deletions.
2 changes: 1 addition & 1 deletion migrations/m150227_114524_init.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function up()
'section' => $this->string()->notNull(),
'key' => $this->string()->notNull(),
'value' => $this->text()->notNull(),
'status' => $this->boolean(),
'status' => $this->smallInteger()->notNull()->defaultValue(1),
'createdAt' => $this->integer()->notNull(),
'updatedAt' => $this->integer()->notNull()
], $tableOptions);
Expand Down
6 changes: 4 additions & 2 deletions models/SettingModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use yii\db\ActiveRecord;
use yii\helpers\ArrayHelper;
use Yii;
use yii2mod\enum\helpers\BooleanEnum;
use yii2mod\settings\models\enumerables\SettingStatus;
use yii2mod\settings\models\enumerables\SettingType;

Expand Down Expand Up @@ -44,7 +43,8 @@ public function rules()
[['value', 'type'], 'string'],
[['section', 'key'], 'string', 'max' => 255],
[['status'], 'integer'],
['status', 'default', 'value' => BooleanEnum::YES],
['status', 'default', 'value' => SettingStatus::ACTIVE],
['status', 'in', 'range' => [SettingStatus::ACTIVE, SettingStatus::INACTIVE]],
[['type'], 'safe'],
];
}
Expand Down Expand Up @@ -98,6 +98,7 @@ public static function find()
public function afterDelete()
{
Yii::$app->settings->invalidateCache();

parent::afterDelete();
}

Expand All @@ -110,6 +111,7 @@ public function afterDelete()
public function afterSave($insert, $changedAttributes)
{
Yii::$app->settings->invalidateCache();

parent::afterSave($insert, $changedAttributes);
}

Expand Down
16 changes: 7 additions & 9 deletions models/search/SettingModelSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace yii2mod\settings\models\search;

use Yii;
use yii\data\ActiveDataProvider;
use yii2mod\settings\models\SettingModel;

Expand All @@ -13,25 +12,25 @@
class SettingModelSearch extends SettingModel
{
/**
* Returns the validation rules for attributes.
* @return array validation rules
* @inheritdoc
*/
public function rules()
{
return [
[['id', 'type', 'section', 'key', 'value', 'status'], 'safe'],
[['type', 'section', 'key', 'value', 'status'], 'safe'],
];
}

/**
* Setup search function for filtering and sorting
* based on fullName field
* Creates data provider instance with search query applied
*
* @param $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = SettingModel::find();
$query = self::find();

$dataProvider = new ActiveDataProvider([
'query' => $query,
Expand All @@ -44,7 +43,6 @@ public function search($params)
return $dataProvider;
}

$query->andFilterWhere(['id' => $this->id]);
$query->andFilterWhere(['status' => $this->status]);
$query->andFilterWhere(['section' => $this->section]);
$query->andFilterWhere(['type' => $this->type]);
Expand All @@ -53,4 +51,4 @@ public function search($params)

return $dataProvider;
}
}
}
2 changes: 1 addition & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ protected function setupTestDbData()
'section' => 'string not null',
'key' => 'string not null',
'value' => 'text not null',
'status' => 'integer',
'status' => 'smallint not null default 1',
'createdAt' => 'integer not null',
'updatedAt' => 'integer not null',
])->execute();
Expand Down
1 change: 0 additions & 1 deletion views/default/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
[
'class' => 'yii\grid\SerialColumn',
],
'id',
[
'attribute' => 'type',
'filter' => SettingType::listData(),
Expand Down

0 comments on commit 7ffce37

Please sign in to comment.