Blame view

frontend/controllers/SearchController.php 5.4 KB
fbdb1f1c   Yarik   test
1
2
3
  <?php
  namespace frontend\controllers;
  
f94a00a6   Yarik   test
4
  use common\models\CustomerSearch;
6dd6c4bf   Administrator   17.02.16
5
  use common\models\Project;
eb7e82fb   Administrator   29.02.16
6
7
  use common\models\UserInfo;
  use common\models\Vacancy;
fbdb1f1c   Yarik   test
8
9
10
11
12
13
14
15
16
  use Yii;
  use common\models\LoginForm;
  use frontend\models\PasswordResetRequestForm;
  use frontend\models\ResetPasswordForm;
  use frontend\models\SignupForm;
  use frontend\models\ContactForm;
  use frontend\models\Options;
  use frontend\models\OptionValues;
  use yii\base\InvalidParamException;
6dd6c4bf   Administrator   17.02.16
17
  use yii\data\ActiveDataProvider;
eb7e82fb   Administrator   29.02.16
18
  use yii\data\Pagination;
fbdb1f1c   Yarik   test
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
  use yii\web\BadRequestHttpException;
  use yii\web\Controller;
  use yii\filters\VerbFilter;
  use yii\filters\AccessControl;
  use frontend\models\OptionsToValues;
  use yii\validators\EmailValidator;
  use common\models\User;
  use yii\helpers\VarDumper;
  use common\models\Page; 
  use frontend\models\Option;
  use common\models\Social;
  
  
  /**
   * Site controller
   */
  class SearchController extends Controller
  {
      public $defaultAction = 'common';
  
      /**
       * @inheritdoc
       */
      public function actions()
      {
          return [
              'error' => [
                  'class' => 'yii\web\ErrorAction',
              ],
              'captcha' => [
                  'class' => 'yii\captcha\CaptchaAction',
                  'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
              ],
          ];
      }
  
      public function actionProject()
      {
6dd6c4bf   Administrator   17.02.16
57
58
59
60
61
62
63
64
65
66
67
  
          $projects = new ActiveDataProvider([
              'query' =>  Project::find(),
              'pagination' => [
                  'pageSize' => 9,
              ],
          ]);
  
          return $this->render('project',[
              'projects' => $projects
          ]);
fbdb1f1c   Yarik   test
68
69
      }
  
06b4c223   Administrator   01.03.16
70
71
  
      public function actionCustomer(){
f94a00a6   Yarik   test
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
          $model = new CustomerSearch();
          $dataProvider = $model->search(Yii::$app->request->queryParams);
          $dataProvider->setSort([
              'attributes' => [
                  'name' => [
                      'asc' => [
                          'company_info.name' => SORT_ASC,
                          'firstname' => SORT_ASC,
                          'lastname' => SORT_ASC,
                      ],
                      'desc' => [
                          'company_info.name' => SORT_DESC,
                          'firstname' => SORT_DESC,
                          'lastname' => SORT_DESC,
                      ],
                      'default' => SORT_ASC,
                      'label' => 'Название',
                  ],
                  'staff' => [
                      'asc' => [
                          'company_info.staff' => SORT_ASC,
                      ],
                      'desc' => [
                          'company_info.staff' => SORT_DESC,
                      ],
                      'default' => SORT_DESC,
                      'label' => 'Количество сотрудников',
                  ],
                  'visit' => [
                      'asc' => [
                          'user_info.date_visit' => SORT_ASC,
                      ],
                      'desc' => [
                          'user_info.date_visit' => SORT_DESC,
                      ],
                      'default' => SORT_DESC,
                      'label' => 'Последний визит',
                  ],
                  'city' => [
                      'asc' => [
                          'user_info.city' => SORT_ASC,
                      ],
                      'desc' => [
                          'user_info.city' => SORT_DESC,
                      ],
                      'default' => SORT_ASC,
                      'label' => 'Город',
                  ],
              ],
          ]);
          $model->load(Yii::$app->request->queryParams);
          $cities = UserInfo::find()->select('city')->distinct()->asArray()->indexBy('city')->column();
06b4c223   Administrator   01.03.16
124
          return $this->render('customer',[
f94a00a6   Yarik   test
125
126
127
              'model' => $model,
              'dataProvider' => $dataProvider,
              'cities' => $cities,
06b4c223   Administrator   01.03.16
128
129
130
          ]);
      }
  
fbdb1f1c   Yarik   test
131
132
      public function actionCompany()
      {
3ea37908   Administrator   01.03.16
133
134
135
136
137
138
139
140
141
142
143
144
145
146
          $query = UserInfo::find()
              ->joinWith([ 'user' ])
              ->where(['is_customer' => 1,'user.type'=>2]);
  
          $companies = new ActiveDataProvider([
              'query' =>  $query,
              'pagination' => [
                  'pageSize' => 3,
              ],
          ]);
  
          return $this->render('company',[
              'companies' => $companies
          ]);
fbdb1f1c   Yarik   test
147
148
149
150
      }
  
      public function actionPerformer()
      {
3ea37908   Administrator   01.03.16
151
152
153
154
          $query = UserInfo::find()
              ->joinWith([ 'user' ])
              ->where(['is_customer' => 1,'user.type'=>1]);
  
eb7e82fb   Administrator   29.02.16
155
156
157
158
159
160
161
162
163
164
165
  
          $performer = new ActiveDataProvider([
              'query' =>  $query,
              'pagination' => [
                  'pageSize' => 3,
              ],
          ]);
  
          return $this->render('performer',[
              'performer' => $performer
          ]);
fbdb1f1c   Yarik   test
166
167
      }
  
7fc05ac5   Yarik   test
168
169
      public function actionVacancy()
      {
eb7e82fb   Administrator   29.02.16
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
  
  
          $query = Vacancy::find();
  
          $countQuery = clone $query;
  
          $pagination = new Pagination(['totalCount' => $countQuery->count(),
              'pageSize' => 15,
          ]);
  
          $vacancy = $query->offset($pagination->offset)
              ->limit($pagination->limit);
  
  
          $provider = new ActiveDataProvider([
              'query' => $vacancy,
              'pagination' => false,
              'sort' => [
                  'defaultOrder' => [
                      'date_add' => SORT_DESC,
                      'name' => SORT_ASC,
                  ]
              ],
          ]);
  
  
  
          return $this->render('vacancy',[
              'provider' => $provider,
              'pagination' => $pagination
          ]);
7fc05ac5   Yarik   test
201
202
      }
  
fbdb1f1c   Yarik   test
203
  }