insertTagParser = $insertTagParser; } protected function getResponse(Template $template, ModuleModel $model, Request $request): ?Response { $GLOBALS['TL_CSS']['vr_wa'] = 'bundles/vonrotenbergweinanlieferung/css/frontend.scss|static'; $arrData = $template->getData(); if (($ListPage = PageModel::findById($model->vr_wa_listPage)) !== null) { $arrData['listPageUrl'] = $ListPage->getFrontendUrl(); } // Get bookings if (($bookings = WeinanlieferungReservationModel::findBy("uid",FrontendUser::getInstance()->id,['order' => "(SELECT tl_vr_wa_slot.time FROM tl_vr_wa_slot WHERE tl_vr_wa_slot.id=tl_vr_wa_reservation.pid) ASC"])) !== null) { /** @var WeinanlieferungReservationModel $booking */ foreach ($bookings as $booking) { if (($Slot = $booking->getRelated('pid')) !== null) { $day = new Date($Slot->date); $arrSorten = []; $arrErnteart = []; if ($booking->sorten !== null) { foreach (explode(';', $booking->sorten) as $sorteLeseart) { list($sorte, $leseart) = explode(',', $sorteLeseart); $objSorte = WeinanlieferungRebsorteModel::findByPk($sorte); $objLeseart = WeinanlieferungLeseartModel::findByPk($leseart); $arrSorten[$objSorte->id . ',' . $objLeseart->id] = ($objSorte !== null ? $objSorte->title : '') . ' ' . ($objLeseart !== null ? $objLeseart->title : ''); } } $strStandort = ''; if (($Standort = $Slot->getRelated('pid')) !== null) { $strStandort = $Standort->title; } if ($booking->ernteart !== null) { foreach (explode(',', $booking->ernteart) as $ernteart) { $arrErnteart[] = $GLOBALS['TL_LANG']['REF']['wa_ernteart'][$ernteart] ?? $ernteart; } } $arrLage = []; if (($Lage = $booking->getRelated('lage')) !== null) { $arrLage = $Lage->fetchEach('title'); } // Compute unit display fields for frontend list $unitTitle = $GLOBALS['TL_LANG']['MSC']['wa_unit_base'] ?? 'Behälter'; $unitAmountDisplay = (int) $booking->behaelter; if (!empty($booking->unit_id) && (int)$booking->unit_id > 0) { $unitModel = \vonRotenberg\WeinanlieferungBundle\Model\WeinanlieferungUnitModel::findByPk((int)$booking->unit_id); if (null !== $unitModel) { $unitTitle = (string)$unitModel->title; } $unitAmountDisplay = (int) ($booking->unit_amount ?: 0); if ($unitAmountDisplay <= 0) { $mult = (int) ($unitModel ? $unitModel->multiplier : 0); $unitAmountDisplay = $mult > 0 ? max(1, (int) ($booking->behaelter / $mult)) : (int) $booking->behaelter; } } $arrData['days'][$day->dayBegin][] = array_merge($booking->row(), [ 'sorte' => $arrSorten, 'slot' => array_merge($Slot->row(),[ 'anmerkungen' => $Slot->anmerkungen ? StringUtil::substr(strip_tags($Slot->anmerkungen),110) : '', ]), 'standort' => $strStandort, 'ernteart' => $arrErnteart, 'lage' => $arrLage, 'unit_title' => $unitTitle, 'unit_amount_display' => $unitAmountDisplay, ]); } } } $template->setData($arrData); // Handle ajax if ($request->headers->get('VR-Ajax') == 'WaBookedModule') { throw new ResponseException(new Response($this->insertTagParser->replace($template->parse()))); } return $template->getResponse(); } }