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') ]; } }