コード例 #1
0
ファイル: SiteController.php プロジェクト: gpis88ce/Gpis88ce
 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
ファイル: WarningSearch.php プロジェクト: gpis88ce/Gpis88ce
 /**
  * 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
ファイル: Station.php プロジェクト: gpis88ce/Gpis88ce
 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
ファイル: Observer.php プロジェクト: gpis88ce/Gpis88ce
 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']);
 }