public function getGroupName($gid) { $query = DcmdGroup::findOne($gid); if ($query) { return $query['gname']; } return ""; }
public function getGname($gid) { $query = DcmdGroup::findOne($gid); if ($query) { return $query->gname; } return ""; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params, $gids = NULL) { if ($gids) { $query = DcmdGroup::find()->andWhere($gids)->orderBy("gname"); } else { $query = DcmdGroup::find()->orderBy("gname"); } $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pagesize' => 20]]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['gid' => $this->gid, 'gtype' => $this->gtype, 'utime' => $this->utime, 'ctime' => $this->ctime, 'opr_uid' => $this->opr_uid]); $query->andFilterWhere(['like', 'gname', $this->gname])->andFilterWhere(['like', 'comment', $this->comment]); return $dataProvider; }
/** * Lists all DcmdGroupCmd models. * @return mixed */ public function actionAddGroup($opr_cmd_id = 0) { if (Yii::$app->user->getIdentity()->admin != 1) { Yii::$app->getSession()->setFlash('success', NULL); Yii::$app->getSession()->setFlash('error', "对不起,你没有权限!"); return $this->redirect(['dcmd-opr-cmd/view', 'id' => $opr_cmd_id]); } $model = new DcmdGroupCmd(); if (Yii::$app->request->post()) { ///var_dump(Yii::$app->request->post());exit; $date = date('Y-m-d H:i:s'); if (is_array(Yii::$app->request->post()['DcmdGroupCmd']['gid'])) { foreach (Yii::$app->request->post()['DcmdGroupCmd']['gid'] as $gid) { $dcmd_group_cmd = new DcmdGroupCmd(); $dcmd_group_cmd->gid = $gid; $dcmd_group_cmd->opr_cmd_id = $opr_cmd_id; $dcmd_group_cmd->utime = $date; $dcmd_group_cmd->ctime = $date; $dcmd_group_cmd->opr_uid = Yii::$app->user->getId(); $dcmd_group_cmd->save(); Yii::$app->getSession()->setFlash('success', '添加成功!'); } } else { Yii::$app->getSession()->setFlash('error', "没有选择用户组!"); } return $this->redirect(['dcmd-opr-cmd/view', 'id' => $opr_cmd_id]); } else { $exist_group = array(); $query = DcmdGroupCmd::find()->andWhere(['opr_cmd_id' => $opr_cmd_id])->asArray()->all(); foreach ($query as $item) { $exist_group[$item['gid']] = $item['gid']; } $query = DcmdGroup::find()->andWhere(['gtype' => 2])->asArray()->all(); $group = array(); foreach ($query as $item) { if (!array_key_exists($item['gid'], $exist_group)) { $group[$item['gid']] = $item['gname']; } } $opr_cmd = DcmdOprCmd::findOne($opr_cmd_id); return $this->render('add_group', ['model' => $model, 'opr_cmd' => $opr_cmd, 'group' => $group]); } }
/** *Get gid-gname */ protected function getGroups() { $ret = DcmdGroup::findBySql("select gid, gname from dcmd_group where gtype=1")->asArray()->all(); $groupId = array(); foreach ($ret as $gid) { $groupId[$gid['gid']] = $gid['gname']; } return $groupId; }
protected function getUserGroup() { $ret = DcmdGroup::find()->asArray()->all(); $user_group = array(); $user_group['sys'] = array(); $user_group['svr'] = array(); foreach ($ret as $item) { if ($item['gtype'] == 1) { $user_group['sys'][$item['gid']] = $item['gname']; } else { $user_group['svr'][$item['gid']] = $item['gname']; } } return $user_group; }
protected function getGroupName($gid) { $query = DcmdGroup::findOne($gid); if ($query) { return $query['gname']; } return $gid; }
/** * Finds the DcmdGroup model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return DcmdGroup the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = DcmdGroup::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }