Esempio n. 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);
 }
Esempio n. 2
0
 public function beforeAction($action)
 {
     // check role
     if (!Yii::$app->user->isGuest) {
         $role = new Role();
         if (!$role->hasRole($action)) {
             $this->permissionDeny();
         }
     }
     return parent::beforeAction($action);
 }
Esempio n. 3
0
 /**
  * 角色列表
  */
 public function actionIndex()
 {
     $request = Yii::$app->request;
     $model = new $this->modelClass();
     //获取列表属性
     $listAttributes = method_exists($model, 'listAttributes') ? $model->listAttributes() : [];
     //获取属性名称
     $attributeLabels = method_exists($model, 'attributeLabels') ? $model->attributeLabels() : [];
     $models = Role::getTreeList();
     return $this->render('index', ['get' => $request->get(), 'model' => $model, 'models' => $models, 'listAttributes' => $listAttributes, 'attributeLabels' => $attributeLabels]);
 }
Esempio n. 4
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Role::find();
     $dataProvider = new ActiveDataProvider(['query' => $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;
     }
     $query->andFilterWhere(['id' => $this->id, 'is_membership_possible' => $this->is_membership_possible, 'price' => $this->price, 'duration' => $this->duration]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'description', $this->description]);
     return $dataProvider;
 }
Esempio n. 5
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Role::find();
     $dataProvider = new ActiveDataProvider(['query' => $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;
     }
     $query->andFilterWhere(['id' => $this->id, 'role_value' => $this->role_value]);
     $query->andFilterWhere(['like', 'role_name', $this->role_name]);
     return $dataProvider;
 }
Esempio n. 6
0
?>
</h3>
    
        <p class="action">
            <?php 
echo Html::a('添加管理员', ['create'], ['class' => 'btn btn-success']);
?>
        </p>
    </div>

    <?php 
Pjax::begin();
?>
    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'columns' => [['attribute' => 'id', 'options' => []], ['attribute' => 'username', 'label' => '管理员账号'], ['attribute' => 'role_id', 'label' => '角色', 'value' => function ($model) {
    return Role::findOne($model->role_id)->role_name;
}], ['attribute' => 'created_at', 'label' => '创建时间', 'value' => function ($model) {
    return date('Y-m-d H:i', $model->created_at);
}], ['header' => Html::a('状态', 'javascript:;'), 'content' => function ($model) {
    if ($model->status == 1) {
        return Html::img('@web/image/yes.gif', ['onclick' => "setStatus(this, {$model->id})", 'data-status' => 0]);
    } else {
        return Html::img('@web/image/no.gif', ['onclick' => "setStatus(this, {$model->id})", 'data-status' => 1]);
    }
}], ['class' => 'yii\\grid\\ActionColumn', 'header' => Html::a('操作', 'javascript:void(0);'), 'template' => '{update} {delete}']]]);
?>
    <?php 
Pjax::end();
?>

</div>
Esempio n. 7
0
 public function actionIndex()
 {
     // get station ids by role
     $permCondition = [];
     $role = new Role();
     if (!$role->isAdministrator) {
         $stationIds = Station::getByRole($role->getPosition(), Yii::$app->user->id);
         $permCondition['s.id'] = $stationIds;
     }
     // default time points
     $timePoints = Convert::currentTimePoints();
     // get post form data
     $get = Yii::$app->request->get('get_by');
     if ($get == 'today') {
         $timePoints = Convert::currentTimePoints();
     } else {
         if ($get == 'week') {
             $timePoints = Convert::currentWeekTimePoints();
         } else {
             if ($get == 'month') {
                 $timePoints = Convert::currentMonthTimePoints();
             }
         }
     }
     $andWhere = ['>=', 'w.warning_time', $timePoints['start']];
     $andWhere1 = ['<=', 'w.warning_time', $timePoints['end']];
     // get data
     $query = new Query();
     $warnings = $query->select('w.warning_time, s.area_id')->from('warning w')->innerJoin('station s', 'w.station_id = s.id')->where($permCondition)->andWhere($andWhere)->andWhere($andWhere1)->all();
     // data
     $parseData = [];
     $data = [];
     // get areas
     $areaQuery = new Query();
     $areas = $areaQuery->select('a.*')->from('area a')->innerJoin('station s', 's.area_id = a.id')->where($permCondition)->groupBy('a.id')->all();
     $parseData['areas'] = $areas;
     if (!empty($areas)) {
         foreach ($areas as $area) {
             $data[$area['id']]['number'] = 0;
             $data[$area['id']]['start'] = 0;
             $data[$area['id']]['end'] = 0;
             if (!empty($warnings)) {
                 $no = 1;
                 foreach ($warnings as $w) {
                     if ($w['area_id'] == $area['id']) {
                         $data[$area['id']]['number']++;
                         if ($no == 1) {
                             $data[$area['id']]['start'] = $w['warning_time'];
                             $data[$area['id']]['end'] = $w['warning_time'];
                         } else {
                             if ($w['warning_time'] < $data[$area['id']]['start']) {
                                 $data[$area['id']]['start'] = $w['warning_time'];
                             }
                             if ($w['warning_time'] > $data[$area['id']]['end']) {
                                 $data[$area['id']]['end'] = $w['warning_time'];
                             }
                         }
                         $no++;
                     }
                 }
             }
         }
     }
     $parseData['data'] = $data;
     return $this->render('warning', $parseData);
 }
Esempio n. 8
0
 /**
  * 生成二级菜单节点
  * @param $_child
  * @return array
  */
 private function items($_child)
 {
     $tree = [];
     if ($_child && is_array($_child)) {
         $Role = new Role();
         foreach ($_child as $val) {
             if (!$Role->isAccess($val['url'])) {
                 continue;
             }
             $tree[] = ['label' => $val->title, 'url' => [$val->url]];
         }
     }
     return $tree;
 }
Esempio n. 9
0
 /**
  * Finds the Role model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Role the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Role::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Esempio n. 10
0
 /**
  * @inheritdoc
  */
 public function controlAttributes()
 {
     return [['id' => 'basic', 'name' => '基本属性', 'attributes' => ['username' => ['type' => 'text'], 'password' => ['type' => 'password', 'hint' => '新增用户时必须填写密码,修改用户时如果为空则不修改,否则则修改密码。'], 'roles' => ['type' => 'dropDown', 'items' => [Role::className(), 'getTreeItems'], 'options' => ['class' => 'select_5', 'multiple' => true]], 'email' => ['type' => 'text'], 'status' => ['type' => 'radio', 'items' => [static::className(), 'getStatusItems']]]]];
 }
Esempio n. 11
0
 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);
 }
Esempio n. 12
0
 protected function findModel($id)
 {
     // session
     $role = new Role();
     if (!$role->isAdministrator) {
         $position = $role->getPosition();
         $stationIds = Station::getByRole($position, Yii::$app->user->id);
         if (!empty($stationIds) && !in_array($id, $stationIds)) {
             $this->permissionDeny();
         }
     }
     if (($model = Station::findOne($id)) !== null) {
         // find area & center
         $model->area = Area::findOne($model->area_id);
         $model->center = Center::findOne($model->center_id);
         // get equipment
         $equipments = EquipmentStatus::findAll(['station_id' => $id]);
         if (!empty($equipments)) {
             foreach ($equipments as $equipment) {
                 $model->equipment[] = $equipment->equipment_id;
             }
         }
         // get power equipment
         $powerEquipments = PowerStatus::findAll(['station_id' => $id]);
         if (!empty($powerEquipments)) {
             foreach ($powerEquipments as $equipment) {
                 $model->power_equipment[] = $equipment->item_id;
             }
         }
         // get dc
         $dcEquips = DcEquipmentStatus::findByStation($id);
         if (!empty($dcEquips)) {
             foreach ($dcEquips as $dcEquip) {
                 $model->dc_equip_ids[] = $dcEquip['equipment_id'];
                 $model->dc_equip_status[] = ['equipment_id' => $dcEquip['equipment_id'], 'name' => $dcEquip['name'], 'amperage' => $dcEquip['amperage'], 'voltage' => $dcEquip['voltage'], 'unit_voltage' => $dcEquip['unit_voltage'], 'temperature' => $dcEquip['temperature'], 'unit_amperage' => $dcEquip['unit_amperage'], 'status' => $dcEquip['status']];
             }
         }
         // get sensor status
         $query = new Query();
         $sensorStatus = $query->select('sst.*, s.type, s.unit_type, s.name')->from('sensor_status sst')->leftJoin('sensor s', 's.id = sst.sensor_id')->where(['sst.station_id' => $id])->andWhere(['s.active' => Sensor::STATUS_ACTIVE])->all();
         if (!empty($sensorStatus)) {
             foreach ($sensorStatus as $sst) {
                 $model->sensor_status[] = ['type' => $sst['type'], 'sensor_id' => $sst['sensor_id'], 'name' => $sst['name'], 'unit' => $sst['unit_type'], 'value' => $sst['value'], 'status' => $sst['status']];
             }
         }
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Esempio n. 13
0
 public function actionIndex()
 {
     // default time duration
     $timePoints = Convert::currentTimePoints();
     $getBy = Yii::$app->request->get('get_by');
     if ($getBy == 'week') {
         $timePoints = Convert::currentWeekTimePoints();
     } else {
         if ($getBy == 'month') {
             $timePoints = Convert::currentMonthTimePoints();
         }
     }
     $whereClause = ['sst.sensor_id' => Sensor::ID_SECURITY];
     // get station ids by role
     $role = new Role();
     if (!$role->isAdministrator) {
         $position = $role->getPosition();
         $stationIds = Station::getByRole($position, Yii::$app->user->id);
         $whereClause['s.id'] = $stationIds;
     }
     // get data
     $query = new Query();
     $stations = $query->select('s.area_id, s.status AS station_status, sst.value AS sensor_value, count(w.id) AS total_warning, max(w.warning_time) AS last_warning_time')->from('station s')->leftJoin('sensor_status sst', 'sst.station_id = s.id')->leftJoin('warning w', 'w.station_id = s.id')->where($whereClause)->groupBy('s.id')->all();
     // data
     $parseData = [];
     $data = [];
     // get areas
     $areas = Area::find()->all();
     $parseData['areas'] = $areas;
     if (!empty($areas)) {
         $notHave = [];
         foreach ($areas as $area) {
             $have = 0;
             $data[$area['id']]['has_warning'] = 0;
             $data[$area['id']]['no_warning'] = 0;
             $data[$area['id']]['security_on'] = 0;
             $data[$area['id']]['security_off'] = 0;
             $data[$area['id']]['connected'] = 0;
             $data[$area['id']]['lost_connect'] = 0;
             $data[$area['id']]['last_warning_time'] = 0;
             // security and connect stations
             if (!empty($stations)) {
                 foreach ($stations as $station) {
                     if ($station['area_id'] == $area['id']) {
                         $have = 1;
                         // warnings
                         if ($station['total_warning'] > 0 && $station['last_warning_time'] >= $timePoints['start'] && $station['last_warning_time'] <= $timePoints['end']) {
                             $data[$area['id']]['has_warning']++;
                             $data[$area['id']]['last_warning_time'] = $station['last_warning_time'] > $data[$area['id']]['last_warning_time'] ? $station['last_warning_time'] : $data[$area['id']]['last_warning_time'];
                         } else {
                             $data[$area['id']]['no_warning']++;
                         }
                         // status
                         if ($station['station_status'] == Station::STATUS_CONNECTED) {
                             $data[$area['id']]['connected']++;
                         } else {
                             if ($station['station_status'] == Station::STATUS_LOST) {
                                 $data[$area['id']]['lost_connect']++;
                             }
                         }
                         // security mode
                         if ($station['sensor_value'] == Sensor::SECURITY_ON) {
                             $data[$area['id']]['security_on']++;
                         } else {
                             if ($station['sensor_value'] == Sensor::SECURITY_OFF) {
                                 $data[$area['id']]['security_off']++;
                             }
                         }
                     }
                 }
             }
             if ($have == 0) {
                 $notHave[] = $area['id'];
             }
         }
         if (!empty($notHave)) {
             foreach ($notHave as $not) {
                 unset($data[$not]);
             }
         }
     }
     $parseData['data'] = $data;
     return $this->render('station', $parseData);
 }
Esempio n. 14
0
 private function checkPermission($id)
 {
     $role = new Role();
     if ($role->isAdmin) {
         $position = $role->getPosition();
         $ids = User::getByRole($position, Yii::$app->user->id);
         if (!in_array($id, $ids)) {
             $this->permissionDeny();
         }
     }
 }
Esempio n. 15
0
 public static function isRoleNameValid($role_name)
 {
     $role = Role::find('role_name')->where(['role_name' => $role_name])->one();
     return isset($role->role_name) ? true : false;
 }