From d248bf1aac1a50a383437b6ba272d094a7f13d8b Mon Sep 17 00:00:00 2001 From: Igor Chepurnoy Date: Thu, 23 Mar 2017 12:46:10 +0200 Subject: [PATCH 1/2] add description column to SettingModel --- .travis.yml | 1 - messages/de/yii2mod.settings.php | 1 + messages/en/yii2mod.settings.php | 1 + messages/ru/yii2mod.settings.php | 1 + messages/uk/yii2mod.settings.php | 1 + ...dd_description_column_to_setting_table.php | 25 +++++++++++++++++++ models/SettingModel.php | 6 +++-- models/search/SettingSearch.php | 20 +++++++++------ tests/TestCase.php | 1 + views/default/_form.php | 7 +++--- views/default/create.php | 2 +- views/default/index.php | 1 + views/default/update.php | 2 +- 13 files changed, 54 insertions(+), 15 deletions(-) create mode 100644 migrations/m170323_102933_add_description_column_to_setting_table.php diff --git a/.travis.yml b/.travis.yml index 2b97385..f0db8b8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ language: php php: - - 5.6 - 7.1 # faster builds on new travis setup not using sudo diff --git a/messages/de/yii2mod.settings.php b/messages/de/yii2mod.settings.php index 8665207..1a078a4 100644 --- a/messages/de/yii2mod.settings.php +++ b/messages/de/yii2mod.settings.php @@ -23,6 +23,7 @@ 'Key' => 'Schlüssel', 'Value' => 'Wert', 'Status' => 'Status', + 'Description' => 'Beschreibung', 'Created date' => 'Erstellungsdatum', 'Updated date' => 'Änderungsdatum', 'Settings' => 'Einstellungen', diff --git a/messages/en/yii2mod.settings.php b/messages/en/yii2mod.settings.php index 80545b7..a2dfcc5 100644 --- a/messages/en/yii2mod.settings.php +++ b/messages/en/yii2mod.settings.php @@ -23,6 +23,7 @@ 'Key' => 'Key', 'Value' => 'Value', 'Status' => 'Status', + 'Description' => 'Description', 'Created date' => 'Created date', 'Updated date' => 'Updated date', 'Settings' => 'Settings', diff --git a/messages/ru/yii2mod.settings.php b/messages/ru/yii2mod.settings.php index d14b863..4afe736 100644 --- a/messages/ru/yii2mod.settings.php +++ b/messages/ru/yii2mod.settings.php @@ -23,6 +23,7 @@ 'Key' => 'Ключ', 'Value' => 'Значение', 'Status' => 'Статус', + 'Description' => 'Описание', 'Created date' => 'Дата создания', 'Updated date' => 'Дата обновления', 'Settings' => 'Настройки', diff --git a/messages/uk/yii2mod.settings.php b/messages/uk/yii2mod.settings.php index 840cbdc..7b3bb3e 100644 --- a/messages/uk/yii2mod.settings.php +++ b/messages/uk/yii2mod.settings.php @@ -23,6 +23,7 @@ 'Key' => 'Ключ', 'Value' => 'Значення', 'Status' => 'Статус', + 'Description' => 'Опис', 'Created date' => 'Дата створення', 'Updated date' => 'Дата поновлення', 'Settings' => 'Налаштування', diff --git a/migrations/m170323_102933_add_description_column_to_setting_table.php b/migrations/m170323_102933_add_description_column_to_setting_table.php new file mode 100644 index 0000000..a8701f0 --- /dev/null +++ b/migrations/m170323_102933_add_description_column_to_setting_table.php @@ -0,0 +1,25 @@ +addColumn('{{%setting}}', 'description', $this->string()->after('status')); + } + + /** + * @inheritdoc + */ + public function down() + { + $this->dropColumn('{{%setting}}', 'description'); + } +} diff --git a/models/SettingModel.php b/models/SettingModel.php index fd977ab..ac37972 100644 --- a/models/SettingModel.php +++ b/models/SettingModel.php @@ -18,6 +18,7 @@ * @property string $key * @property string $value * @property bool $status + * @property string $description * @property string $createdAt * @property string $updatedAt */ @@ -40,10 +41,10 @@ public function rules() [['section', 'key', 'value'], 'required'], [['section', 'key'], 'unique', 'targetAttribute' => ['section', 'key']], [['value', 'type'], 'string'], - [['section', 'key'], 'string', 'max' => 255], + [['section', 'key', 'description'], 'string', 'max' => 255], [['status'], 'integer'], ['status', 'default', 'value' => SettingStatus::ACTIVE], - ['status', 'in', 'range' => [SettingStatus::ACTIVE, SettingStatus::INACTIVE]], + ['status', 'in', 'range' => SettingStatus::getConstantsByName()], [['type'], 'safe'], ]; } @@ -60,6 +61,7 @@ public function attributeLabels() 'key' => Yii::t('yii2mod.settings', 'Key'), 'value' => Yii::t('yii2mod.settings', 'Value'), 'status' => Yii::t('yii2mod.settings', 'Status'), + 'description' => Yii::t('yii2mod.settings', 'Description'), 'createdAt' => Yii::t('yii2mod.settings', 'Created date'), 'updatedAt' => Yii::t('yii2mod.settings', 'Updated date'), ]; diff --git a/models/search/SettingSearch.php b/models/search/SettingSearch.php index 0a683f6..19b24c4 100644 --- a/models/search/SettingSearch.php +++ b/models/search/SettingSearch.php @@ -23,7 +23,7 @@ class SettingSearch extends SettingModel public function rules() { return [ - [['type', 'section', 'key', 'value', 'status'], 'safe'], + [['type', 'section', 'key', 'value', 'status', 'description'], 'safe'], ]; } @@ -45,15 +45,21 @@ public function search($params) ], ]); - if (!($this->load($params) && $this->validate())) { + $this->load($params); + + if (!$this->validate()) { return $dataProvider; } - $query->andFilterWhere(['status' => $this->status]); - $query->andFilterWhere(['section' => $this->section]); - $query->andFilterWhere(['type' => $this->type]); - $query->andFilterWhere(['like', 'key', $this->key]); - $query->andFilterWhere(['like', 'value', $this->value]); + $query->andFilterWhere([ + 'status' => $this->status, + 'section' => $this->section, + 'type' => $this->type, + ]); + + $query->andFilterWhere(['like', 'key', $this->key]) + ->andFilterWhere(['like', 'value', $this->value]) + ->andFilterWhere(['like', 'description', $this->description]); return $dataProvider; } diff --git a/tests/TestCase.php b/tests/TestCase.php index 9023db7..0802f7a 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -106,6 +106,7 @@ protected function setupTestDbData() 'key' => 'string not null', 'value' => 'text not null', 'status' => 'smallint not null default 1', + 'description' => 'string', 'createdAt' => 'integer not null', 'updatedAt' => 'integer not null', ])->execute(); diff --git a/views/default/_form.php b/views/default/_form.php index 25db68d..ac3a21f 100644 --- a/views/default/_form.php +++ b/views/default/_form.php @@ -13,9 +13,10 @@ - field($model, 'section')->textInput(['maxlength' => 255]) ?> - field($model, 'key')->textInput(['maxlength' => 255]) ?> - field($model, 'value')->textarea(['rows' => 10]) ?> + field($model, 'section')->textInput(['maxlength' => 255]); ?> + field($model, 'key')->textInput(['maxlength' => 255]); ?> + field($model, 'value')->textarea(['rows' => 5]); ?> + field($model, 'description')->textarea(['rows' => 5]); ?> field($model, 'status')->dropDownList(SettingStatus::listData()); ?> field($model, 'type')->dropDownList(SettingType::listData()); ?> diff --git a/views/default/create.php b/views/default/create.php index b1622f8..54bb95c 100644 --- a/views/default/create.php +++ b/views/default/create.php @@ -11,7 +11,7 @@ ?>
-

title) ?>

+

title); ?>

render('_form', [ 'model' => $model, diff --git a/views/default/index.php b/views/default/index.php index 14e445a..7bd91de 100644 --- a/views/default/index.php +++ b/views/default/index.php @@ -56,6 +56,7 @@ 'filter' => SettingStatus::listData(), 'filterInputOptions' => ['prompt' => Yii::t('yii2mod.settings', 'Select Status'), 'class' => 'form-control'], ], + 'description:ntext', [ 'header' => Yii::t('yii2mod.settings', 'Actions'), 'class' => 'yii\grid\ActionColumn', diff --git a/views/default/update.php b/views/default/update.php index 64acb29..286f36b 100644 --- a/views/default/update.php +++ b/views/default/update.php @@ -11,7 +11,7 @@ ?>
-

title) ?>

+

title); ?>

render('_form', [ 'model' => $model, From 6285ea87351fa85a0e02df267b0c53c933cbf647 Mon Sep 17 00:00:00 2001 From: Igor Chepurnoy Date: Thu, 23 Mar 2017 12:50:19 +0200 Subject: [PATCH 2/2] update TestCase class --- tests/TestCase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/TestCase.php b/tests/TestCase.php index 0802f7a..c2d9275 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -9,7 +9,7 @@ /** * This is the base class for all yii framework unit tests. */ -class TestCase extends \PHPUnit_Framework_TestCase +class TestCase extends \PHPUnit\Framework\TestCase { protected function setUp() {