diff --git a/controllers/PanelController.php b/controllers/PanelController.php index e511309..93def03 100644 --- a/controllers/PanelController.php +++ b/controllers/PanelController.php @@ -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, diff --git a/migrations/m170312_221606_add_room_order_to_room.php b/migrations/m170312_221606_add_room_order_to_room.php new file mode 100644 index 0000000..76b1cf5 --- /dev/null +++ b/migrations/m170312_221606_add_room_order_to_room.php @@ -0,0 +1,18 @@ +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()); + } +} diff --git a/models/Room.php b/models/Room.php index d501df8..d03e436 100644 --- a/models/Room.php +++ b/models/Room.php @@ -3,6 +3,7 @@ namespace app\models; use Yii; +use yii\db\ActiveRecord; use yii\helpers\ArrayHelper; /** @@ -10,11 +11,11 @@ * * @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 @@ -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], ]; } @@ -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 */ @@ -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 */ diff --git a/models/RoomQuery.php b/models/RoomQuery.php deleted file mode 100644 index 5a7bd87..0000000 --- a/models/RoomQuery.php +++ /dev/null @@ -1,34 +0,0 @@ -andWhere('[[status]]=1'); - }*/ - - /** - * @inheritdoc - * @return Room[]|array - */ - public function all($db = null) - { - return parent::all($db); - } - - /** - * @inheritdoc - * @return Room|array|null - */ - public function one($db = null) - { - return parent::one($db); - } -} diff --git a/models/RoomSearch.php b/models/RoomSearch.php index f002262..084b3ca 100644 --- a/models/RoomSearch.php +++ b/models/RoomSearch.php @@ -18,8 +18,8 @@ class RoomSearch extends Room public function rules() { return [ - [['id'], 'integer'], - [['name', 'bg'], 'safe'], + [['id', 'sort_order'], 'integer'], + [['name'], 'safe'], ]; } @@ -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; } diff --git a/modules/admin/views/room/_form.php b/modules/admin/views/room/_form.php index 607e9ee..ceadac7 100644 --- a/modules/admin/views/room/_form.php +++ b/modules/admin/views/room/_form.php @@ -14,12 +14,7 @@ field($model, 'name')->textInput(['maxlength' => true]) ?> - field($model, 'bg')->dropDownList([ - 'success' => 'Зеленый', - 'danger' => 'Красный', - 'warning' => 'Оранжевый', - 'info' => 'Синий', - ]) ?> + field($model, 'sort_order')->input('number') ?>
isNewRecord ? 'Добавить' : 'Сохранить', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> diff --git a/modules/admin/views/room/index.php b/modules/admin/views/room/index.php index 05828e9..e947174 100644 --- a/modules/admin/views/room/index.php +++ b/modules/admin/views/room/index.php @@ -25,7 +25,7 @@ 'columns' => [ 'id', 'name', - 'bg', + 'sort_order', ['class' => 'app\components\ActionButtonColumn'], ], diff --git a/modules/admin/views/room/view.php b/modules/admin/views/room/view.php index 9a6a0a1..2ea9600 100644 --- a/modules/admin/views/room/view.php +++ b/modules/admin/views/room/view.php @@ -28,7 +28,7 @@ 'attributes' => [ 'id', 'name', - 'bg', + 'sort_order', ], ]) ?>