Skip to content

Commit 7ffce37

Browse files
author
Igor Chepurnoy
committed
update settings grid, update migration
1 parent 3e56203 commit 7ffce37

File tree

5 files changed

+13
-14
lines changed

5 files changed

+13
-14
lines changed

migrations/m150227_114524_init.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function up()
2424
'section' => $this->string()->notNull(),
2525
'key' => $this->string()->notNull(),
2626
'value' => $this->text()->notNull(),
27-
'status' => $this->boolean(),
27+
'status' => $this->smallInteger()->notNull()->defaultValue(1),
2828
'createdAt' => $this->integer()->notNull(),
2929
'updatedAt' => $this->integer()->notNull()
3030
], $tableOptions);

models/SettingModel.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use yii\db\ActiveRecord;
77
use yii\helpers\ArrayHelper;
88
use Yii;
9-
use yii2mod\enum\helpers\BooleanEnum;
109
use yii2mod\settings\models\enumerables\SettingStatus;
1110
use yii2mod\settings\models\enumerables\SettingType;
1211

@@ -44,7 +43,8 @@ public function rules()
4443
[['value', 'type'], 'string'],
4544
[['section', 'key'], 'string', 'max' => 255],
4645
[['status'], 'integer'],
47-
['status', 'default', 'value' => BooleanEnum::YES],
46+
['status', 'default', 'value' => SettingStatus::ACTIVE],
47+
['status', 'in', 'range' => [SettingStatus::ACTIVE, SettingStatus::INACTIVE]],
4848
[['type'], 'safe'],
4949
];
5050
}
@@ -98,6 +98,7 @@ public static function find()
9898
public function afterDelete()
9999
{
100100
Yii::$app->settings->invalidateCache();
101+
101102
parent::afterDelete();
102103
}
103104

@@ -110,6 +111,7 @@ public function afterDelete()
110111
public function afterSave($insert, $changedAttributes)
111112
{
112113
Yii::$app->settings->invalidateCache();
114+
113115
parent::afterSave($insert, $changedAttributes);
114116
}
115117

models/search/SettingModelSearch.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace yii2mod\settings\models\search;
44

5-
use Yii;
65
use yii\data\ActiveDataProvider;
76
use yii2mod\settings\models\SettingModel;
87

@@ -13,25 +12,25 @@
1312
class SettingModelSearch extends SettingModel
1413
{
1514
/**
16-
* Returns the validation rules for attributes.
17-
* @return array validation rules
15+
* @inheritdoc
1816
*/
1917
public function rules()
2018
{
2119
return [
22-
[['id', 'type', 'section', 'key', 'value', 'status'], 'safe'],
20+
[['type', 'section', 'key', 'value', 'status'], 'safe'],
2321
];
2422
}
2523

2624
/**
27-
* Setup search function for filtering and sorting
28-
* based on fullName field
25+
* Creates data provider instance with search query applied
26+
*
2927
* @param $params
28+
*
3029
* @return ActiveDataProvider
3130
*/
3231
public function search($params)
3332
{
34-
$query = SettingModel::find();
33+
$query = self::find();
3534

3635
$dataProvider = new ActiveDataProvider([
3736
'query' => $query,
@@ -44,7 +43,6 @@ public function search($params)
4443
return $dataProvider;
4544
}
4645

47-
$query->andFilterWhere(['id' => $this->id]);
4846
$query->andFilterWhere(['status' => $this->status]);
4947
$query->andFilterWhere(['section' => $this->section]);
5048
$query->andFilterWhere(['type' => $this->type]);
@@ -53,4 +51,4 @@ public function search($params)
5351

5452
return $dataProvider;
5553
}
56-
}
54+
}

tests/TestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ protected function setupTestDbData()
8989
'section' => 'string not null',
9090
'key' => 'string not null',
9191
'value' => 'text not null',
92-
'status' => 'integer',
92+
'status' => 'smallint not null default 1',
9393
'createdAt' => 'integer not null',
9494
'updatedAt' => 'integer not null',
9595
])->execute();

views/default/index.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
[
2828
'class' => 'yii\grid\SerialColumn',
2929
],
30-
'id',
3130
[
3231
'attribute' => 'type',
3332
'filter' => SettingType::listData(),

0 commit comments

Comments
 (0)