Пример #1
0
 /**
  *Get dcmd node group name
  */
 public function getNodeGname($ngid)
 {
     $query = DcmdNodeGroup::findOne($ngid);
     if ($query) {
         return $query->ngroup_name;
     }
     return "";
 }
Пример #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = DcmdNodeGroup::find()->orderBy("ngroup_name");
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pagesize' => 20]]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['ngroup_id' => $this->ngroup_id, 'gid' => $this->gid]);
     $query->andFilterWhere(['like', 'ngroup_name', $this->ngroup_name]);
     return $dataProvider;
 }
 /**
  * Finds the DcmdNodeGroup model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return DcmdNodeGroup the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = DcmdNodeGroup::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  *Get dcmd_node_group list
  */
 protected function getDcmdNodeGroup()
 {
     $group = array();
     $ret = DcmdNodeGroup::findBySql("select ngroup_id, ngroup_name from dcmd_node_group")->asArray()->all();
     foreach ($ret as $g) {
         $group[$g['ngroup_id']] = $g['ngroup_name'];
     }
     return $group;
 }
 /**
  * Updates an existing DcmdNodeGroupAttr model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id, $ngroup_id)
 {
     $node_group = DcmdNodeGroup::findOne($ngroup_id);
     ///仅仅用户与该应用在同一个系统组才可以操作
     $query = DcmdUserGroup::findOne(['uid' => Yii::$app->user->getId(), 'gid' => $node_group->gid]);
     if ($query == NULL) {
         Yii::$app->getSession()->setFlash('success', NULL);
         Yii::$app->getSession()->setFlash('error', "对不起, 你没有权限!");
         return $this->redirect(['/dcmd-node-group/view', 'id' => $ngroup_id, 'show_div' => 'dcmd-node-group-attr']);
     }
     if ($id == 0) {
         ///需要新建
         $attr_id = Yii::$app->request->queryParams['attr_id'];
         $def_attr = DcmdNodeGroupAttrDef::findOne($attr_id);
         $query = DcmdNodeGroupAttr::findOne(['ngroup_id' => $ngroup_id, 'attr_name' => $def_attr->attr_name]);
         if (count($query) > 0) {
             $id = $query['id'];
         } else {
             $model = new DcmdNodeGroupAttr();
             $model->ngroup_id = $ngroup_id;
             $model->attr_name = $def_attr->attr_name;
             $model->attr_value = $def_attr->def_value;
             $model->comment = $def_attr->comment;
             $model->utime = date('Y-m-d H:i:s');
             $model->ctime = $model->utime;
             $model->opr_uid = Yii::$app->user->getId();
             $model->save();
             $id = $model->id;
         }
     }
     $model = $this->findModel($id);
     $group = DcmdNodeGroup::findOne($model->ngroup_id);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         Yii::$app->getSession()->setFlash('success', '修改成功!');
         return $this->redirect(['/dcmd-node-group/view', 'id' => $group->ngroup_id, 'show_div' => 'dcmd-node-group-attr']);
     } else {
         return $this->render('update', ['model' => $model, 'group' => $group]);
     }
 }