Example #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = DataList::find();
     // add conditions that should always apply here
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     /**
      * Настройка параметров сортировки
      * Важно: должна быть выполнена раньше $this->load($params)
      * statement below
      */
     $dataProvider->setSort(['attributes' => ['id', 'id_device', 'deviceName' => ['asc' => ['device.name_device' => SORT_ASC], 'desc' => ['device.name_device' => SORT_DESC], 'label' => 'Прибор'], 'dataRef' => ['asc' => ['data_ref.name_ref' => SORT_ASC], 'desc' => ['data_ref.name_ref' => SORT_DESC]], 'number', 'time_point', 'work_data', 'typeDataRef' => ['asc' => ['data_ref.type_data_ref' => SORT_ASC], 'desc' => ['data_ref.type_data_ref' => SORT_DESC]]]]);
     if (!($this->load($params) && $this->validate())) {
         /**
          * Жадная загрузка данных типа приборов
          * для работы сортировки.
          */
         $query->joinWith(['idDevice']);
         $query->joinWith(['idDataRef']);
         return $dataProvider;
     }
     // grid filtering conditions
     $query->andFilterWhere(['data_list.id' => $this->id, 'id_device' => $this->id_device, 'id_data_ref' => $this->id_data_ref, 'number' => $this->number, 'time_point' => $this->time_point, 'work_data' => $this->work_data]);
     // Фильтр по типу прибора
     $query->joinWith(['idDevice' => function ($q) {
         $q->andFilterWhere(['like', 'device.name_device', $this->deviceName]);
     }]);
     // Фильтр по типу данных
     $query->joinWith(['idDataRef' => function ($q) {
         $q->andFilterWhere(['like', 'data_ref.name_ref', $this->dataRef]);
         $q->andFilterWhere(['like', 'data_ref.type_data_ref', $this->typeDataRef]);
     }]);
     return $dataProvider;
 }
Example #2
0
 public function actionIn()
 {
     if (User::hasRole('admin')) {
         $model = new Device();
         //$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
         //\Yii::trace('### ### ### Тест лога');
         //\Yii::trace(Yii::$app->request->post());
         if ($model->load(Yii::$app->request->post())) {
             //\Yii::trace('### ### ### If');
             //return $this->redirect(['/table/device/view', 'id' => $model->id]);
             $searchModel = new DataListSearch();
             $dataProvider = $searchModel->search(['DataListSearch' => ['id_device' => $model->id, 'typeDataRef' => 'b']]);
             //Получаем массив данных из таблицы
             $allq = DataList::find()->select(['data_list.id', 'number', 'time_point'])->joinWith('idDataRef')->where(['id_device' => $model->id, 'type_data_ref' => 'b'])->createCommand()->queryAll();
             return $this->render('in', ['model' => $model, 'r' => 1, 'dataProvider' => $dataProvider, 'qwery' => $allq]);
         } else {
             //\Yii::trace('### ### ### Else');
             return $this->render('in', ['model' => $model, 'r' => NULL]);
         }
     } else {
         throw new NotFoundHttpException('Страница не найдена.');
     }
 }
Example #3
0
File: DataRef.php Project: robky/tb
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getDataLists()
 {
     return $this->hasMany(DataList::className(), ['id_data_ref' => 'id']);
 }
Example #4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getIdDataList()
 {
     return $this->hasOne(DataList::className(), ['id' => 'id_data_list']);
 }
Example #5
0
 /**
  * Finds the DataList model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return DataList the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = DataList::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Example #6
0
File: Start.php Project: robky/tb
 private function MovePoint($id, $new_time)
 {
     try {
         $modelsave = DataList::find()->where(['id' => $id])->one();
         if ($modelsave->time_point != $new_time) {
             //Текущее значение не равно новому
             $old_time = $modelsave->time_point;
             //Посчитаем сколько получасовок должно быть
             $per = date_diff(new DateTime($new_time), new DateTime($old_time));
             $out = floor($per->h * 2 + $per->format('%a') * 24 * 2 + $per->i / 30);
             //Посчитаем сколько значений в базе в этот периуд
             $count = BlockInterval::find()->where(['id_data_list' => '6'])->andFilterCompare('time_interval', ">{$old_time}")->andFilterCompare('time_interval', "<={$new_time}")->count();
             if ($out != $count) {
                 //Если не равно, значит есть дырка, ей нужно проставить статус
                 for ($i = 1; $i <= $out; $i++) {
                     try {
                         $times = date('Y-m-d H:i:s', strtotime($old_time) + 1800 * $i);
                         if (!($model = BlockInterval::find()->where(['id_data_list' => $id, 'time_interval' => $times])->one())) {
                             $model = new BlockInterval();
                             $model->id_data_list = $id;
                             $model->time_interval = $times;
                             $model->value = '0';
                             $model->status = '-1';
                             if (!$model->save()) {
                                 echo "Of move point something went wrong at " . strval($times) . " element\n";
                                 $ok = FALSE;
                                 break;
                             }
                         }
                     } catch (\Exception $e) {
                         echo "Of move point something went wrong at " . strval($i) . " element\n";
                         throw $e;
                         return FALSE;
                     }
                 }
             }
             $modelsave->time_point = $new_time;
             if (!$modelsave->save()) {
                 echo "Something went wrong move time point:" . $new_time . ".\n";
                 return FALSE;
             }
             echo "...Time point for " . $id . " move in last value: " . $new_time . "\n";
         }
     } catch (\Exception $e) {
         echo "Error! Something went wrong after save\n";
         throw $e;
     }
 }