Files
register/marko_unpacked/marko/portal/models/OrderBooking.php
T
Admin Nasledstvo ac168868ee Initial import
2026-05-01 20:52:04 +03:00

115 lines
3.1 KiB
PHP

<?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 implements CartInterface
{
public function getEvent()
{
return $this->hasOne(Events::class, ['id' => 'event_id']);
}
public function getTicketType()
{
return $this->hasOne(PriceObject::class, ['id' => 'ticket_id']);
}
public function getCartKey()
{
return Cart::encodeKey('OrderBooking', $this->id);
}
public function setCart(CartModel $model)
{
$model->title = $this->{'description_' . \Yii::$app->language};;
$model->subTitle = Ts::get(176);
$model->description = $this->{'name_' . \Yii::$app->language};
$model->singlePrice = number_format($this->single_price, 2, '.', ' ') . ' лв.';
$model->price = $this->single_price;
$model->availableQuantity = 100;
if ($this->datetime)
$model->datetime = date_create($this->datetime)->format('d.m.Y H:i');
return $model;
}
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')
];
}
public function getOrder() {
return $this->hasOne(Order::class, ['id' => 'order_id']);
}
}