Skip to content

Commit 0bdf4cb

Browse files
author
Igor Chepurnoy
authored
Merge pull request #9 from yii2mod/add_description_column
add description column to SettingModel
2 parents b79846d + 6285ea8 commit 0bdf4cb

13 files changed

+55
-16
lines changed

.travis.yml

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
language: php
22

33
php:
4-
- 5.6
54
- 7.1
65

76
# faster builds on new travis setup not using sudo

messages/de/yii2mod.settings.php

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
'Key' => 'Schlüssel',
2424
'Value' => 'Wert',
2525
'Status' => 'Status',
26+
'Description' => 'Beschreibung',
2627
'Created date' => 'Erstellungsdatum',
2728
'Updated date' => 'Änderungsdatum',
2829
'Settings' => 'Einstellungen',

messages/en/yii2mod.settings.php

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
'Key' => 'Key',
2424
'Value' => 'Value',
2525
'Status' => 'Status',
26+
'Description' => 'Description',
2627
'Created date' => 'Created date',
2728
'Updated date' => 'Updated date',
2829
'Settings' => 'Settings',

messages/ru/yii2mod.settings.php

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
'Key' => 'Ключ',
2424
'Value' => 'Значение',
2525
'Status' => 'Статус',
26+
'Description' => 'Описание',
2627
'Created date' => 'Дата создания',
2728
'Updated date' => 'Дата обновления',
2829
'Settings' => 'Настройки',

messages/uk/yii2mod.settings.php

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
'Key' => 'Ключ',
2424
'Value' => 'Значення',
2525
'Status' => 'Статус',
26+
'Description' => 'Опис',
2627
'Created date' => 'Дата створення',
2728
'Updated date' => 'Дата поновлення',
2829
'Settings' => 'Налаштування',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
use yii\db\Migration;
4+
5+
/**
6+
* Handles adding description to table `setting`.
7+
*/
8+
class m170323_102933_add_description_column_to_setting_table extends Migration
9+
{
10+
/**
11+
* @inheritdoc
12+
*/
13+
public function up()
14+
{
15+
$this->addColumn('{{%setting}}', 'description', $this->string()->after('status'));
16+
}
17+
18+
/**
19+
* @inheritdoc
20+
*/
21+
public function down()
22+
{
23+
$this->dropColumn('{{%setting}}', 'description');
24+
}
25+
}

models/SettingModel.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* @property string $key
1919
* @property string $value
2020
* @property bool $status
21+
* @property string $description
2122
* @property string $createdAt
2223
* @property string $updatedAt
2324
*/
@@ -40,10 +41,10 @@ public function rules()
4041
[['section', 'key', 'value'], 'required'],
4142
[['section', 'key'], 'unique', 'targetAttribute' => ['section', 'key']],
4243
[['value', 'type'], 'string'],
43-
[['section', 'key'], 'string', 'max' => 255],
44+
[['section', 'key', 'description'], 'string', 'max' => 255],
4445
[['status'], 'integer'],
4546
['status', 'default', 'value' => SettingStatus::ACTIVE],
46-
['status', 'in', 'range' => [SettingStatus::ACTIVE, SettingStatus::INACTIVE]],
47+
['status', 'in', 'range' => SettingStatus::getConstantsByName()],
4748
[['type'], 'safe'],
4849
];
4950
}
@@ -60,6 +61,7 @@ public function attributeLabels()
6061
'key' => Yii::t('yii2mod.settings', 'Key'),
6162
'value' => Yii::t('yii2mod.settings', 'Value'),
6263
'status' => Yii::t('yii2mod.settings', 'Status'),
64+
'description' => Yii::t('yii2mod.settings', 'Description'),
6365
'createdAt' => Yii::t('yii2mod.settings', 'Created date'),
6466
'updatedAt' => Yii::t('yii2mod.settings', 'Updated date'),
6567
];

models/search/SettingSearch.php

+13-7
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class SettingSearch extends SettingModel
2323
public function rules()
2424
{
2525
return [
26-
[['type', 'section', 'key', 'value', 'status'], 'safe'],
26+
[['type', 'section', 'key', 'value', 'status', 'description'], 'safe'],
2727
];
2828
}
2929

@@ -45,15 +45,21 @@ public function search($params)
4545
],
4646
]);
4747

48-
if (!($this->load($params) && $this->validate())) {
48+
$this->load($params);
49+
50+
if (!$this->validate()) {
4951
return $dataProvider;
5052
}
5153

52-
$query->andFilterWhere(['status' => $this->status]);
53-
$query->andFilterWhere(['section' => $this->section]);
54-
$query->andFilterWhere(['type' => $this->type]);
55-
$query->andFilterWhere(['like', 'key', $this->key]);
56-
$query->andFilterWhere(['like', 'value', $this->value]);
54+
$query->andFilterWhere([
55+
'status' => $this->status,
56+
'section' => $this->section,
57+
'type' => $this->type,
58+
]);
59+
60+
$query->andFilterWhere(['like', 'key', $this->key])
61+
->andFilterWhere(['like', 'value', $this->value])
62+
->andFilterWhere(['like', 'description', $this->description]);
5763

5864
return $dataProvider;
5965
}

tests/TestCase.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/**
1010
* This is the base class for all yii framework unit tests.
1111
*/
12-
class TestCase extends \PHPUnit_Framework_TestCase
12+
class TestCase extends \PHPUnit\Framework\TestCase
1313
{
1414
protected function setUp()
1515
{
@@ -106,6 +106,7 @@ protected function setupTestDbData()
106106
'key' => 'string not null',
107107
'value' => 'text not null',
108108
'status' => 'smallint not null default 1',
109+
'description' => 'string',
109110
'createdAt' => 'integer not null',
110111
'updatedAt' => 'integer not null',
111112
])->execute();

views/default/_form.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313

1414
<?php $form = ActiveForm::begin(); ?>
1515

16-
<?php echo $form->field($model, 'section')->textInput(['maxlength' => 255]) ?>
17-
<?php echo $form->field($model, 'key')->textInput(['maxlength' => 255]) ?>
18-
<?php echo $form->field($model, 'value')->textarea(['rows' => 10]) ?>
16+
<?php echo $form->field($model, 'section')->textInput(['maxlength' => 255]); ?>
17+
<?php echo $form->field($model, 'key')->textInput(['maxlength' => 255]); ?>
18+
<?php echo $form->field($model, 'value')->textarea(['rows' => 5]); ?>
19+
<?php echo $form->field($model, 'description')->textarea(['rows' => 5]); ?>
1920
<?php echo $form->field($model, 'status')->dropDownList(SettingStatus::listData()); ?>
2021
<?php echo $form->field($model, 'type')->dropDownList(SettingType::listData()); ?>
2122

views/default/create.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
?>
1212
<div class="setting-create">
1313

14-
<h1><?php echo Html::encode($this->title) ?></h1>
14+
<h1><?php echo Html::encode($this->title); ?></h1>
1515

1616
<?php echo $this->render('_form', [
1717
'model' => $model,

views/default/index.php

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
'filter' => SettingStatus::listData(),
5757
'filterInputOptions' => ['prompt' => Yii::t('yii2mod.settings', 'Select Status'), 'class' => 'form-control'],
5858
],
59+
'description:ntext',
5960
[
6061
'header' => Yii::t('yii2mod.settings', 'Actions'),
6162
'class' => 'yii\grid\ActionColumn',

views/default/update.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
?>
1212
<div class="setting-update">
1313

14-
<h3><?php echo Html::encode($this->title) ?></h3>
14+
<h3><?php echo Html::encode($this->title); ?></h3>
1515

1616
<?php echo $this->render('_form', [
1717
'model' => $model,

0 commit comments

Comments
 (0)