public function getPrivilege($userId = null) { $db = new Query(); $db->select("group_id")->from("privilege")->where("user_id = '{$userId}' "); $groupUser = $db->all(); $GroupUserArr = array(); foreach ($groupUser as $Guser) { $GroupUserArr[] = "'" . $Guser['group_id'] . "'"; } $GroupUser = implode(",", $GroupUserArr); if (!empty($GroupUser)) { $GroupUserVal = $GroupUser; } else { $GroupUserVal = "''"; } if (!empty($GroupUserVal)) { $Privilege = GroupPcu::find()->where('group_id IN(' . $GroupUserVal . ')')->all(); $PcuArr = array(); foreach ($Privilege as $rs) { $PcuArr[] = $rs['hospcode']; } } else { $PcuArr = null; } Yii::$app->session['privilege'] = $PcuArr; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = GroupPcu::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, 'group_id' => $this->group_id, 'create_date' => $this->create_date]); $query->andFilterWhere(['like', 'hospcode', $this->hospcode]); return $dataProvider; }
/** * Displays a single GroupUser model. * @param integer $id * @return mixed */ public function actionView($id) { $model = new GroupPcu(); $pcu = $model->get_pcu_ingroup($id); return $this->render('view', ['model' => $this->findModel($id), 'pcu' => $pcu]); }
?> <div class="group-user-index"> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <p> <?php echo Html::a('Create Group User', ['create'], ['class' => 'btn btn-success']); ?> </p> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'group_name', 'detail', ['class' => '\\kartik\\grid\\DataColumn', 'label' => 'สถานบริการในกลุ่มนี้', 'mergeHeader' => true, 'hAlign' => 'center', 'format' => 'raw', 'value' => function ($model) { $groupPcu = new GroupPcu(); $btn = "<button type=\"button\" class=\"btn btn-default btn-sm\" onclick=\"get_pcu_in_privilage('{$model->id} ','{$model->group_name} ')\">" . "ดูสถานบริการ <span class=\"badge\">" . $groupPcu->count_pcu($model->id) . "</span>" . "</button>"; return $btn; }], ['class' => 'yii\\grid\\ActionColumn']], 'panel' => ['type' => GridView::TYPE_PRIMARY, 'heading' => $this->title]]); ?> </div> <!--- ######### Dialog Get PCU ########### --> <div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" id="pop_get_pcu"> <div class="modal-dialog modal-lg"> <div class="modal-content"> <div class="modal-header">
public function actionGet_pcu_all() { $input = \Yii::$app->request; $GroupId = $input->post('id'); $model = new GroupPcu(); $pcu = $model->get_pcu_outgroup($GroupId); return $this->renderPartial('pcu_out_groups', ['pcu' => $pcu, 'groupId' => $GroupId]); }