add contract, add door_log
This commit is contained in:
147
backend/models/DoorLogSearch.php
Normal file
147
backend/models/DoorLogSearch.php
Normal file
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
|
||||
namespace backend\models;
|
||||
|
||||
use Yii;
|
||||
use yii\base\Model;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use common\models\DoorLog;
|
||||
|
||||
/**
|
||||
* DoorLogSearch represents the model behind the search form about `common\models\DoorLog`.
|
||||
*/
|
||||
class DoorLogSearch extends DoorLog
|
||||
{
|
||||
|
||||
|
||||
public $searchCardNumber;
|
||||
public $searchCustomerName;
|
||||
public $searchKeyName;
|
||||
|
||||
public $start;
|
||||
public $end;
|
||||
public $timestampStart;
|
||||
public $timestampEnd;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[[ 'direction', 'type'], 'integer'],
|
||||
[['created_at'], 'safe'],
|
||||
[['searchCardNumber','searchCustomerName','searchKeyName'], 'safe'],
|
||||
[[ 'start', ], 'date' , 'timestampAttribute' => 'timestampStart' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ],
|
||||
[[ 'end' , ], 'date' , 'timestampAttribute' => 'timestampEnd' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ],
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
public function attributeLabels(){
|
||||
return [
|
||||
'searchCardNumber' => 'Kártya szám',
|
||||
'searchCustomerName' => 'Vendég',
|
||||
'searchKeyName' => 'Kulcs szám',
|
||||
'type' => 'Típus',
|
||||
'direction' => 'Irány',
|
||||
'start' => 'Időszak kezdete',
|
||||
'end' => 'Időszak vége'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 = DoorLog::find();
|
||||
|
||||
$dataProvider = new ActiveDataProvider([
|
||||
'query' => $query,
|
||||
'sort' =>[
|
||||
'attributes' => [
|
||||
// 'age',
|
||||
'id_card' => [
|
||||
'asc' => ['card.number' => SORT_ASC ],
|
||||
'desc' => ['card.number' => SORT_DESC],
|
||||
],
|
||||
'id_key' => [
|
||||
'asc' => ['key.number' => SORT_ASC ],
|
||||
'desc' => ['key.number' => SORT_DESC],
|
||||
],
|
||||
'id_customer' => [
|
||||
'asc' => ['customer.name' => SORT_ASC ],
|
||||
'desc' => ['customer.name' => SORT_DESC],
|
||||
],
|
||||
'direction' => [
|
||||
'asc' => ['door_log.direction' => SORT_ASC ],
|
||||
'desc' => ['door_log.direction' => SORT_DESC],
|
||||
],
|
||||
'created_at' => [
|
||||
'asc' => ['door_log.created_at' => SORT_ASC ],
|
||||
'desc' => ['door_log.created_at' => SORT_DESC],
|
||||
],
|
||||
],
|
||||
]
|
||||
]);
|
||||
|
||||
$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([
|
||||
// 'id_door_log' => $this->id_door_log,
|
||||
// 'id_card' => $this->id_card,
|
||||
// 'id_customer' => $this->id_customer,
|
||||
// 'id_key' => $this->id_key,
|
||||
'direction' => $this->direction,
|
||||
// 'type' => $this->type,
|
||||
// 'created_at' => $this->created_at,
|
||||
]);
|
||||
|
||||
$query->andFilterWhere(['>=', 'door_log.created_at', $this->timestampStart]);
|
||||
$query->andFilterWhere(['<', 'door_log.created_at', $this->timestampEnd]);
|
||||
|
||||
$query->innerJoin('card','card.id_card = door_log.id_card');
|
||||
$query->leftJoin('key','key.id_key = door_log.id_key');
|
||||
$query->leftJoin('customer','customer.id_customer = door_log.id_customer');
|
||||
|
||||
if ( !empty($this->searchCardNumber)){
|
||||
$query->andWhere(['or',
|
||||
['and',[ 'in','card.number' , [$this->searchCardNumber]],"trim(coalesce(card.number, '')) <>'' " ],
|
||||
['and', ['in','card.rfid_key' ,[ $this->searchCardNumber] ],"trim(coalesce(card.rfid_key, '')) <>'' "],
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
if ( !empty($this->searchKeyName)){
|
||||
$query->andWhere(['or',
|
||||
['and',[ 'in','key.number' , [$this->searchKeyName]],"trim(coalesce(key.number, '')) <>'' " ],
|
||||
['and', ['in','key.rfid_key' ,[ $this->searchKeyName] ],"trim(coalesce(key.rfid_key, '')) <>'' "]
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
$query->andFilterWhere(['like', 'customer.name', $this->searchCustomerName]);
|
||||
|
||||
return $dataProvider;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user