SearchController.php 5.48 KB
<?php
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;


/**
 * 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()
    {

        $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([
            '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();
        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,
            ],
        ]);

        return $this->render('performer',[
            'performer' => $performer
        ]);
    }

    public function actionVacancy()
    {


        $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
        ]);
    }

}