add city, customer and card model + crud
This commit is contained in:
117
backend/models/CustomerSearch.php
Normal file
117
backend/models/CustomerSearch.php
Normal file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
namespace backend\models;
|
||||
|
||||
use Yii;
|
||||
use yii\base\Model;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use common\models\Customer;
|
||||
use common\models\Card;
|
||||
|
||||
/**
|
||||
* CustomerSearch represents the model behind the search form about `common\models\Customer`.
|
||||
*/
|
||||
class CustomerSearch extends Customer
|
||||
{
|
||||
|
||||
public $cardNumber;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['cardNumber', 'name', 'email'] ,'safe']
|
||||
// [['id_customer', 'id_customer_card', 'id_user', 'id_partner_card', 'id_proposer', 'sex'], 'integer'],
|
||||
// [['name', 'email', 'password', 'phone', 'date_stundent_card_expire', 'birthdate', 'image', 'description', 'tax_number', 'country', 'zip', 'city', 'address', '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 = Customer::find();
|
||||
|
||||
$dataProvider = new ActiveDataProvider([
|
||||
'query' => $query,
|
||||
]);
|
||||
|
||||
$dataProvider->sort ->attributes['customerCardNumber'] =[
|
||||
'asc' => ['card.number' => SORT_ASC ],
|
||||
'desc' => ['card.number' => SORT_DESC ],
|
||||
];
|
||||
$dataProvider->sort->defaultOrder = [
|
||||
'name' => SORT_ASC,
|
||||
];
|
||||
|
||||
|
||||
// $dataProvider->setSort(
|
||||
|
||||
|
||||
// [
|
||||
// 'attributes' => [
|
||||
// 'id',
|
||||
// 'fullName' => [
|
||||
// 'asc' => ['first_name' => SORT_ASC, 'last_name' => SORT_ASC],
|
||||
// 'desc' => ['first_name' => SORT_DESC, 'last_name' => SORT_DESC],
|
||||
// 'label' => 'Full Name',
|
||||
// 'default' => SORT_ASC
|
||||
// ],
|
||||
// 'country_id'
|
||||
// ]
|
||||
// ]);
|
||||
|
||||
|
||||
$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(Card::tableName(), " customer.id_customer_card = card.id_card" );
|
||||
|
||||
// $query->andFilterWhere([
|
||||
// 'id_customer' => $this->id_customer,
|
||||
// 'id_customer_card' => $this->id_customer_card,
|
||||
// 'id_user' => $this->id_user,
|
||||
// 'id_partner_card' => $this->id_partner_card,
|
||||
// 'id_proposer' => $this->id_proposer,
|
||||
// 'sex' => $this->sex,
|
||||
// 'date_stundent_card_expire' => $this->date_stundent_card_expire,
|
||||
// 'birthdate' => $this->birthdate,
|
||||
// 'created_at' => $this->created_at,
|
||||
// 'updated_at' => $this->updated_at,
|
||||
// ]);
|
||||
|
||||
$query->andFilterWhere(['like', 'customer.name', $this->name])
|
||||
->andFilterWhere(['like', 'customer.email', $this->email])
|
||||
->andFilterWhere(['like', 'card.number', $this->cardNumber])
|
||||
->andFilterWhere(['like', 'address', $this->address]);
|
||||
|
||||
return $dataProvider;
|
||||
}
|
||||
|
||||
public function attributeLabels( ) {
|
||||
$labels = parent::attributeLabels();
|
||||
return $labels;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user