示例#1
0
 /**
  * Assign or remove items
  * @param string $action
  * @return array
  */
 public function actionAssign()
 {
     $post = Yii::$app->getRequest()->post();
     $action = $post['action'];
     $routes = $post['routes'];
     $manager = Yii::$app->getAuthManager();
     $error = [];
     if ($action == 'assign') {
         $this->saveNew($routes);
     } else {
         foreach ($routes as $route) {
             $child = $manager->getPermission($route);
             try {
                 $manager->remove($child);
             } catch (Exception $exc) {
                 $error[] = $exc->getMessage();
             }
         }
     }
     Helper::invalidate();
     Yii::$app->getResponse()->format = 'json';
     return array_merge($this->getRoutes(), ['errors' => $error]);
 }
 /**
  * Assign or revoke assignment to user
  * @param  integer $id
  * @param  string  $action
  * @return mixed
  */
 public function actionAssign($id)
 {
     $post = Yii::$app->getRequest()->post();
     $action = $post['action'];
     $roles = $post['roles'];
     $manager = Yii::$app->getAuthManager();
     $error = [];
     if ($action == 'assign') {
         foreach ($roles as $name) {
             try {
                 $item = $manager->getRole($name);
                 $item = $item ?: $manager->getPermission($name);
                 $manager->assign($item, $id);
             } catch (\Exception $exc) {
                 $error[] = $exc->getMessage();
             }
         }
     } else {
         foreach ($roles as $name) {
             try {
                 $item = $manager->getRole($name);
                 $item = $item ?: $manager->getPermission($name);
                 $manager->revoke($item, $id);
             } catch (\Exception $exc) {
                 $error[] = $exc->getMessage();
             }
         }
     }
     Helper::invalidate();
     Yii::$app->response->format = 'json';
     return array_merge($this->getItems($id), ['errors' => $error]);
 }
 public function actionDeviceOverview()
 {
     $deviceModel = Devices::find()->all();
     $this->layout = "dashboard";
     $response = array();
     foreach ($deviceModel as $device) {
         $temp = array();
         $deviceLogs = DeviceLogs::find()->where(['device_id' => $device->id])->orderBy(['id' => SORT_DESC])->one();
         $temp['id'] = $device->id;
         $temp['controller_id'] = $device->controller_id;
         $temp['sim_number'] = $device->sim_number;
         $temp['status'] = $device->status == 1 ? "Online" : "Offline";
         if (!empty($deviceLogs)) {
             $temp['current_voltage'] = $deviceLogs->current_voltage;
             $temp['current_load'] = isset($deviceLogs->current_load) ? $deviceLogs->current_load / 10 : $deviceLogs->current_load;
             $temp['voltage_status'] = Helper::voltageStatus($deviceLogs->voltage_status);
             $temp['light_status'] = Helper::lightStatus($deviceLogs->light_status);
             $temp['overload_status'] = Helper::overloadStatus($deviceLogs->overload_status);
             $temp['created'] = date("d-M-Y H:i:s", strtotime($deviceLogs->created));
         }
         $response[] = $temp;
     }
     $dataProvider = new ArrayDataProvider(['key' => 'id', 'allModels' => $response]);
     return $this->render('deviceOverview', ['dataProvider' => $dataProvider]);
 }
示例#4
0
 /**
  * Assign or remove items
  * @param string $id
  * @param string $action
  * @return array
  */
 public function actionAssign($id)
 {
     $post = Yii::$app->getRequest()->post();
     $action = $post['action'];
     $items = $post['items'];
     $manager = Yii::$app->getAuthManager();
     $parent = $this->type === Item::TYPE_ROLE ? $manager->getRole($id) : $manager->getPermission($id);
     $error = [];
     if ($action == 'assign') {
         foreach ($items as $name) {
             $child = $manager->getPermission($name);
             if ($this->type === Item::TYPE_ROLE && $child === null) {
                 $child = $manager->getRole($name);
             }
             try {
                 $manager->addChild($parent, $child);
             } catch (\Exception $e) {
                 $error[] = $e->getMessage();
             }
         }
     } else {
         foreach ($items as $name) {
             $child = $manager->getPermission($name);
             if ($this->type === Item::TYPE_ROLE && $child === null) {
                 $child = $manager->getRole($name);
             }
             try {
                 $manager->removeChild($parent, $child);
             } catch (\Exception $e) {
                 $error[] = $e->getMessage();
             }
         }
     }
     Helper::invalidate();
     Yii::$app->getResponse()->format = 'json';
     return $this->getItems($id);
 }