public function edit()
 {
     $model = Model::find($this->request->id);
     if (!$model) {
         $this->redirect('Models::index');
     }
     if ($this->request->data && $model->save($this->request->data)) {
         $this->redirect(array('Models::view', 'args' => array($model->id)));
     }
     return compact('model');
 }
Example #2
0
 private function notHas($uid, $app)
 {
     $app = App::find()->where(['code' => $app])->asArray()->one();
     $role = RoleUser::find()->where(['uid' => $uid])->asArray()->all();
     $roleid = array();
     foreach ($role as $vr) {
         $roleid[] = $vr['rid'];
     }
     $roleid = implode(',', $roleid);
     $rule = Rule::find()->select(['aid', 'role_id', 'model_id', 'feature_id', 'scope_id'])->where("role_id not in({$roleid})")->andWhere(['aid' => $app['id']])->asArray()->all();
     $result = array();
     $unique = array();
     foreach ($rule as $k => $vu) {
         $apps = App::find()->select(['name'])->where(['id' => $vu['aid']])->asArray()->one();
         $result[$k]['app'] = $apps['name'];
         $roles = Role::find()->select(['name'])->where(['id' => $vu['role_id']])->asArray()->one();
         $result[$k]['role'] = $roles['name'];
         $model = Model::find()->select(['name'])->where(['id' => $vu['model_id']])->asArray()->one();
         $result[$k]['model'] = $model['name'];
         $feature = Feature::find()->select(['name'])->where(['id' => $vu['feature_id']])->asArray()->one();
         $result[$k]['feature'] = $feature['name'];
         $scopes = Rule::find()->select(['scope_id'])->where(['aid' => $vu['aid'], 'role_id' => $vu['role_id'], 'model_id' => $vu['model_id'], 'feature_id' => $vu['feature_id']])->asArray()->all();
         foreach ($scopes as $ks => $vs) {
             $scope = Scope::find()->select(['name', 'attribute'])->where(['id' => $vs['scope_id']])->asArray()->one();
             $result[$k]['scope'][$ks]['name'] = $scope['name'];
             $result[$k]['scope'][$ks]['attribute'] = $scope['attribute'];
         }
         $unique[$k] = $vu['aid'] . $vu['role_id'] . $model['name'] . $feature['name'];
     }
     // delete the repeat elements
     $unique = array_unique($unique);
     $res = array();
     foreach ($unique as $kq => $vq) {
         $res[] = $result[$kq];
     }
     return $res;
 }
Example #3
0
 private function notHas($uid, $app, $feature)
 {
     $app = App::find()->select(['id', 'name'])->where(['code' => $app])->asArray()->one();
     $role = RoleUser::find()->select(['rid', 'rname'])->where(['uid' => $uid])->asArray()->all();
     $roleid = array();
     foreach ($role as $vr) {
         $roleid[] = $vr['rid'];
     }
     $roleid = implode(',', $roleid);
     $scopes = Rule::find()->select(['model_id', 'scope_id'])->where(['aid' => $app['id']])->andWhere(['feature_code' => $feature])->andWhere("role_id not in({$roleid})")->asArray()->all();
     $feature = Feature::find()->select(['name'])->where(['code' => $feature])->asArray()->one();
     // delete repeat data
     $unique = array();
     foreach ($scopes as $k => $vs) {
         $unique[$k] = $vs['model_id'] . ',' . $vs['scope_id'];
     }
     $scope = array_unique($unique);
     $result = array();
     foreach ($scope as $k => $v) {
         $result[] = $scopes[$k];
     }
     $final = array();
     foreach ($result as $k => $vu) {
         $model = Model::find()->select(['name'])->where(['id' => $vu['model_id']])->asArray()->one();
         $scope = Scope::find()->select(['name', 'attribute'])->where(['id' => $vu['scope_id']])->asArray()->one();
         $final[$k]['model'] = $model['name'];
         $final[$k]['feature'] = $feature['name'];
         $final[$k]['scope'] = $scope['name'];
         $final[$k]['scope_attribute'] = $scope['attribute'];
     }
     return $final;
 }