add default account to frontend
This commit is contained in:
70
frontend/models/AccountSearch.php
Normal file
70
frontend/models/AccountSearch.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\models;
|
||||
|
||||
use Yii;
|
||||
use yii\base\Model;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use common\models\Account;
|
||||
|
||||
/**
|
||||
* AccountSearch represents the model behind the search form about `common\models\Account`.
|
||||
*/
|
||||
class AccountSearch extends Account
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['id_account', 'status', 'type'], 'integer'],
|
||||
[['name', '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 = Account::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_account' => $this->id_account,
|
||||
'status' => $this->status,
|
||||
'type' => $this->type,
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
]);
|
||||
|
||||
$query->andFilterWhere(['like', 'name', $this->name]);
|
||||
|
||||
return $dataProvider;
|
||||
}
|
||||
}
|
||||
42
frontend/models/AccountSelect.php
Normal file
42
frontend/models/AccountSelect.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\models;
|
||||
|
||||
use Yii;
|
||||
use yii\base\Model;
|
||||
use common\models\Account;
|
||||
|
||||
/**
|
||||
* AccountSearch represents the model behind the search form about `common\models\Account`.
|
||||
*/
|
||||
class AccountSelect extends Model
|
||||
{
|
||||
|
||||
public $id_account;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['id_account', 'type'], 'integer'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function scenarios()
|
||||
{
|
||||
// bypass scenarios() implementation in the parent class
|
||||
return Model::scenarios();
|
||||
}
|
||||
|
||||
public function writeToSession(){
|
||||
$account = Account::findOne($this->id_account);
|
||||
Account::writeDefault($account);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -68,6 +68,15 @@ class CustomerCreate extends \common\models\Customer
|
||||
[['email'], 'string', 'max' => 255],
|
||||
[['email'], 'email' ],
|
||||
[['email'], 'unique' ],
|
||||
[['email'], 'required', 'when' => function($model) {
|
||||
return !isset( $model->email ) || empty($model->phone) ;
|
||||
} ,
|
||||
// 'enableClientValidation' => false,
|
||||
'whenClient' => "function (attribute, value) {
|
||||
return false;
|
||||
}",
|
||||
'message' => Yii::t('customer/frontend','E-mail or phone number required!')
|
||||
],
|
||||
|
||||
[['password_plain','password_repeat'], 'string', 'max' => 32],
|
||||
|
||||
@@ -80,13 +89,24 @@ class CustomerCreate extends \common\models\Customer
|
||||
|
||||
[['phone', 'tax_number', 'country'], 'string', 'max' => 20],
|
||||
|
||||
[['phone'], 'required', 'when' => function($model) {
|
||||
return !isset( $model->email ) || empty( $model->email ) ;
|
||||
} ,
|
||||
// 'enableClientValidation' => false,
|
||||
'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]
|
||||
[['city'], 'string', 'max' => 30],
|
||||
|
||||
// [['email','phone'], 'validateEmailOrPhoneRequired' ],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function validateCustomerCard($a,$p){
|
||||
$card = null;
|
||||
|
||||
|
||||
@@ -68,6 +68,16 @@ class CustomerUpdate extends \common\models\Customer
|
||||
[['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'],
|
||||
@@ -79,6 +89,15 @@ class CustomerUpdate extends \common\models\Customer
|
||||
|
||||
[['phone', 'tax_number', 'country'], 'string', 'max' => 20],
|
||||
|
||||
[['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]
|
||||
|
||||
@@ -53,6 +53,41 @@ class ReceptionForm extends Model
|
||||
$this->tickets = Ticket::readActive($this->card);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true , if card found without customer
|
||||
* */
|
||||
public function isFreeCard(){
|
||||
$result = isset($this->card) && !isset($this->customer);
|
||||
return $result;
|
||||
}
|
||||
/**
|
||||
* @return true , if card found with customer
|
||||
* */
|
||||
public function isCardWithCustomer(){
|
||||
$result = isset($this->card) && isset($this->customer);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true , if card and customer found with at least one valid tickets
|
||||
* */
|
||||
public function isCustomerWithTicket(){
|
||||
$result = false;
|
||||
if ( isset($this->card) && isset($this->customer) ){
|
||||
if ( isset($this->tickets) && count($this->tickets) > 0 ){
|
||||
$result = true;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true, if no card and customer found
|
||||
* */
|
||||
public function isInvalidNumber(){
|
||||
$result = !isset($this->card) && !isset($this->customer);
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user