fitness-web/frontend/models/ReceptionForm.php

94 lines
1.9 KiB
PHP

<?php
namespace frontend\models;
use Yii;
use yii\base\Model;
use common\models\Card;
use common\models\Customer;
use common\models\Ticket;
/**
* ContactForm is the model behind the contact form.
*/
class ReceptionForm extends Model
{
public $number;
public $card;
public $customer;
public $tickets;
/**
* @inheritdoc
*/
public function rules()
{
return [
[['number'], 'required'],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'verifyCode' => 'Verification Code',
];
}
public function readCard(){
$this->card = Card::findOne(['number' => $this->number]);
if ( $this->card != null ){
$this->customer = $this->card->customer;
$this->readValidTickets();
}
}
public function readValidTickets(){
$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;
}
}