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;
|
||||
}
|
||||
|
||||
}
|
||||
76
backend/models/CitySearch.php
Normal file
76
backend/models/CitySearch.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace backend\models;
|
||||
|
||||
use Yii;
|
||||
use yii\base\Model;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use common\models\City;
|
||||
|
||||
/**
|
||||
* CitySearch represents the model behind the search form about `common\models\City`.
|
||||
*/
|
||||
class CitySearch extends City
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['id_city', 'cso_code', 'rig_id', 'population', 'homes'], 'integer'],
|
||||
[['zip', 'name', 'city_code'], 'safe'],
|
||||
[['latitude', 'longitude', 'range'], 'number'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 = City::find();
|
||||
|
||||
$dataProvider = new ActiveDataProvider([
|
||||
'query' => $query,
|
||||
]);
|
||||
|
||||
$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_city' => $this->id_city,
|
||||
'latitude' => $this->latitude,
|
||||
'longitude' => $this->longitude,
|
||||
'cso_code' => $this->cso_code,
|
||||
'rig_id' => $this->rig_id,
|
||||
'range' => $this->range,
|
||||
'population' => $this->population,
|
||||
'homes' => $this->homes,
|
||||
]);
|
||||
|
||||
$query->andFilterWhere(['like', 'zip', $this->zip])
|
||||
->andFilterWhere(['like', 'name', $this->name])
|
||||
->andFilterWhere(['like', 'city_code', $this->city_code]);
|
||||
|
||||
return $dataProvider;
|
||||
}
|
||||
}
|
||||
117
backend/models/CustomerCreate.php
Normal file
117
backend/models/CustomerCreate.php
Normal file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
namespace backend\models;
|
||||
|
||||
use Yii;
|
||||
use common\models\Customer;
|
||||
use common\models\Card;
|
||||
|
||||
/**
|
||||
* This is the model class for table "customer".
|
||||
*
|
||||
* @property integer $id_customer
|
||||
* @property integer $id_customer_card
|
||||
* @property integer $id_user
|
||||
* @property integer $id_partner_card
|
||||
* @property integer $id_proposer
|
||||
* @property string $name
|
||||
* @property string $email
|
||||
* @property string $password
|
||||
* @property string $phone
|
||||
* @property integer $sex
|
||||
* @property string $date_stundent_card_expire
|
||||
* @property string $birthdate
|
||||
* @property string $image
|
||||
* @property string $description
|
||||
* @property string $tax_number
|
||||
* @property string $country
|
||||
* @property string $zip
|
||||
* @property string $city
|
||||
* @property string $address
|
||||
* @property string $created_at
|
||||
* @property string $updated_at
|
||||
* @property string $cardNumber
|
||||
*/
|
||||
class CustomerCreate extends \common\models\Customer
|
||||
{
|
||||
|
||||
public $cardNumber;
|
||||
public $partnerCardNumber;
|
||||
|
||||
public $password_plain;
|
||||
public $password_repeat;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return 'customer';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['cardNumber'], 'required' ],
|
||||
[['cardNumber'], 'string', 'max' => 10],
|
||||
[['cardNumber'], 'validateCustomerCard' ],
|
||||
|
||||
[['partnerCardNumber'], 'string', 'max' => 10],
|
||||
[['partnerCardNumber'], 'validatePartnerCard' ],
|
||||
|
||||
[['name'], 'required' ],
|
||||
[['name'], 'string', 'max' => 128],
|
||||
|
||||
[['email'], 'string', 'max' => 255],
|
||||
[['email'], 'email' ],
|
||||
[['email'], 'unique' ],
|
||||
|
||||
[['password_plain','password_repeat'], 'string', 'max' => 32],
|
||||
|
||||
[['sex'], 'integer'],
|
||||
|
||||
[[ 'birthdate', ], 'date' ],
|
||||
[[ 'date_stundent_card_expire', ], 'date' ],
|
||||
|
||||
[[ 'description', 'address'], 'string', 'max' => 255],
|
||||
|
||||
[['phone', 'tax_number', 'country'], 'string', 'max' => 20],
|
||||
|
||||
[['zip'], 'string', 'max' => 8],
|
||||
|
||||
[['city'], 'string', 'max' => 30]
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function validateCustomerCard($a,$p){
|
||||
$card = null;
|
||||
|
||||
if ( !empty($this->cardNumber)){
|
||||
$card = Card::readCard($this->cardNumber,true);
|
||||
}
|
||||
|
||||
if ( $card == null ){
|
||||
$this->addError($a,Yii::t('common/customer', "Bérlet kártya nem üres vagy hibás kártyaszám"));
|
||||
}else{
|
||||
$this->id_customer_card = $card->id_card;
|
||||
}
|
||||
|
||||
// $this->addError($a,Yii::t('common/customer', "Bérlet kártya nem üres vagy hibás kártyaszám"));
|
||||
}
|
||||
|
||||
public function validatePartnerCard($a,$p){
|
||||
if ( !empty($this->partnerCardNumber) ){
|
||||
$card = Card::readCard($this->partnerCardNumber,true);
|
||||
if ( $card == null ){
|
||||
$this->addError($a,Yii::t('common/customer', "Bérlet kártya nem üres vagy hibás kártyaszám"));
|
||||
}else{
|
||||
$this->id_partner_card = $card->id_card;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
96
backend/models/CustomerUpdate.php
Normal file
96
backend/models/CustomerUpdate.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace backend\models;
|
||||
|
||||
use Yii;
|
||||
use common\models\Customer;
|
||||
|
||||
/**
|
||||
* This is the model class for table "customer".
|
||||
*
|
||||
* @property integer $id_customer
|
||||
* @property integer $id_customer_card
|
||||
* @property integer $id_user
|
||||
* @property integer $id_partner_card
|
||||
* @property integer $id_proposer
|
||||
* @property string $name
|
||||
* @property string $email
|
||||
* @property string $password
|
||||
* @property string $phone
|
||||
* @property integer $sex
|
||||
* @property string $date_stundent_card_expire
|
||||
* @property string $birthdate
|
||||
* @property string $image
|
||||
* @property string $description
|
||||
* @property string $tax_number
|
||||
* @property string $country
|
||||
* @property string $zip
|
||||
* @property string $city
|
||||
* @property string $address
|
||||
* @property string $created_at
|
||||
* @property string $updated_at
|
||||
* @property string $cardNumber
|
||||
*/
|
||||
class CustomerUpdate extends \common\models\Customer
|
||||
{
|
||||
|
||||
public $cardNumber;
|
||||
public $partnerCardNumber;
|
||||
|
||||
public $password_plain;
|
||||
public $password_repeat;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return 'customer';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
// [['cardNumber'], 'required' ],
|
||||
// [['cardNumber'], 'string', 'max' => 10],
|
||||
// [['cardNumber'], 'validateCustomerCard' ],
|
||||
|
||||
[['partnerCardNumber'], 'string', 'max' => 10],
|
||||
[['partnerCardNumber'], 'validatePartnerCard' ],
|
||||
|
||||
[['name'], 'required' ],
|
||||
[['name'], 'string', 'max' => 128],
|
||||
|
||||
[['email'], 'string', 'max' => 255],
|
||||
[['email'], 'email' ],
|
||||
[['email'], 'unique' ],
|
||||
|
||||
[['password_plain','password_repeat'], 'string', 'max' => 32],
|
||||
|
||||
[['sex'], 'integer'],
|
||||
|
||||
[[ 'birthdate', ], 'date' ],
|
||||
[[ 'date_stundent_card_expire', ], 'date' ],
|
||||
|
||||
[[ 'description', 'address'], 'string', 'max' => 255],
|
||||
|
||||
[['phone', 'tax_number', 'country'], 'string', 'max' => 20],
|
||||
|
||||
[['zip'], 'string', 'max' => 8],
|
||||
|
||||
[['city'], 'string', 'max' => 30]
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function validateCustomerCard($a,$p){
|
||||
// Customer::find()->andWhere( [$this->cardNumber )
|
||||
}
|
||||
public function validatePartnerCard($a,$p){
|
||||
// Customer::find()->andWhere( [$this->cardNumber )
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user