fitness-web/frontend/models/CustomerCreate.php

144 lines
4.1 KiB
PHP

<?php
namespace frontend\models;
use Yii;
use common\models\Customer;
use common\models\Card;
use common\components\Helper;
/**
* 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'], 'filter', 'filter' => function($value){return Helper::fixAsciiChars($value);}],
[['cardNumber'], 'validateCustomerCard' ],
[['partnerCardNumber'], 'string', 'max' => 10],
[['partnerCardNumber'], 'validatePartnerCard' ],
[['name'], 'required' ],
[['name'], 'string', 'max' => 128],
[['email'], 'string', 'max' => 255],
[['email'], 'email' ],
[['email'], 'unique' ],
[['email'], 'required', 'when' => function($model) {
return !isset( $model->email ) || empty($model->phone) ;
} ,
'whenClient' => "function (attribute, value) {
return false;
}",
'message' => Yii::t('customer/frontend','E-mail or phone number required!')
],
[['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],
[['bank_account'], 'string', 'max' => 24],
[['bank_name'], 'string', 'max' => 100],
[['phone'], 'required', 'when' => function($model) {
return !isset( $model->email ) || empty( $model->email ) ;
} ,
'whenClient' => "function (attribute, value) {
return false;
}",
'message' => Yii::t('customer/frontend','E-mail or phone number required!')
],
[['zip'], 'string', 'max' => 8],
[['city'], 'string', 'max' => 30],
[['photo_data'] ,'safe'],
[['birth_place'] ,'safe'],
[['mother_name'] ,'safe'],
// [['email','phone'], 'validateEmailOrPhoneRequired' ],
];
}
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;
}
}
}
}