Пример #1
0
 public function actionIndex()
 {
     $role = new Role();
     $position = $role->getPosition();
     if (Yii::$app->user->isGuest) {
         $this->doLogin();
     }
     // search model
     $searchModel = new StationSearch();
     $parseData['searchModel'] = $searchModel;
     // get latest warning
     if ($position != Role::POSITION_ADMINISTRATOR) {
         $stationIds = Station::getByRole($position, Yii::$app->user->id);
         $condition = ['in', 'station_id', $stationIds];
         $parseData['warnings'] = Warning::getWarning('warning_time DESC', 100, [$condition]);
     } else {
         $parseData['warnings'] = Warning::getWarning('warning_time DESC', 100, []);
     }
     // get stations
     if ($position != Role::POSITION_ADMINISTRATOR) {
         $sCondition = ['in', 'id', $stationIds];
     } else {
         $sCondition = [];
     }
     // data provider
     $data = $searchModel->search(Yii::$app->request->queryParams, $sCondition);
     $parseData['stationProvider'] = $data['provider'];
     // write station locator for map
     $this->_writeStationLocator($data['query']);
     return $this->render('index', $parseData);
 }
Пример #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Warning::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'warning_type' => $this->warning_type, 'station_id' => $this->station_id, 'warning_time' => $this->warning_time, 'read' => $this->read]);
     $query->andFilterWhere(['like', 'message', $this->message]);
     return $dataProvider;
 }
Пример #3
0
 public function hasUnreadWarning($id)
 {
     if ($id > 0) {
         $newest = Warning::find()->where(['station_id' => $id, 'read' => Warning::STATUS_UNREAD])->one();
         if ($newest) {
             return $newest;
         }
     }
     return false;
 }
Пример #4
0
 public function insertWarning($message = null)
 {
     $warning = new Warning();
     $warning->station_id = $this->request['id'];
     if ($message) {
         $warning->message = $message;
     } else {
         $warning->message = $this->request['message'];
     }
     $warning->warning_time = time();
     if ($warning->validate()) {
         $warning->save();
     } else {
         var_dump($warning->getErrors());
         die;
     }
     return Yii::$app->db->lastInsertID;
 }
Пример #5
0
 protected function findModel($id)
 {
     if (($model = Warning::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Пример #6
0
 public function actionDelete($id)
 {
     $id = Yii::$app->request->get('id');
     if ($id > 0) {
         // delete equipment status
         DcEquipmentStatus::deleteAll(['station_id' => $id]);
         // delete sensor status
         SensorStatus::deleteAll(['station_id' => $id]);
         // delete dc equipment status
         DcEquipmentStatus::deleteAll(['station_id' => $id]);
         // delete power status
         PowerStatus::deleteAll(['station_id' => $id]);
         // delete station status
         StationStatus::deleteAll(['station_id' => $id]);
         // delete station status controller
         StationStatusHandler::deleteAll(['station_id' => $id]);
         // delete warning
         $warnings = Warning::findAll(['station_id' => $id]);
         if (!empty($warnings)) {
             foreach ($warnings as $w) {
                 Yii::$app->db->createCommand()->delete('warning_picture', ['warning_id' => $w['id']])->execute();
             }
         }
         Warning::deleteAll(['station_id' => $id]);
         // delete station
         Station::deleteAll(['id' => $id]);
         //write log action
         Log::logControl(Yii::$app->user->id, Log::ACTION_DELETE_STATION, $id);
     }
     return $this->redirect(['index']);
 }