<?phpdeclare(strict_types=1);namespace Klaravik\Product\BasicData;use Klaravik\Model\ProductValue;use Klaravik\Translate\Trans;use stdClass;class RenderBasicProductData{ private Trans $trans; private stdClass $productObject; /** * @param Trans $trans * @param stdClass $productObject */ public function __construct(Trans $trans, stdClass $productObject) { $this->trans = $trans; $this->productObject = $productObject; } /** * @return array */ private function highLightMakeModel(): array { if (empty($this->productObject->fabrikat)) { $this->productObject->fabrikat = $this->trans->get('text_label_page-product_highlight-unknown'); } if (empty($this->productObject->model)) { $this->productObject->model = $this->trans->get('text_label_page-product_highlight-unknown'); } $productValueMake = (new ProductValue())->setValue($this->productObject->fabrikat); $productValueModel = (new ProductValue())->setValue($this->productObject->model); return [ $this->trans->get('text_label_page-product_highlight-model') => $productValueMake, $this->trans->get('text_label_productEditor_base_model') => $productValueModel ]; } /** * @param int $products_id * @param int $categories_id * @return string */ public function renderHtml(int $products_id, int $categories_id): array { $getProductBasicData = (new BasicProductData($this->trans))->getProductBasicData($products_id, $categories_id); $getProductBasicData['highLight'] = array_merge($this->highLightMakeModel(), $getProductBasicData['highLight']); $htmlOutput = ''; if (!empty($getProductBasicData['highLight'])) { $htmlOutput .= '<div class="object-information__highlight">'; foreach ($getProductBasicData['highLight'] as $productFieldValue => $basicDataModel) { $htmlOutput .= ' <div class="object-information__highlight-item"> <div class="object-information__highlight-key">'.$productFieldValue.':</div> <div class="object-information__highlight-value">'.$basicDataModel->getValue().'</div> </div>'; } $htmlOutput .= '</div>'; } if (!empty($getProductBasicData['basicData'])) { $htmlOutput .= ' <div class="object-information expander-script" data-expander="basicData"> <div class="expander-script__container">'; foreach ($getProductBasicData['basicData'] as $headLine => $headLineGroup) { if (empty($headLineGroup)) { continue; } $htmlOutput .= ' <div class="object-information"> <span class="object-information__title">'. $headLine .':</span> <div class="object-information__items">'; foreach ($headLineGroup as $basicDataName => $basicDataType) { foreach ($basicDataType as $basicDataModel) { $htmlOutput .= '<div class="object-information__item"> <span class="object-information__item-key">'.$basicDataName.'</span> <span class="object-information__item-value">'.$basicDataModel->getValue().'</span> </div>'; } } $htmlOutput .=' </div> </div>'; } $htmlOutput .= ' </div> <div class="expander-script__toggle button--primary button--outlined button--large" data-expander="basicData"> <span class="toggler-text">'. $this->trans->get("text_label_page-product_extra-vehicle-dropdown") .'</span> <span class="arrow-icon"><i class="ri-arrow-down-s-line"></i></span> </div> </div>'; } return [ 'htmlOutput' => $htmlOutput, 'loadingHelp' => $getProductBasicData['loadingHelp'], 'loadingHelpText' => $getProductBasicData['loadingHelpText'] ]; }}