Initial import
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\models;
|
||||
|
||||
use app\models\parsed\CartInterface;
|
||||
use app\models\parsed\CartModel;
|
||||
use app\services\Cart;
|
||||
use app\services\Formatter;
|
||||
use app\services\JWT;
|
||||
use Prophecy\Comparator\Factory;
|
||||
|
||||
/**
|
||||
* Class OrderBooking
|
||||
* @package app\models
|
||||
* @property $id
|
||||
* @property $datetime
|
||||
* @property $name_bg
|
||||
* @property $name_en
|
||||
* @property $description_bg
|
||||
* @property $description_en
|
||||
* @property $single_price
|
||||
* @property $tickets_count
|
||||
* @property $validated_count
|
||||
* @property $last_validation_time
|
||||
* @property $event_id
|
||||
* @property $ticket_id
|
||||
* @property \app\models\PriceObject $ticketType
|
||||
* @property $order_id
|
||||
* @property $cart_key
|
||||
* @property \app\models\Events $event
|
||||
* @property \app\models\Order $order
|
||||
*/
|
||||
class OrderBooking extends _Base
|
||||
{
|
||||
|
||||
public function getOrder() {
|
||||
return $this->hasOne(Order::class, ['id' => 'order_id']);
|
||||
}
|
||||
public function getEvent()
|
||||
{
|
||||
return $this->hasOne(Events::class, ['id' => 'event_id']);
|
||||
}
|
||||
|
||||
public function getTicketType()
|
||||
{
|
||||
return $this->hasOne(PriceObject::class, ['id' => 'ticket_id']);
|
||||
}
|
||||
|
||||
public function formatedHtmlDate()
|
||||
{
|
||||
if ($this->datetime)
|
||||
$datetime = date_create($this->datetime);
|
||||
return $datetime->format('d.m.Y H:i');
|
||||
}
|
||||
|
||||
public function getHashedId()
|
||||
{
|
||||
return 'qrnasledstvo_'.base64_encode('nasledsto-ticket_' . $this->id);
|
||||
}
|
||||
|
||||
public static function getBookingByHashId($hashId)
|
||||
{
|
||||
$idStr = base64_decode($hashId);
|
||||
$exp = explode('_', $idStr);
|
||||
$id = $exp[1] ?? null;
|
||||
if ($id) {
|
||||
$booking = OrderBooking::findOne($id);
|
||||
if ($booking)
|
||||
return $booking;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function responseData()
|
||||
{
|
||||
|
||||
$lg = \Yii::$app->language;
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'ticket_type' => $this->{'name_' . $lg},
|
||||
'event' => $this->event->title(),
|
||||
'event_img' => $this->event->image('16:11'),
|
||||
'single_price' => $this->single_price,
|
||||
'datetime' => $this->formatedHtmlDate(),
|
||||
'hashed_id' => $this->getHashedId(),
|
||||
'tickets_count' => $this->tickets_count,
|
||||
'validated' => $this->validated_count ?? 0,
|
||||
'to_validate' => $this->tickets_count - $this->validated_count,
|
||||
'last_validation_time' => date('d.m.Y H:i:s')
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user