Blame view

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