public function actionMain() { $uid = Yii::$app->user->identity->user_id; $access = Access::find()->where(['user_id' => $uid]); Yii::$app->view->params['customParam'] = 'customValue'; $this->view->params['customParam'] = 'customValue'; return $this->render('/layouts/main', ['param' => 'lol']); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Access::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'roleId' => $this->roleId]); $query->andFilterWhere(['like', 'controller', $this->controller])->andFilterWhere(['like', 'method', $this->method]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Access::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, 'user_owner' => $this->user_owner, 'user_gest' => $this->user_gest, 'date' => $this->date]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Access::find(); $query->joinWith(['module']); $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, 'profile_id' => $this->profile_id, 'module_id' => $this->module_id]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function searchFriends($params) { $query = Access::find()->withUser(Yii::$app->user->id); $dataProvider = new ActiveDataProvider(['query' => $query]); $query->joinWith(['note', 'note.user']); $query->groupBy('evrnt_note.creator'); $dataProvider->sort->attributes['noteCreator'] = ['asc' => ['evrnt_note.creator' => SORT_ASC], 'desc' => ['evrnt_note.creator' => SORT_DESC]]; $this->load($params); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['evrnt_access.id' => $this->id, 'evrnt_access.note_id' => $this->note_id]); $query->andWhere('evrnt_user.name LIKE "%' . $this->noteCreator . '%" ' . 'OR evrnt_user.surname LIKE "%' . $this->noteCreator . '%"'); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Access::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $dataProvider->sort->attributes['noteCreator'] = ['asc' => ['evrnt_note.creator' => SORT_ASC], 'desc' => ['evrnt_note.creator' => SORT_DESC]]; $this->load($params); if (!($this->load($params) && $this->validate())) { $query->joinWith(['note']); return $dataProvider; } $query->andFilterWhere(['evrnt_access.id' => $this->id, 'evrnt_access.note_id' => $this->note_id, 'evrnt_access.user_id' => $this->user_id]); $query->joinWith(['noteCreator' => function ($q) { $q->where(['evrnt_note.creator' => $this->noteCreator]); }]); return $dataProvider; }
public function createMenu() { $menu = ""; if (!Yii::$app->user->isGuest) { $profile = Profile::findOne(Yii::$app->user->identity->profile_id); $menu .= "<h2><span class='label label-primary'>{$profile->name}</span></h2>"; // $menu .= "<a href='" . Url::toRoute("site/index") . "'><i class='fa fa-fw fa-home'></i><span>Home</span></a>"; $access = Access::find()->where(["profile_id" => Yii::$app->user->identity->profile_id])->all(); foreach ($access as $value) { $module = Module::find()->where(["id" => $value->module_id])->one(); $path = "{$module->controller}/index"; $href = Url::toRoute($path); $link = "<a href='{$href}'><i class='fa fa-fw {$module->iconfa}'></i><span>{$module->label}</span></a>"; $menu .= $link; } } // if (Yii::$app->user->isGuest) { // $menu .= "<a href='" . Url::toRoute('site/login') . "'><i class='fa fa-fw fa-sign-in'></i><span>Login</span></a>"; // } else { // $menu .= "<a href='" . Url::toRoute('site/logout') . "' data-method='post'><i class='fa fa-fw fa-sign-out'></i><span>Logout (" . Yii::$app->user->identity->username . ")</span></a>"; // } return $menu; }
public function actionDeletemodule() { $data = []; $module = Access::findOne(["id" => $_POST["module_id"]]); $profile_id = $module->profile_id; $rowdeleted = $module->delete(); $data['message'] = "{$rowdeleted} Module(s) Deleted"; $dataProvider = new ActiveDataProvider(['query' => Access::find()->where(["profile_id" => $profile_id])->orderBy('id DESC'), 'pagination' => ['pageSize' => 20]]); $data['gridmodules'] = GridView::widget(['dataProvider' => $dataProvider, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'id', ['attribute' => 'module', 'value' => 'module.label'], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{deletemodule}', 'buttons' => ['deletemodule' => function () { return Html::a('<span class="glyphicon glyphicon-trash"></span>', null, ['data-confirm' => 'Are you sure you want to delete this item?', 'class' => "deletemoduleajax"]); }]]], 'options' => ['class' => '', 'id' => 'grid-accesses']]); Yii::$app->response->format = Response::FORMAT_JSON; return $data; }
} ?> </tr> <?php foreach ($controllers as $controller) { ?> <tr> <td><?php echo $controller; ?> </td> <?php foreach ($methods as $method) { $name = "Roles[{$controller}][{$method}]"; $elementId = $method; $access = \app\models\Access::find()->where(['roleId' => $roleId, 'controller' => $controller, 'method' => $method])->exists(); if ($access) { $checked = ' checked="checked" '; } else { $checked = ''; } //echo $method .$fields[$controller]; exit(0); // if (array_search($method, $fields[$controller]) !== false) // echo '<td> <input type="checkbox" name="' . $name . '" id="' . $elementId . '" ' . $checked . ' title="Role for ' . $controller . ' ' . $method . '" /> </td>'; // else echo '<td> <input type="checkbox" name="' . $name . '" id="' . $elementId . '" ' . $checked . ' title="Role for ' . $controller . ' ' . $method . '" /> </td>'; } ?> </tr> <?php }
public static function checkAccess($name, $roleId) { $parts = explode(".", $name); return \app\models\Access::find()->where(['roleId' => $roleId, 'LOWER(controller)' => strtolower($parts[0]), 'LOWER(method)' => strtolower($parts[1])])->exists(); }