Skip to content

Commit

Permalink
Merge pull request #9 from yii2mod/add_description_column
Browse files Browse the repository at this point in the history
add description column to SettingModel
  • Loading branch information
Igor Chepurnoy authored Mar 23, 2017
2 parents b79846d + 6285ea8 commit 0bdf4cb
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 16 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: php

php:
- 5.6
- 7.1

# faster builds on new travis setup not using sudo
Expand Down
1 change: 1 addition & 0 deletions messages/de/yii2mod.settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
'Key' => 'Schlüssel',
'Value' => 'Wert',
'Status' => 'Status',
'Description' => 'Beschreibung',
'Created date' => 'Erstellungsdatum',
'Updated date' => 'Änderungsdatum',
'Settings' => 'Einstellungen',
Expand Down
1 change: 1 addition & 0 deletions messages/en/yii2mod.settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
'Key' => 'Key',
'Value' => 'Value',
'Status' => 'Status',
'Description' => 'Description',
'Created date' => 'Created date',
'Updated date' => 'Updated date',
'Settings' => 'Settings',
Expand Down
1 change: 1 addition & 0 deletions messages/ru/yii2mod.settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
'Key' => 'Ключ',
'Value' => 'Значение',
'Status' => 'Статус',
'Description' => 'Описание',
'Created date' => 'Дата создания',
'Updated date' => 'Дата обновления',
'Settings' => 'Настройки',
Expand Down
1 change: 1 addition & 0 deletions messages/uk/yii2mod.settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
'Key' => 'Ключ',
'Value' => 'Значення',
'Status' => 'Статус',
'Description' => 'Опис',
'Created date' => 'Дата створення',
'Updated date' => 'Дата поновлення',
'Settings' => 'Налаштування',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

use yii\db\Migration;

/**
* Handles adding description to table `setting`.
*/
class m170323_102933_add_description_column_to_setting_table extends Migration
{
/**
* @inheritdoc
*/
public function up()
{
$this->addColumn('{{%setting}}', 'description', $this->string()->after('status'));
}

/**
* @inheritdoc
*/
public function down()
{
$this->dropColumn('{{%setting}}', 'description');
}
}
6 changes: 4 additions & 2 deletions models/SettingModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* @property string $key
* @property string $value
* @property bool $status
* @property string $description
* @property string $createdAt
* @property string $updatedAt
*/
Expand All @@ -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'],
];
}
Expand All @@ -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'),
];
Expand Down
20 changes: 13 additions & 7 deletions models/search/SettingSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
];
}

Expand All @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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();
Expand Down
7 changes: 4 additions & 3 deletions views/default/_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@

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

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

Expand Down
2 changes: 1 addition & 1 deletion views/default/create.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
?>
<div class="setting-create">

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

<?php echo $this->render('_form', [
'model' => $model,
Expand Down
1 change: 1 addition & 0 deletions views/default/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion views/default/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
?>
<div class="setting-update">

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

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

0 comments on commit 0bdf4cb

Please sign in to comment.