public function actionIndex() { $methods = Role::$methods; $fields = Role::accessFilter(); $controllers = Role::$controllers; $roleId = isset($_GET['roleId']) == null ? 1 : $_GET['roleId']; $model = $this->findModel($roleId); $model->role_name = $roleId; $sql = ''; //echo '<pre>';print_r($_POST['Roles']); exit(0); if ($model->load(Yii::$app->request->post())) { \app\models\Access::deleteAll('roleId = :roleId', [':roleId' => $roleId]); foreach ($_POST['Roles'] as $keys => $values) { foreach ($values as $k => $v) { //if($v=='on') $sql .= ' INSERT INTO access (roleId,controller,method) values ("' . $roleId . '","' . $keys . '","' . $k . '"); '; } } if ($sql) { Yii::$app->db->createCommand($sql)->execute(); Yii::$app->session->setFlash('success', 'Successfully, Update access role!'); } } return $this->render('index', ['model' => $model, 'methods' => $methods, 'fields' => $fields, 'controllers' => $controllers, 'roleId' => $roleId]); }
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; }
public function getAccess($controller) { $allow = false; $accesses = Access::findAll(["profile_id" => Yii::$app->user->identity->profile_id]); foreach ($accesses as $accesses) { $module = Module::findOne(["id" => $accesses->module_id]); if ($module->controller === $controller) { $allow = true; break; } } return $allow; }
/** * 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; }
/** * Displays a single Calendar model. * @param integer $id * @return string * @throws ForbiddenHttpException * @throws NotFoundHttpException */ public function actionView($id) { $model = $this->findModel($id); $result = Access::checkAccess($model); if ($result) { switch ($result) { case Access::ACCESS_CREATOR: return $this->render('viewCreator', ['model' => $model]); break; case Access::ACCESS_GUEST: return $this->render('viewGuest', ['model' => $model]); break; } } throw new ForbiddenHttpException("You are not allowed here"); }
/** * 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; }
/** * @param $id * @return string * @throws ForbiddenHttpException * @throws NotFoundHttpException */ public function actionView($id) { $model = $this->findModel($id); $result = Access::checkAccess($model); switch ($result) { case Access::ACCESS_CREATOR: return $this->render('viewCreator', ['model' => $model]); break; case Access::ACCESS_GUEST: return $this->render('viewGuest', ['model' => $model]); break; default: throw new ForbiddenHttpException("Access denied", 403); break; } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $access = Access::findAll(['user_id' => Yii::$app->user->getId()]); $counties = ArrayHelper::getColumn($access, 'county_id'); $query = Job::find()->where(['county.id' => $counties]); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 20]]); $dataProvider->sort->attributes['jobField.name'] = ['asc' => ['job_field.name' => SORT_ASC], 'desc' => ['Job_field.name' => SORT_DESC]]; $dataProvider->sort->attributes['city.name'] = ['asc' => ['city.name' => SORT_ASC], 'desc' => ['city.name' => SORT_DESC]]; $dataProvider->sort->attributes['state.name'] = ['asc' => ['state.name' => SORT_ASC], 'desc' => ['state.name' => SORT_DESC]]; $dataProvider->sort->attributes['county.name'] = ['asc' => ['county.name' => SORT_ASC], 'desc' => ['county.name' => SORT_DESC]]; $query->joinWith(['jobField']); $query->joinWith(['city']); $query->joinWith(['state']); $query->joinWith(['county']); $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, 'job_field_id' => $this->job_field_id, 'state_id' => $this->state_id, 'date_posted' => $this->date_posted, 'job_field.name' => $this->jobField['name'], 'city.name' => $this->city['name'], 'county.name' => $this->county['name'], 'state.name' => $this->state['name']]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'company', $this->company])->andFilterWhere(['like', 'phone_number', $this->phone_number])->andFilterWhere(['like', 'url', $this->url])->andFilterWhere(['like', 'job_field.name', $this->getAttribute('jobField.name')])->andFilterWhere(['like', 'city.name', $this->getAttribute('city.name')])->andFilterWhere(['like', 'county.name', $this->getAttribute('county.name')])->andFilterWhere(['like', 'state.name', $this->getAttribute('state.name')]); return $dataProvider; }
public function actionIndex() { if (\Yii::$app->user->isGuest) { return $this->render('guest'); } else { $access = Access::findAll(['user_id' => Yii::$app->user->getId()]); $counties = ArrayHelper::getColumn($access, 'county_id'); $numCounties = count($counties); $model = new IndustryForm(); $model->load(Yii::$app->request->post()); $dataProvider = $this->filter($counties, $model->field); $allIndrLine = [['Date', 'All Industries']]; $queryPast = (new \yii\db\Query())->select(['*'])->from('past_listings')->where(['county_id' => $counties])->orderBy(['date' => SORT_DESC])->limit(10 * $numCounties)->all(); $lastMonthCounties = []; for ($i = 0; $i < $numCounties; $i++) { array_push($lastMonthCounties, $queryPast[3 * $numCounties + $i]); } $industry = $this->countIndustry($counties); $lastMonthInd = $this->countLastMonthIndustry($lastMonthCounties, $numCounties); $monthChange = $this->countMonthChange($industry, $lastMonthInd); $byIndrLine = $this->countByIndrPast($queryPast, $numCounties); return $this->render('index', ['dataProvider' => $dataProvider, 'model' => $model, 'industry' => $industry, 'lastMonthInd' => $lastMonthInd, 'monthChange' => $monthChange, 'byIndrLine' => $byIndrLine]); } }
/** * Deletes an existing Note model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param $id * @return \yii\web\Response * @throws ForbiddenHttpException * @throws NotFoundHttpException * @throws \Exception */ public function actionDelete($id) { $model = $this->findModel($id); if (Access::checkIsCreator($model)) { $model->delete(); return $this->redirect(['index']); } throw new ForbiddenHttpException("Not allowed delete note other user"); }
public function actionUpdateRegion() { /** * check if the user is already logged in * if so, do nothing and return them to the home screen */ if (\Yii::$app->user->isGuest) { return $this->goHome(); } $model = new UpdateRegionForm(); $stateList = State::find()->all(); $countyList = County::find()->orderBy('name')->all(); if ($model->load(Yii::$app->request->post())) { $subHead = 'You must select a region.'; if ($model->validate()) { $subHead = 'Region Successfully Changed'; $post = Yii::$app->db->createCommand()->delete('access', ['user_id' => Yii::$app->user->getId()])->execute(); foreach ($model->access as $county => $id) { if ($id != "multiselect-all") { $post = Yii::$app->db->createCommand()->insert('access', ['county_id' => $id, 'user_id' => Yii::$app->user->getId()])->execute(); } } } $access = Access::findAll(['user_id' => Yii::$app->user->getId()]); $access = ArrayHelper::getColumn($access, 'county_id'); return $this->render('update-region', ['access' => $access, 'model' => $model, 'stateList' => $stateList, 'countyList' => $countyList, 'subHead' => $subHead]); } $access = Access::findAll(['user_id' => Yii::$app->user->getId()]); $access = ArrayHelper::getColumn($access, 'county_id'); return $this->render('update-region', ['access' => $access, 'model' => $model, 'stateList' => $stateList, 'countyList' => $countyList, 'subHead' => '']); }
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(); }
/** * @return \yii\db\ActiveQuery */ public function getAccess() { return $this->hasMany(Access::className(), ['date' => 'date_event']); }
/** * Finds the Access model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Access the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Access::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getAccesses() { return $this->hasMany(Access::className(), ['roleId' => 'id']); }
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; }
public function getAccess() { return $this->hasMany(Access::className(), ['user_gest' => 'id']); }
} ?> </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 function actionAddrole() { $access = new Access(); $access->addRole(); return $this->render('index'); }