user->getIdentity(); if (!isset($device)) { throw new NotFoundHttpException(); } $card = Card::findOne($device->id_card); if (!isset($card)) { throw new NotFoundHttpException(); } $customer = Customer::findOne(['id_customer_card' => $device->id_card]); if (!isset($customer)) { throw new NotFoundHttpException(); } $qrCode = new QrCode($card->number); return [ 'qrcode' => $qrCode->writeDataUri(), 'cardNumber' => $card->number, 'customerName' => $customer->name ]; } public function getTicketPage() { $device = Yii::$app->user->getIdentity(); if (!isset($device)) { throw new NotFoundHttpException(); } $card = Card::findOne($device->id_card); if (!isset($card)) { throw new NotFoundHttpException(); } $tickets = Ticket::readActive($card); $result = []; foreach ($tickets as $ticket) { $result[] = [ 'idTicket' => $ticket->id_ticket, 'type' => [ 'idType' => $ticket->ticketType->id_ticket_type, 'name' => $ticket->ticketType->name, ], 'usageCount' => $ticket->usage_count, 'start' => DateUtil::parseDateTime($ticket->start)->getTimestamp(), 'end' => DateUtil::parseDateTime($ticket->end)->getTimestamp() ]; } return [ 'tickets' => $result ]; } public function getVirtualKeyPage() { $device = Yii::$app->user->getIdentity(); if (!isset($device)) { throw new NotFoundHttpException(); } $card = Card::findOne($device->id_card); if (!isset($card)) { throw new NotFoundHttpException(); } $keyObject = null; try { $virtualKey = VirtualKey::findOne(['id_card' => $card->id_card]); if (!isset($virtualKey)) { throw new NotFoundHttpException(); } $key = Key::findOne(['id_key' => $virtualKey->id_key]); if (!isset($key)) { throw new NotFoundHttpException(); } $qrCode = new QrCode($virtualKey->number); $keyObject = [ 'qrcode' => $qrCode->writeDataUri(), 'createdAt' => $card->created_at, 'key' => $key->number, 'idKey' => $key->id_key ]; } catch (Exception $e) { // failed to get key Yii::error('Failed to get virtual key: ' . $e->getMessage()); } return [ 'key' => $keyObject ]; } public function getDashboardPage() { return [ 'virtual-key' => $this->getVirtualKeyPage(), 'card' => $this->getCardPage(), 'ticket' => $this->getTicketPage(), ]; } }