90 lines
2.2 KiB
PHP
90 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace frontend\models;
|
|
|
|
use common\components\Helper;
|
|
use common\models\MobileDevice;
|
|
use Yii;
|
|
use yii\base\Model;
|
|
use yii\data\ActiveDataProvider;
|
|
use yii\db\Query;
|
|
|
|
/**
|
|
* EventSearch represents the model behind the search form about `common\models\Event`.
|
|
*/
|
|
class MobileDeviceSearch extends MobileDevice
|
|
{
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
public function rules()
|
|
{
|
|
return [
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @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 = new Query();
|
|
|
|
$query->select([
|
|
'card.id_card as card_id',
|
|
'card.number as card_number',
|
|
'mobile_device.id as device_id',
|
|
'mobile_device.device_name as device_name',
|
|
'mobile_device.status as device_status',
|
|
'mobile_device.created_at as device_created_at',
|
|
]);
|
|
|
|
$query->from("mobile_device");
|
|
$query->innerJoin('customer', 'customer.id_customer_card = mobile_device.id_card');
|
|
$query->innerJoin('card', 'card.id_card = mobile_device.id_card');
|
|
$query->andWhere(['card.id_card' => $this->id_card]);
|
|
|
|
$dataProvider = new ActiveDataProvider([
|
|
'query' => $query,
|
|
'sort' => [
|
|
'defaultOrder' => [
|
|
'device_created_at' => SORT_DESC
|
|
],
|
|
'attributes' => Helper::mkYiiSortItems([
|
|
['device_created_at'],
|
|
['device_status'],
|
|
]),
|
|
]
|
|
]);
|
|
|
|
$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([
|
|
// 'event.id' => $this->id,
|
|
// ]);
|
|
|
|
return $dataProvider;
|
|
}
|
|
|
|
}
|