<?php
namespace app\models;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\models\Zakaz;
/**
* ZakazSearch represents the model behind the search form about `app\models\Zakaz`.
*/
class ZakazSearch extends Zakaz
{
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id_zakaz', 'id_sotrud', 'id_tovar', 'status'], 'integer'],
[['srok', 'prioritet', 'data', 'name', 'email', 'phone', 'search'], 'safe'],
];
}
/**
* @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, $role)
{
$query = Zakaz::find();
switch ($role) {
case 'master':
$query->andWhere(['status' => Zakaz::STATUS_MASTER, 'action' => 1]);
$sort = ['srok' => SORT_ASC];
break;
case 'disain':
$query->andWhere(['status' => Zakaz::STATUS_DISAIN, 'action' => 1]);
$sort = ['srok' => SORT_ASC];
break;
case 'shop':
$query->andWhere(['id_sotrud' => Yii::$app->user->id, 'action' => 1]);
$sort = ['data' => SORT_DESC];
break;
case 'admin':
$query->andWhere(['status' => [Zakaz::STATUS_DISAIN, Zakaz::STATUS_MASTER, Zakaz::STATUS_AUTSORS], 'action' => 1]);
$sort = ['srok' => SORT_DESC];
break;
case 'archive':
$query->andWhere(['action' => 0]);
break;
case 'closeshop':
$query->andWhere(['id_sotrud' => Yii::$app->user->id, 'action' => 0]);
break;
}
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider([
'query' => $query,
'sort' => [
'defaultOrder' => $sort,
],
]);
$dataProvider->pagination = false;
$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;
}
// grid filtering conditions
$query->andFilterWhere([
'id_zakaz' => $this->id_zakaz,
'srok' => $this->srok,
'id_sotrud' => $this->id_sotrud,
'id_tovar' => $this->id_tovar,
'oplata' => $this->oplata,
'data' => $this->data,
// 'name' => $this->name,
'email' => $this->email,
]);
if (isset($model->search)) {
$query->orFilterWhere(['like', 'sotrud_name', $this->search])
->orFilterWhere(['like', 'description', $this->search])
->orFilterWhere(['like', 'information', $this->search])
->orFilterWhere(['like', 'name', $this->search]);
} else {
$query->andFilterWhere(['like', 'prioritet', $this->prioritet])
->andFilterWhere(['like', 'status', $this->status])
->andFilterWhere(['like', 'name', $this->name])
->andFilterWhere(['like', 'phone', $this->phone])
->andFilterWhere(['like', 'email', $this->email]);
}
return $dataProvider;
}
public function attributeLabels()
{
return [
'srok' => 'Срок',
'id_sotrud' => 'Магазин',
'name' => 'Имя клиента',
'status' => 'Этап',
'phone' => 'Телефон',
'data' => 'Дата принятия заказа',
'search' => 'Поиск',
];
}
}
public $search;
$query->orFilterWhere(['like', 'sotrud_name', $this->search])
->orFilterWhere(['like', 'description', $this->search])
->orFilterWhere(['like', 'information', $this->search])
->orFilterWhere(['like', 'name', $this->search]);
[
'attribute' => 'id_zakaz',
'format' => 'text',
'value' => 'idZakaz.description',
],
'value' => Courier::findOne('id_zakaz')->idZakaz->description,
class Courier extends \yii\db\ActiveRecord
{
public static function tableName()
{
return 'courier';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id_zakaz'], 'integer'],
[['data_to', 'data_from'], 'safe'],
[['commit'], 'string'],
[['to', 'from'], 'string', 'max' => 50],
[['id_zakaz'], 'exist', 'skipOnError' => true, 'targetClass' => Zakaz::className(), 'targetAttribute' => ['id_zakaz' => 'id_zakaz']],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'id_zakaz' => 'Id Zakaz',
'to' => 'To',
'data_to' => 'Data To',
'from' => 'From',
'data_from' => 'Data From',
'commit' => 'Commit',
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getIdZakaz()
{
return $this->hasOne(Zakaz::className(), ['id_zakaz' => 'id_zakaz']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getZakazs()
{
return $this->hasMany(Zakaz::className(), ['id_shipping' => 'id']);
}
public function rules()
{
return [
[['id_zakaz'], 'integer'],
[['data_to', 'data_from'], 'safe'],
[['commit'], 'string'],
[['to', 'from'], 'string', 'max' => 50],
[['id_zakaz'], 'exist', 'skipOnError' => true, 'targetClass' => Zakaz::className(), 'targetAttribute' => ['id_zakaz' => 'id_zakaz']],
];
}
public function getIdZakaz()
{
return $this->hasOne(Zakaz::className(), ['id_zakaz' => 'id_zakaz']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getZakazs()
{
return $this->hasMany(Zakaz::className(), ['id_shipping' => 'id']);
}
public function rules()
{
return [
[['srok', 'minut', 'number', 'description', 'phone'], 'required'],
[['id_zakaz', 'id_tovar', 'oplata', 'fact_oplata', 'number', 'status', 'action', 'id_sotrud', 'phone', 'id_shipping'], 'integer'],
[['srok', 'minut', 'data'], 'safe'],
[['comment'], 'string'],
[['prioritet'], 'string', 'max' => 36],
['status', 'default', 'value' => self::STATUS_NEW],
['id_sotrud', 'default', 'value' => Yii::$app->user->getId()],
['data', 'default', 'value' => date('Y-m-d')],
[['description', 'information'], 'string', 'max' => 500],
[['email', 'name', 'img', 'maket'],'string', 'max' => 50],
[['file'], 'file', 'skipOnEmpty' => true],
[['id_sotrud'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['id_sotrud' => 'id']],
[['id_tovar'], 'exist', 'skipOnError' => true, 'targetClass' => Tovar::className(), 'targetAttribute' => ['id_tovar' => 'id']],
[['id_shipping'], 'exist', 'skipOnError' => true, 'targetClass' => Courier::className(), 'targetAttribute' => ['id_shipping' => 'id']],
];
}
public function getIdShipping()
{
return $this->hasOne(Courier::className(), ['id' => 'id_shipping']);
}