diff --git a/migrations/m161126_184646_create_events.php b/migrations/m161126_184646_create_events.php new file mode 100644 index 0000000..5445f7a --- /dev/null +++ b/migrations/m161126_184646_create_events.php @@ -0,0 +1,32 @@ +db->driverName === 'mysql') { + $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB'; + } + + $this->createTable('event', [ + 'id' => $this->primaryKey(), + 'type' => $this->smallInteger()->notNull(), + 'trig_date' => $this->string(), + 'trig_time' => $this->string(), + 'trig_time_wdays' => $this->string(), + 'trig_item_id' => $this->integer(), + 'trig_item_value' => $this->string(), + 'task_id' => $this->integer(), + 'name' => $this->string()->notNull(), + ], $tableOptions); + } + + public function safeDown() + { + $this->dropTable('event'); + } +} diff --git a/migrations/m161126_185030_create_task.php b/migrations/m161126_185030_create_task.php new file mode 100644 index 0000000..9f240f6 --- /dev/null +++ b/migrations/m161126_185030_create_task.php @@ -0,0 +1,25 @@ +db->driverName === 'mysql') { + $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB'; + } + + $this->createTable('task', [ + 'id' => $this->primaryKey(), + 'name' => $this->string()->notNull(), + ], $tableOptions); + } + + public function safeDown() + { + $this->dropTable('task'); + } +} diff --git a/migrations/m161126_185035_create_action.php b/migrations/m161126_185035_create_action.php new file mode 100644 index 0000000..5649a1f --- /dev/null +++ b/migrations/m161126_185035_create_action.php @@ -0,0 +1,29 @@ +db->driverName === 'mysql') { + $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB'; + } + + $this->createTable('task_action', [ + 'id' => $this->primaryKey(), + 'type' => $this->smallInteger()->notNull(), + 'item_id' => $this->integer(), + 'item_value' => $this->string(), + 'task_id' => $this->integer(), + 'name' => $this->string()->notNull(), + ], $tableOptions); + } + + public function safeDown() + { + $this->dropTable('task_action'); + } +} diff --git a/models/Event.php b/models/Event.php new file mode 100644 index 0000000..8b6d490 --- /dev/null +++ b/models/Event.php @@ -0,0 +1,108 @@ + self::getStatusesArray()], + [['trig_date', 'trig_item_value', 'name', 'trig_time', 'trig_time_wdays'], 'string', 'max' => 255], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'id' => 'ID', + 'type' => 'Тип', + 'trig_date' => 'Дата срабатывания', + 'trig_time' => 'Время срабатывания', + 'trig_time_wdays' => 'Дни срабатывания', + 'trig_item_id' => 'Элемент срабатывания', + 'trig_item_value' => 'Значение элемента срабатывания', + 'task_id' => 'Задача', + 'name' => 'Имя', + ]; + } + + /** + * @return array + */ + public static function getStatuses() + { + return [ + self::TYPE_BY_ITEM_VALUE => 'Значение Элемента', + self::TYPE_BY_USER_ITEM_CHANGE => 'Изменение Значение Элемента', + self::TYPE_BY_DATE => 'Дата', + self::TYPE_BY_TIME => 'Время', + ]; + } + + /** + * @return array + */ + public static function getStatusesArray() + { + return [ + self::TYPE_BY_ITEM_VALUE, + self::TYPE_BY_USER_ITEM_CHANGE, + self::TYPE_BY_DATE, + self::TYPE_BY_TIME, + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getTask() + { + return $this->hasOne(Task::className(), ['id' => 'task_id'])->inverseOf('events'); + } + + public static function getList() + { + return ArrayHelper::map(self::find()->all(), 'id', 'name'); + } +} diff --git a/models/Item.php b/models/Item.php index 447303a..fd024d4 100644 --- a/models/Item.php +++ b/models/Item.php @@ -5,6 +5,7 @@ namespace app\models; use linslin\yii2\curl\Curl; use Yii; use yii\db\ActiveRecord; +use yii\helpers\ArrayHelper; /** * This is the model class for table "item". @@ -41,6 +42,9 @@ class Item extends ActiveRecord const VALUE_ON = 1; const VALUE_OFF = 0; + const MODE_RAINBOW = 'rainbow'; + const MODE_BREATH = 'breath'; + /** * Used for WS handler * @var mixed @@ -145,4 +149,9 @@ class Item extends ActiveRecord { return self::getTypesArray()[$this->type]; } + + public static function getList() + { + return ArrayHelper::map(self::find()->all(), 'id', 'name'); + } } diff --git a/models/Task.php b/models/Task.php new file mode 100644 index 0000000..17bbf41 --- /dev/null +++ b/models/Task.php @@ -0,0 +1,60 @@ + 255], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'id' => 'ID', + 'name' => 'Name', + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getTaskActions() + { + return $this->hasMany(TaskAction::className(), ['task_id' => 'id']); + } + + public static function getList() + { + return ArrayHelper::map(self::find()->all(), 'id', 'name'); + } +} diff --git a/models/TaskAction.php b/models/TaskAction.php new file mode 100644 index 0000000..66b9f01 --- /dev/null +++ b/models/TaskAction.php @@ -0,0 +1,72 @@ + 255], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'id' => 'ID', + 'type' => 'Тип', + 'item_id' => 'Элемент', + 'item_value' => 'Значение Элемента', + 'task_id' => 'Задача', + 'name' => 'Название', + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getItem() + { + return $this->hasOne(Item::className(), ['id' => 'item_id']); + } + + public static function getTypes() + { + return [ + self::TYPE_CHANGE_ITEM_VALUE => 'Изменить значение Элемента', + ]; + } +} diff --git a/modules/admin/controllers/EventController.php b/modules/admin/controllers/EventController.php new file mode 100644 index 0000000..aaa48b5 --- /dev/null +++ b/modules/admin/controllers/EventController.php @@ -0,0 +1,124 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + ]; + } + + /** + * Lists all Event models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new EventSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single Event model. + * @param integer $id + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new Event model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new Event(); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id]); + } else { + return $this->render('create', [ + 'model' => $model, + ]); + } + } + + /** + * Updates an existing Event model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param integer $id + * @return mixed + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id]); + } else { + return $this->render('update', [ + 'model' => $model, + ]); + } + } + + /** + * Deletes an existing Event model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param integer $id + * @return mixed + */ + public function actionDelete($id) + { + $this->findModel($id)->delete(); + + return $this->redirect(['index']); + } + + /** + * Finds the Event model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return Event the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = Event::findOne($id)) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } +} diff --git a/modules/admin/controllers/TaskActionController.php b/modules/admin/controllers/TaskActionController.php new file mode 100644 index 0000000..8265518 --- /dev/null +++ b/modules/admin/controllers/TaskActionController.php @@ -0,0 +1,124 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + ]; + } + + /** + * Lists all TaskAction models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new TaskActionSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single TaskAction model. + * @param integer $id + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new TaskAction model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new TaskAction(); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id]); + } else { + return $this->render('create', [ + 'model' => $model, + ]); + } + } + + /** + * Updates an existing TaskAction model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param integer $id + * @return mixed + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id]); + } else { + return $this->render('update', [ + 'model' => $model, + ]); + } + } + + /** + * Deletes an existing TaskAction model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param integer $id + * @return mixed + */ + public function actionDelete($id) + { + $this->findModel($id)->delete(); + + return $this->redirect(['index']); + } + + /** + * Finds the TaskAction model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return TaskAction the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = TaskAction::findOne($id)) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } +} diff --git a/modules/admin/controllers/TaskController.php b/modules/admin/controllers/TaskController.php new file mode 100644 index 0000000..700616e --- /dev/null +++ b/modules/admin/controllers/TaskController.php @@ -0,0 +1,124 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + ]; + } + + /** + * Lists all Task models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new TaskSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single Task model. + * @param integer $id + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new Task model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new Task(); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id]); + } else { + return $this->render('create', [ + 'model' => $model, + ]); + } + } + + /** + * Updates an existing Task model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param integer $id + * @return mixed + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id]); + } else { + return $this->render('update', [ + 'model' => $model, + ]); + } + } + + /** + * Deletes an existing Task model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param integer $id + * @return mixed + */ + public function actionDelete($id) + { + $this->findModel($id)->delete(); + + return $this->redirect(['index']); + } + + /** + * Finds the Task model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return Task the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = Task::findOne($id)) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } +} diff --git a/modules/admin/models/EventSearch.php b/modules/admin/models/EventSearch.php new file mode 100644 index 0000000..b530874 --- /dev/null +++ b/modules/admin/models/EventSearch.php @@ -0,0 +1,76 @@ + $query, + ]); + + $this->load($params); + + if (!$this->validate()) { + // uncomment the following line if you do not want to return any records when validation fails + // $query->where('0=1'); + return $dataProvider; + } + + // grid filtering conditions + $query->andFilterWhere([ + 'id' => $this->id, + 'type' => $this->type, + 'trig_item_id' => $this->trig_item_id, + 'task_id' => $this->task_id, + ]); + + $query->andFilterWhere(['like', 'trig_date', $this->trig_date]) + ->andFilterWhere(['like', 'trig_time', $this->trig_time]) + ->andFilterWhere(['like', 'trig_time_wdays', $this->trig_time_wdays]) + ->andFilterWhere(['like', 'trig_item_value', $this->trig_item_value]) + ->andFilterWhere(['like', 'name', $this->name]); + + return $dataProvider; + } +} diff --git a/modules/admin/models/TaskActionSearch.php b/modules/admin/models/TaskActionSearch.php new file mode 100644 index 0000000..6b1ee51 --- /dev/null +++ b/modules/admin/models/TaskActionSearch.php @@ -0,0 +1,72 @@ + $query, + ]); + + $this->load($params); + + if (!$this->validate()) { + // uncomment the following line if you do not want to return any records when validation fails + // $query->where('0=1'); + return $dataProvider; + } + + // grid filtering conditions + $query->andFilterWhere([ + 'id' => $this->id, + 'type' => $this->type, + 'item_id' => $this->item_id, + ]); + + $query->andFilterWhere(['like', 'item_value', $this->item_value]) + ->andFilterWhere(['like', 'name', $this->name]); + + return $dataProvider; + } +} diff --git a/modules/admin/models/TaskSearch.php b/modules/admin/models/TaskSearch.php new file mode 100644 index 0000000..f0b9967 --- /dev/null +++ b/modules/admin/models/TaskSearch.php @@ -0,0 +1,69 @@ + $query, + ]); + + $this->load($params); + + if (!$this->validate()) { + // uncomment the following line if you do not want to return any records when validation fails + // $query->where('0=1'); + return $dataProvider; + } + + // grid filtering conditions + $query->andFilterWhere([ + 'id' => $this->id, + ]); + + $query->andFilterWhere(['like', 'name', $this->name]); + + return $dataProvider; + } +} diff --git a/modules/admin/views/event/_form.php b/modules/admin/views/event/_form.php new file mode 100644 index 0000000..2b0367d --- /dev/null +++ b/modules/admin/views/event/_form.php @@ -0,0 +1,53 @@ + + +
+ = Html::a('Добавить', ['create'], ['class' => 'btn btn-success']) ?> +
+ render('_search', ['model' => $searchModel]); ?> + + + = GridView::widget([ + 'dataProvider' => $dataProvider, + 'summaryOptions' => ['class' => 'alert alert-info'], + 'layout' => '{summary}+ = Html::a('Редактировать', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?> + = Html::a('Удалить', ['delete', 'id' => $model->id], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => 'Are you sure you want to delete this item?', + 'method' => 'post', + ], + ]) ?> +
+ + = DetailView::widget([ + 'model' => $model, + 'attributes' => [ + 'id', + 'type', + 'trig_date', + 'trig_time', + 'trig_time_wdays', + 'trig_item_id', + 'trig_item_value', + 'task_id', + 'name', + ], + ]) ?> + ++ = Html::a('Добавить', ['create'], ['class' => 'btn btn-success']) ?> +
+ render('_search', ['model' => $searchModel]); ?> + + + = GridView::widget([ + 'dataProvider' => $dataProvider, + 'summaryOptions' => ['class' => 'alert alert-info'], + 'layout' => '{summary}+ = Html::a('Редактировать', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?> + = Html::a('Удалить', ['delete', 'id' => $model->id], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => 'Are you sure you want to delete this item?', + 'method' => 'post', + ], + ]) ?> +
+ + = DetailView::widget([ + 'model' => $model, + 'attributes' => [ + 'id', + 'type', + 'item_id', + 'item_value', + 'name', + ], + ]) ?> + ++ = Html::a('Добавить', ['create'], ['class' => 'btn btn-success']) ?> +
+ render('_search', ['model' => $searchModel]); ?> + + + = GridView::widget([ + 'dataProvider' => $dataProvider, + 'summaryOptions' => ['class' => 'alert alert-info'], + 'layout' => '{summary}+ = Html::a('Редактировать', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?> + = Html::a('Удалить', ['delete', 'id' => $model->id], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => 'Are you sure you want to delete this item?', + 'method' => 'post', + ], + ]) ?> +
+ + = DetailView::widget([ + 'model' => $model, + 'attributes' => [ + 'id', + 'name', + ], + ]) ?> + +