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); }
public function actionCronUnread() { $html = ''; $count = 0; $post = Yii::$app->request->post(); // permission $role = new Role(); $condition = []; if (!$role->isAdministrator) { $position = $role->getPosition(); $stationIds = Station::getByRole($position, Yii::$app->user->id); $condition[] = ['in', 'station_id', $stationIds]; } $condition[] = ['=', 'read', Warning::STATUS_UNREAD]; $warnings = Warning::getWarning('warning_time DESC', 0, $condition); if (!empty($warnings)) { $count = count($warnings); $html = Show::warningsTable($warnings); } $data['html'] = $html; $data['count'] = $count; print json_encode($data); }