Beispiel #1
0
 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;
 }
 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]);
     }
 }
Beispiel #3
0
 /**
  * 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;
 }
 /**
  * Delete multiple existing Access model.
  * For ajax request will return json object
  * and for non-ajax request if deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionBulkDelete()
 {
     $request = Yii::$app->request;
     $pks = $request->post('pks');
     // Array or selected records primary keys
     foreach (Access::findAll(json_decode($pks)) as $model) {
         $model->delete();
     }
     if ($request->isAjax) {
         /*
          *   Process for ajax request
          */
         Yii::$app->response->format = Response::FORMAT_JSON;
         return ['forceClose' => true, 'forceReload' => true];
     } else {
         /*
          *   Process for non-ajax request
          */
         return $this->redirect(['index']);
     }
 }
 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' => '']);
 }