Skip to content
This repository has been archived by the owner on Jun 21, 2019. It is now read-only.

Commit

Permalink
Close #45
Browse files Browse the repository at this point in the history
  • Loading branch information
CyanoFresh committed Mar 12, 2017
1 parent eb1d4b6 commit c405503
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 68 deletions.
2 changes: 1 addition & 1 deletion controllers/PanelController.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function actionIndex()
. '";
', View::POS_HEAD);

$roomModels = Room::find()->all();
$roomModels = Room::find()->orderBy('sort_order')->all();

return $this->render('index', [
'roomModels' => $roomModels,
Expand Down
18 changes: 18 additions & 0 deletions migrations/m170312_221606_add_room_order_to_room.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

use yii\db\Migration;

class m170312_221606_add_room_order_to_room extends Migration
{
public function safeUp()
{
$this->addColumn('room', 'sort_order', $this->integer()->defaultValue(0));
$this->dropColumn('room', 'bg');
}

public function safeDown()
{
$this->dropColumn('room', 'sort_order');
$this->addColumn('room', 'bg', $this->string());
}
}
28 changes: 7 additions & 21 deletions models/Room.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@
namespace app\models;

use Yii;
use yii\db\ActiveRecord;
use yii\helpers\ArrayHelper;

/**
* This is the model class for table "room".
*
* @property integer $id
* @property string $name
* @property string $bg
* @property integer $sort_order
*
* @property Item[] $items
*/
class Room extends \yii\db\ActiveRecord
class Room extends ActiveRecord
{
/**
* @inheritdoc
Expand All @@ -31,7 +32,9 @@ public function rules()
{
return [
[['name'], 'required'],
[['name', 'bg'], 'string', 'max' => 255],
[['name'], 'string', 'max' => 255],
[['sort_order'], 'integer'],
[['sort_order'], 'default', 'value' => 0],
];
}

Expand All @@ -43,18 +46,10 @@ public function attributeLabels()
return [
'id' => Yii::t('app', 'ID'),
'name' => Yii::t('app', 'Название'),
'bg' => Yii::t('app', 'Фон'),
'sort_order' => Yii::t('app', 'Порядок сортировки'),
];
}

/**
* @return \yii\db\ActiveQuery
*/
public function getItems()
{
return $this->hasMany(Item::className(), ['room_id' => 'id'])->inverseOf('room');
}

/**
* @return \yii\db\ActiveQuery|ItemWidgetQuery
*/
Expand All @@ -63,15 +58,6 @@ public function getItemWidgets()
return $this->hasMany(ItemWidget::className(), ['room_id' => 'id'])->inverseOf('room');
}

/**
* @inheritdoc
* @return RoomQuery the active query used by this AR class.
*/
public static function find()
{
return new RoomQuery(get_called_class());
}

/**
* @return array
*/
Expand Down
34 changes: 0 additions & 34 deletions models/RoomQuery.php

This file was deleted.

8 changes: 4 additions & 4 deletions models/RoomSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class RoomSearch extends Room
public function rules()
{
return [
[['id'], 'integer'],
[['name', 'bg'], 'safe'],
[['id', 'sort_order'], 'integer'],
[['name'], 'safe'],
];
}

Expand Down Expand Up @@ -60,10 +60,10 @@ public function search($params)
// grid filtering conditions
$query->andFilterWhere([
'id' => $this->id,
'sort_order' => $this->sort_order,
]);

$query->andFilterWhere(['like', 'name', $this->name])
->andFilterWhere(['like', 'bg', $this->bg]);
$query->andFilterWhere(['like', 'name', $this->name]);

return $dataProvider;
}
Expand Down
7 changes: 1 addition & 6 deletions modules/admin/views/room/_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@

<?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>

<?= $form->field($model, 'bg')->dropDownList([
'success' => 'Зеленый',
'danger' => 'Красный',
'warning' => 'Оранжевый',
'info' => 'Синий',
]) ?>
<?= $form->field($model, 'sort_order')->input('number') ?>

<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? 'Добавить' : 'Сохранить', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
Expand Down
2 changes: 1 addition & 1 deletion modules/admin/views/room/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
'columns' => [
'id',
'name',
'bg',
'sort_order',

['class' => 'app\components\ActionButtonColumn'],
],
Expand Down
2 changes: 1 addition & 1 deletion modules/admin/views/room/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
'attributes' => [
'id',
'name',
'bg',
'sort_order',
],
]) ?>

Expand Down

0 comments on commit c405503

Please sign in to comment.