add city, customer and card model + crud
This commit is contained in:
88
backend/models/CardSearch.php
Normal file
88
backend/models/CardSearch.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace backend\models;
|
||||
|
||||
use Yii;
|
||||
use yii\base\Model;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use common\models\Card;
|
||||
use common\models\Customer;
|
||||
|
||||
/**
|
||||
* CardSearch represents the model behind the search form about `common\models\Card`.
|
||||
*/
|
||||
class CardSearch extends Card
|
||||
{
|
||||
|
||||
public $searchCustomerName;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['id_card', 'status', 'type'], 'integer'],
|
||||
[[ 'searchCustomerName', 'number', 'created_at', 'updated_at'], '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)
|
||||
{
|
||||
$query = Card::find();
|
||||
|
||||
$dataProvider = new ActiveDataProvider([
|
||||
'query' => $query,
|
||||
]);
|
||||
|
||||
$dataProvider->sort ->attributes['customerName'] =[
|
||||
'asc' => ['customer.name' => SORT_ASC ],
|
||||
'desc' => ['customer.name' => 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->leftJoin(Customer::tableName(), 'customer.id_customer_card = card.id_card');
|
||||
|
||||
$query->andFilterWhere([
|
||||
'card.status' => $this->status,
|
||||
'card.type' => $this->type,
|
||||
]);
|
||||
|
||||
$query->andFilterWhere(['like', 'card.number', $this->number]);
|
||||
$query->andFilterWhere(['like', 'customer.name', $this->searchCustomerName]);
|
||||
|
||||
return $dataProvider;
|
||||
}
|
||||
|
||||
public function attributeLabels(){
|
||||
$result = parent::attributeLabels();
|
||||
$result +=[
|
||||
'searchCustomerName' => Yii::t('common/card','Customer')
|
||||
];
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user