Your IP : 216.73.216.79


Current Path : /var/www/html/jppmintranetv2/backend/modules/contentDirectory/models/
Upload File :
Current File : /var/www/html/jppmintranetv2/backend/modules/contentDirectory/models/ContentDirectorySearch.php

<?php

namespace backend\modules\contentDirectory\models;

use yii\base\Model;
use yii\data\ActiveDataProvider;
use backend\modules\contentDirectory\models\ContentDirectory;
use yii;

/**
 * ContentDirectorySearch represents the model behind the search form of `backend\modules\contentDirectory\models\ContentDirectory`.
 */
class ContentDirectorySearch extends ContentDirectory {

    /**
     * {@inheritdoc}
     */
    public function rules() {
        return [
            [['created_at', 'updated_at', 'employee_dob', 'employee_status', 'employee_phone', 'employee_email', 'employee_name', 'employee_dept', 'employee_unit'], 'safe'],
            [['created_by', 'updated_by', 'sorting'], 'integer'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function scenarios() {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params) {
        $query = ContentDirectory::find();

        // add conditions that should always apply here
        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            'pagination' => ['pageSize' => 10],
            'sort' => ['defaultOrder' => ['sorting' => SORT_ASC]],
        ]);

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

        // grid filtering conditions
        $query->andFilterWhere(['=', 'employee_unit', $this->employee_unit]);
        $query->andFilterWhere(['LIKE', 'employee_name', $this->employee_name]);
        $query->andFilterWhere(['LIKE', 'employee_email', $this->employee_email]);

		if (\backend\modules\mimin\models\User::userrole() == 'admin-department'){
			$query->andWhere(['=', 'employee_unit', Yii::$app->user->identity->dept]);
		}

        return $dataProvider;
    }
    
    public function searchsorting($params) {
        $query = ContentDirectory::find();

        // add conditions that should always apply here
        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            'pagination' => ['pageSize' => false],
            'sort' => ['defaultOrder' => ['sorting' => SORT_ASC]],
        ]);

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

        // grid filtering conditions
        $query->andFilterWhere(['=', 'employee_unit', $this->employee_unit]);
        $query->andFilterWhere(['LIKE', 'employee_name', $this->employee_name]);
        $query->andFilterWhere(['LIKE', 'employee_email', $this->employee_email]);

		if (\backend\modules\mimin\models\User::userrole() == 'admin-department'){
			$query->andWhere(['=', 'employee_unit', Yii::$app->user->identity->dept]);
		}

        return $dataProvider;
    }

}