src/AtechNet/CoreBundle/Helper/Furbify/Module.php line 706

Open in your IDE?
  1. <?php
  2. namespace App\AtechNet\CoreBundle\Helper\Furbify;
  3. use App\AtechNet\CoreBundle\Entity\Basket;
  4. use App\AtechNet\CoreBundle\Entity\BlogPage;
  5. use App\AtechNet\CoreBundle\Entity\CategoryPage;
  6. use App\AtechNet\CoreBundle\Entity\Coupon;
  7. use App\AtechNet\CoreBundle\Entity\DomainPaymentType;
  8. use App\AtechNet\CoreBundle\Entity\DomainShippingType;
  9. use App\AtechNet\CoreBundle\Entity\Language;
  10. use App\AtechNet\CoreBundle\Entity\Product;
  11. use App\AtechNet\CoreBundle\Entity\Review;
  12. use App\AtechNet\CoreBundle\Enum\PaymentType;
  13. use Symfony\Component\Filesystem\Filesystem;
  14. use Symfony\Component\HttpFoundation\Request;
  15. use Twig\Environment;
  16. class Module
  17. {
  18.     public const CART_TIMEOUT = 2; // hours
  19.     private $url;
  20.     private $request;
  21.     private $translator;
  22.     private $internalTranslator;
  23.     private $multiStore;
  24.     private $productHelper;
  25.     private $cloudFlareApiConfig;
  26.     private $entityManager;
  27.     private $twig;
  28.     public function __construct($entityManager, Request $request, $productHelper, $cloudFlareApiConfig, $multiStore, $translator, $url, $internalTranslator, Environment $twig)
  29.     {
  30.         $this->url = $url;
  31.         $this->request = $request;
  32.         $this->translator = $translator;
  33.         $this->internalTranslator = $internalTranslator;
  34.         $this->multiStore = $multiStore;
  35.         $this->productHelper = $productHelper;
  36.         $this->cloudFlareApiConfig = $cloudFlareApiConfig;
  37.         $this->entityManager = $entityManager;
  38.         $this->twig = $twig;
  39.     }
  40.     /**
  41.      * @return string rendered view
  42.      * @throws \Exception
  43.      */
  44.     public function widgetCart(): string
  45.     {
  46.         $data = [];
  47.         $domain = $this->multiStore->getDomain();
  48.         $data['currency'] = $domain->getCurrency();
  49.         $data['precision'] = $domain->getPricePrecision();
  50.         $data['total'] = 0;
  51.         $data['subTotal'] = 0;
  52.         $data['items'] = [];
  53.         $data['countItems'] = 0;
  54.         $placeholder = $this->getImage('placeholder.jpg', '')->resize(Image::PRODUCT_CART_THUMB_WIDTH, Image::PRODUCT_CART_THUMB_HEIGHT);
  55.         $cart = $this->entityManager->getRepository(Basket::class)->findOneBy(
  56.             [
  57.                 'id' => $this->request->getSession()->get('cartId'),
  58.                 'active' => true,
  59.             ]
  60.         );
  61.         if ($cart) {
  62.             $expire = $cart->getUpdated()->add(new \DateInterval("PT" . self::CART_TIMEOUT . "H"));
  63.             if ($expire <= (new \DateTime('NOW'))) {
  64.                 $cart->setActive(false);
  65.                 $this->entityManager->flush();
  66.             } else {
  67.                 foreach ($cart->getBasketItems() as $item) {
  68.                     $product = $this->productHelper->getStructuredDataForProduct($item->getProduct(), 'cart');
  69.                     if ($product && !in_array($product['id'], [Product::CASH_ON_DELIVERY_PRODUCT_ID, Product::MPL_PACKAGE_FEE_PRODUCT_ID])) {
  70.                         $image = $placeholder;
  71.                         if (is_object($product['images'])) {
  72.                             $image = $this->getImage($product['images'], 'product/' . $product['code'])->resize(Image::PRODUCT_CART_THUMB_WIDTH, Image::PRODUCT_CART_THUMB_HEIGHT);
  73.                         }
  74.                         // Cross-sell Attribute Options
  75.                         $crossSellAttributeOptions = CartHelper::getCrossSellAttributeOptionsByProductTypeId($product['productTypeId'], $domain->getId());
  76.                         $options = [];
  77.                         $optionPrice = 0;
  78.                         foreach ($item->getItemAttributes() as $attribute) {
  79.                             $option = $attribute->getAttributeOption();
  80.                             $optionMeta = $option->getDomainMeta($domain);
  81.                             if ($optionMeta) {
  82.                                 $optionValue = $option->getLongTitle($this->translator);
  83.                                 if (!$optionValue) {
  84.                                     $optionValue = $option->getTitle($this->translator);
  85.                                 }
  86.                                 $optionTitle = $option->getAttribute()->getTitle();
  87.                                 if ($optionMeta->isDiscounted()) {
  88.                                     $price = $optionMeta->getDomainVatDiscount();
  89.                                 } else {
  90.                                     $price = $optionMeta->getDomainVatPrice();
  91.                                 }
  92.                                 $optionModel = $optionHref = '';
  93.                                 /** @var Product $optionProduct */
  94.                                 $optionProduct = $option->getProduct();
  95.                                 if ($optionProduct) {
  96.                                     $optionModel = $optionProduct->getCode();
  97.                                     $optionHref = $this->url->link('product', [
  98.                                         'product_id' => $optionProduct->getId(), 
  99.                                         'isBazaar'   => $optionProduct->isBazaar()
  100.                                     ]);
  101.                                 }
  102.                                 // If Attribute Option is for Cross-sell
  103.                                 if (isset($crossSellAttributeOptions[$option->getId()])) {
  104.                                     if (isset($crossSellAttributeOptions[$option->getId()]['percentPrice'])) {
  105.                                         $price = $domain->createVatPrice((($item->getPriceWithAttributesForDomainWithException($domain, $option) * $crossSellAttributeOptions[$option->getId()]['percentPrice']) / 100), 1.);
  106.                                     }
  107.                                 }
  108.                                 $options[] = [
  109.                                     'id' => $attribute->getId(),
  110.                                     'title' => $optionTitle,
  111.                                     'value' => $optionValue,
  112.                                     'price' => $price * $item->getQuantity(),
  113.                                     'model' => $optionModel,
  114.                                     'href' => $optionHref,
  115.                                 ];
  116.                                 $optionPrice += $price;
  117.                             }
  118.                         }
  119.                         if ($product['isDiscounted']) {
  120.                             $price = $product['discountVatPrice'];
  121.                         } else {
  122.                             $price = $product['vatPrice'];
  123.                         }
  124.                         $data['items'][] = [
  125.                             'id' => $item->getId(),
  126.                             'productId' => $product['id'],
  127.                             'model' => $product['code'],
  128.                             'name' => ($product['vendor'] !== '' ? $product['vendor'] . ' ' : '') . $product['title'],
  129.                             'image' => $image,
  130.                             'quantity' => $item->getQuantity(),
  131.                             'price' => $price * $item->getQuantity(),
  132.                             'options' => $options,
  133.                             'href' => $this->url->link('product', [
  134.                                 'product_id' => $product['id'],
  135.                                 'isBazaar'   => $product['isBazaar'] ?? 0
  136.                             ]),
  137.                         ];
  138.                         $data['subTotal'] += ($price + $optionPrice) * $item->getQuantity();
  139.                         $data['countItems'] += (int)$item->getQuantity();
  140.                     }
  141.                 }
  142.             }
  143.             $data['expire'] = $expire->format('Y-m-d H:i:s');
  144.         }
  145.         $data['estimation'] = true;
  146.         $data['coupon'] = '';
  147.         $data['paymentCost'] = $data['shippingCost'] = $data['discount'] = 0;
  148.         if ($this->request->getSession()->has('checkout')) {
  149.             $checkout = $this->request->getSession()->get('checkout');
  150.             if (isset($checkout['shippingMethodId']) && (int)$checkout['shippingMethodId'] > 0) {
  151.                 $shippingMethod = $this->entityManager->getRepository(DomainShippingType::class)->findOneBy([
  152.                     'id' => $checkout['shippingMethodId'],
  153.                     'domain' => $this->multiStore->getDomainId(),
  154.                 ]);
  155.                 if ($shippingMethod) {
  156.                     $data['shippingCost'] = ($shippingMethod->getFreeShipLimit() > $data['subTotal'] ? $shippingMethod->getPrice() : 0);
  157.                     $data['estimation'] = false;
  158.                 }
  159.             } else {
  160.                 $shippingMethodWithHighestPrice = CartHelper::getShippingMethodWithHighestPriceForDomain($domain, $this->entityManager);
  161.                 if ($shippingMethodWithHighestPrice) {
  162.                     $data['shippingCost'] = (float)($shippingMethodWithHighestPrice->getFreeShipLimit() > (float)$data['subTotal'] ? $shippingMethodWithHighestPrice->getPrice() : 0);
  163.                     $data['estimation'] = false;
  164.                 }
  165.             }
  166.             if (isset($checkout['paymentMethodId']) && (int)$checkout['paymentMethodId'] > 0) {
  167.                 $paymentMethod = $this->entityManager->getRepository(DomainPaymentType::class)->findOneBy([
  168.                     'id' => $checkout['paymentMethodId'],
  169.                     'domain' => $this->multiStore->getDomainId(),
  170.                 ]);
  171.                 if ($paymentMethod) {
  172.                     $data['paymentCost'] = $paymentMethod->getPrice();
  173.                 }
  174.             }
  175.             if (isset($checkout['coupon']['discount']) && (int)$checkout['coupon']['discount'] > 0) {
  176.                 $data['coupon'] = $checkout['coupon']['code'];
  177.                 $coupon = $this->entityManager->getRepository(Coupon::class)->findOneBy([
  178.                     'code' => $checkout['coupon']['code'],
  179.                     'domain' => $domain,
  180.                 ]);
  181.                 if ($coupon && $cart) {
  182.                     // Set Email
  183.                     if (!empty($checkout['email'])) {
  184.                         $cart->setEmail($checkout['email']);
  185.                     } else {
  186.                         $cart->setEmail(null);
  187.                     }
  188.                     $isCouponValidForBasket = CartHelper::isCouponValidForBasket($coupon, $cart, $this->entityManager);
  189.                     if ($isCouponValidForBasket) {
  190.                         $data['discount'] = $isCouponValidForBasket;
  191.                     }
  192.                 }
  193.             }
  194.             if (isset($checkout['3_percent_discount']) && $checkout['3_percent_discount']) {
  195.                 if ($cart) {
  196.                     $data['discount'] = CartHelper::getPercentDiscountForBasket($cart, 3);
  197.                     $data['three_percent_partner_discount'] = true;
  198.                 }
  199.             }
  200.             if (isset($checkout['paymentMethodTypeId']) && (int)$checkout['paymentMethodTypeId'] == PaymentType::CashOnDelivery->value) {
  201.                 $domainPaymentType = $this->entityManager->getRepository(DomainPaymentType::class)->findOneBy(
  202.                     [
  203.                         'domain' => $this->multiStore->getDomainId(),
  204.                         'type' => $checkout['paymentMethodTypeId'],
  205.                     ]
  206.                 );
  207.                 if ($domainPaymentType) {
  208.                     $data['cashOnDeliveryProductItem'] = [
  209.                         'title' => $this->translator->trans('Cash on delivery'),
  210.                         'price' => $domainPaymentType->getPrice(),
  211.                     ];
  212.                 }
  213.             }
  214.         } else {
  215.             $shippingMethodWithHighestPrice = CartHelper::getShippingMethodWithHighestPriceForDomain($domain, $this->entityManager);
  216.             if ($shippingMethodWithHighestPrice) {
  217.                 $data['shippingCost'] = ($shippingMethodWithHighestPrice->getFreeShipLimit() > $data['subTotal'] ? $shippingMethodWithHighestPrice->getPrice() : 0);
  218.                 $data['estimation'] = false;
  219.             }
  220.         }
  221.         $data['total'] = $data['subTotal'] + $data['shippingCost'] + $data['paymentCost'] - $data['discount'];
  222.         return $this->twig->render('AtechNetCoreBundle/Module/cart.html.twig', $data);
  223.     }
  224.     /**
  225.      * @return string rendered view
  226.      */
  227.     public function blockPopularLink(): string
  228.     {
  229.         $data = [];
  230.         $data['links'] = [];
  231.         if ($this->multiStore->getDomain()->getId() == 1) {
  232.             $data['links'][] = [
  233.                 'text' => $this->translator->trans('Computer monitor'),
  234.                 'href' => $this->url->link('category', [
  235.                     'path' => 6,
  236.                 ]),
  237.             ];
  238.         } else {
  239.             $data['links'][] = [
  240.                 'text' => $this->translator->trans('Computer monitor'),
  241.                 'href' => $this->url->link('category', [
  242.                     'path' => 78,
  243.                 ]),
  244.             ];
  245.         }
  246.         $data['links'][] = [
  247.             'text' => $this->translator->trans('For camera systems'),
  248.             'href' => $this->url->link('search', [
  249.                 'ft' => '60',
  250.             ]),
  251.         ];
  252.         $data['links'][] = [
  253.             'text' => 'HDMI Monitor',
  254.             'href' => $this->url->link('search', [
  255.                 'ft' => '44',
  256.             ]),
  257.         ];
  258.         $data['links'][] = [
  259.             'text' => $this->translator->trans('Used laptops'),
  260.             'href' => $this->url->link('search', [
  261.                 'ft' => '52',
  262.             ]),
  263.         ];
  264.         $data['links'][] = [
  265.             'text' => $this->translator->trans('User gamer computers'),
  266.             'href' => $this->url->link('search', [
  267.                 'ft' => '60,52',
  268.                 'fb' => 'gamer',
  269.             ]),
  270.         ];
  271.         $data['links'][] = [
  272.             'text' => $this->translator->trans('Complete computer'),
  273.             'href' => $this->url->link('search', [
  274.                 'ft' => '107',
  275.             ]),
  276.         ];
  277.         $data['links'][] = [
  278.             'text' => $this->translator->trans('Desktop PC full configuration'),
  279.             'href' => $this->url->link('search', [
  280.                 'ft' => '60',
  281.             ]),
  282.         ];
  283.         $data['links'][] = [
  284.             'text' => 'USB wifi',
  285.             'href' => $this->url->link('search', [
  286.                 'fa[105]' => '773',
  287.             ]),
  288.         ];
  289.         $data['links'][] = [
  290.             'text' => 'ddr 4gb',
  291.             'href' => $this->url->link('search', [
  292.                 'fa[3]' => ['74'],
  293.             ]),
  294.         ];
  295.         $data['links'][] = [
  296.             'text' => $this->translator->trans('With webcam'),
  297.             'href' => $this->url->link('search', [
  298.                 'fa[19]' => '571,574,763,1481',
  299.             ]),
  300.         ];
  301.         $data['links'][] = [
  302.             'text' => $this->translator->trans('For loan'),
  303.             'href' => $this->url->link('search', [
  304.                 'ft' => '60',
  305.             ]),
  306.         ];
  307.         $data['links'][] = [
  308.             'text' => $this->translator->trans('Power supply'),
  309.             'href' => $this->url->link('search', [
  310.                 'ft' => '65',
  311.             ]),
  312.         ];
  313.         $data['links'][] = [
  314.             'text' => $this->translator->trans('With touch display'),
  315.             'href' => $this->url->link('search', [
  316.                 'fa[139]' => '1295',
  317.             ]),
  318.         ];
  319.         if ($this->multiStore->getDomain()->getId() == 1) {
  320.             $data['links'][] = [
  321.                 'text' => $this->translator->trans('Renewed notebooks'),
  322.                 'href' => $this->url->link('category', [
  323.                     'path' => 5,
  324.                 ]), // HU 56
  325.             ];
  326.             $data['links'][] = [
  327.                 'text' => $this->translator->trans('Renewed PC'),
  328.                 'href' => $this->url->link('category', [
  329.                     'path' => 4,
  330.                 ]), // HU 48
  331.             ];
  332.             $data['links'][] = [
  333.                 'text' => $this->translator->trans('Notebook docking station'),
  334.                 'href' => $this->url->link('category', [
  335.                     'path' => 9,
  336.                 ]), // HU 46
  337.             ];
  338.         } else {
  339.             $data['links'][] = [
  340.                 'text' => $this->translator->trans('Renewed notebooks'),
  341.                 'href' => $this->url->link('category', [
  342.                     'path' => 56,
  343.                 ]), // HU 56
  344.             ];
  345.             $data['links'][] = [
  346.                 'text' => $this->translator->trans('Renewed PC'),
  347.                 'href' => $this->url->link('category', [
  348.                     'path' => 48,
  349.                 ]), // HU 48
  350.             ];
  351.             $data['links'][] = [
  352.                 'text' => $this->translator->trans('Notebook docking station'),
  353.                 'href' => $this->url->link('category', [
  354.                     'path' => 46,
  355.                 ]), // HU 46
  356.             ];
  357.         }
  358.         return $this->twig->render('AtechNetCoreBundle/Module/popularLink.html.twig', $data);
  359.     }
  360.     /**
  361.      * @param string $view
  362.      * @return string rendered view
  363.      */
  364.     public function blockTestimonial(string $view = 'full', $checkShowAtHomePage = false): string
  365.     {
  366.         $data = [];
  367.         $data['view'] = $view;
  368.         $data['testimonials'] = [];
  369.         $reviewCount = $this->testimonialCount();
  370.         $data['reviewCount'] = $reviewCount;
  371.         $multiStore = $this->multiStore;
  372.         $languageIds = [$multiStore->getDefaultLanguageId()];
  373.         if ($multiStore->getDefaultLanguageId() == Language::LANGUAGE_ID_CZ) {
  374.             $languageIds[] = Language::LANGUAGE_ID_SK;
  375.         } elseif ($multiStore->getDefaultLanguageId() == Language::LANGUAGE_ID_SK) {
  376.             $languageIds[] = Language::LANGUAGE_ID_CZ;
  377.         }
  378.         $reviews = $this->entityManager->createQuery("SELECT DISTINCT r
  379.                 FROM AtechNetCoreBundle:Review r
  380.                 LEFT JOIN r.surveyMedias surveyMedias
  381.                 WHERE r.language IN(:languageIds) AND r.type = :type AND r.approved = :approved AND surveyMedias IS NOT NULL AND surveyMedias.approved = 1" . ($checkShowAtHomePage ? " AND r.showAtHomepage = 1" : "") . "
  382.                 ORDER BY r.created DESC")
  383.             ->setParameters([
  384.                 'languageIds' => $languageIds,
  385.                 'type' => Review::TYPE_PRODUCT,
  386.                 'approved' => true,
  387.             ])
  388.             ->setMaxResults(5)
  389.             ->getResult()
  390.         ;
  391.         $fs = new Filesystem();
  392.         foreach ($reviews as $review) {
  393.             $key = $review->getName() . '-' . $review->getCreated()->format('YmdHi');
  394.             $text = mb_strlen($review->getText()) > 200 ? mb_substr($review->getText(), 0, 196) . ' ...' : $review->getText();
  395.             $data['testimonials'][$key] = [
  396.                 'name' => $review->getName(),
  397.                 'text' => $text,
  398.                 'rating' => $review->getStars(),
  399.                 'order' => $review->getOrder(),
  400.                 'created' => $review->getCreated(),
  401.                 'product' => $review->getProduct(),
  402.             ];
  403.             $data['testimonials'][$key]['images'] = [];
  404.             foreach ($review->getSurveyMedias() as $reviewSurveyMedia) {
  405.                 $surveyMedia = $reviewSurveyMedia->getSurveyMedia();
  406.                 if ($reviewSurveyMedia->isApproved() && !isset($data['testimonials'][$key]['images'][$surveyMedia->getId()]) && count($data['testimonials'][$key]['images']) < 1) {
  407.                     $thumbDirPath = 'storage/image/reviews/' . $review->getId() . '/thumbs';
  408.                     $popupDirPath = 'storage/image/reviews/' . $review->getId() . '/popup';
  409.                     $blockDirPath = 'storage/image/reviews/' . $review->getId() . '/block';
  410.                     $thumbPath = $thumbDirPath . '/' . $surveyMedia->getFilename();
  411.                     $popupPath = $popupDirPath . '/' . $surveyMedia->getFilename();
  412.                     $blockPath = $blockDirPath . '/' . $surveyMedia->getFilename();
  413.                     if (!$fs->exists($thumbDirPath)) {
  414.                         $fs->mkdir($thumbDirPath, 0755);
  415.                     }
  416.                     if (!$fs->exists($popupDirPath)) {
  417.                         $fs->mkdir($popupDirPath, 0755);
  418.                     }
  419.                     if (!$fs->exists($blockDirPath)) {
  420.                         $fs->mkdir($blockDirPath, 0755);
  421.                     }
  422.                     if (!$fs->exists($thumbPath)) {
  423.                         $resize = new ResizeImage($surveyMedia->getDirectory() . '/' . $surveyMedia->getFilename());
  424.                         $resize->resizeTo(Image::PRODUCT_VIEW_THUMB_WIDTH, Image::PRODUCT_VIEW_THUMB_HEIGHT, 'maxWidth');
  425.                         $resize->saveImage($thumbPath);
  426.                     }
  427.                     if (!$fs->exists($popupPath)) {
  428.                         $resize = new ResizeImage($surveyMedia->getDirectory() . '/' . $surveyMedia->getFilename());
  429.                         $resize->resizeTo(Image::PRODUCT_VIEW_POPUP_WIDTH, Image::PRODUCT_VIEW_POPUP_HEIGHT);
  430.                         $resize->saveImage($popupPath);
  431.                     }
  432.                     // Cloudflare Image
  433.                     $imagePath = $reviewSurveyMedia->getCdnUrl('ProductViewThumb');
  434.                     // Internal Image
  435.                     if ($imagePath == '' && !$fs->exists($blockPath)) {
  436.                         $resize = new ResizeImage($surveyMedia->getDirectory() . '/' . $surveyMedia->getFilename());
  437.                         $resize->resizeTo(Image::PRODUCT_VIEW_THUMB_WIDTH, Image::PRODUCT_VIEW_THUMB_HEIGHT, 'crop');
  438.                         $resize->saveImage($blockPath);
  439.                         $imagePath = '/' . $blockPath;
  440.                     } elseif ($imagePath == '') {
  441.                         $imagePath = '/' . $thumbPath;
  442.                     }
  443.                     $data['testimonials'][$key]['images'][$surveyMedia->getId()] = $imagePath;
  444.                 }
  445.             }
  446.         }
  447.         return $this->twig->render('AtechNetCoreBundle/Module/testimonial.html.twig', $data);
  448.     }
  449.     public function testimonialCount()
  450.     {
  451.         $multiStore = $this->multiStore;
  452.         $languageIds = [$multiStore->getDefaultLanguageId()];
  453.         if ($multiStore->getDefaultLanguageId() == Language::LANGUAGE_ID_CZ) {
  454.             $languageIds[] = Language::LANGUAGE_ID_SK;
  455.         } elseif ($multiStore->getDefaultLanguageId() == Language::LANGUAGE_ID_SK) {
  456.             $languageIds[] = Language::LANGUAGE_ID_CZ;
  457.         }
  458.         return $this->entityManager->createQuery("SELECT COUNT(r.id) 
  459.                 FROM AtechNetCoreBundle:Review r
  460.                 WHERE r.language IN(:language) AND r.type = :type AND r.approved = :approved")
  461.             ->setParameters([
  462.                 'language' => $languageIds,
  463.                 'type' => Review::TYPE_PRODUCT,
  464.                 'approved' => true,
  465.             ])
  466.             ->getSingleScalarResult()
  467.         ;
  468.     }
  469.     /**
  470.      * @return string rendered view
  471.      */
  472.     public function blockBlogCategory(): string
  473.     {
  474.         $data = [];
  475.         $domain = $this->multiStore->getDomain();
  476.         $language = $this->multiStore->getDefaultLanguage();
  477.         $blogCategoryId = 0;
  478.         if ($this->request->attributes->get('blogCategoryId')) {
  479.             $blogCategoryId = (int)$this->request->attributes->get('blogCategoryId');
  480.         } elseif ($this->request->attributes->get('blogId')) {
  481.             $blog = $this->entityManager->getRepository(BlogPage::class)->findOneById($this->request->attributes->get('blogId'));
  482.             if ($blog) {
  483.                 $blogCategory = $blog->getCategoryPage();
  484.                 if ($blogCategory) {
  485.                     $blogCategoryId = $blogCategory->getId();
  486.                 }
  487.             }
  488.         }
  489.         $data['categories'] = [];
  490.         $categories = $this->entityManager->getRepository(CategoryPage::class)->findBy([
  491.             'domain' => $domain->getId(),
  492.             'published' => 1,
  493.             'type' => CategoryPage::TYPE_BLOG,
  494.         ]);
  495.         foreach ($categories as $category) {
  496.             $meta = $category->getMetaByLanguage($language);
  497.             $blogCount = $this->entityManager->getRepository(BlogPage::class)->count([
  498.                 'categoryPage' => $category->getId(),
  499.             ]);
  500.             if ($meta && !in_array($meta->getTitle(), ['blog', 'BLOG']) && $blogCount > 0) {
  501.                 $data['categories'][] = [
  502.                     'id' => $category->getId(),
  503.                     'title' => $meta->getTitle(),
  504.                     'href' => $this->url->link('blog_category', [
  505.                         'blog_category_id' => $category->getId(),
  506.                     ]),
  507.                 ];
  508.             }
  509.         }
  510.         $data['blogCategoryId'] = $blogCategoryId;
  511.         return $this->twig->render('AtechNetCoreBundle/Module/blogCategory.html.twig', $data);
  512.     }
  513.     /**
  514.      * @return string rendered view
  515.      */
  516.     public function blockBlogTagCloud(): string
  517.     {
  518.         $domain = $this->multiStore->getDomain();
  519.         $connection = $this->entityManager->getConnection();
  520.         $tags = $connection->executeQuery("SELECT t.name, t.slug, COUNT(DISTINCT bp.blog_page_id ) AS total FROM pages_blog_tags AS bp JOIN tag AS t ON t.id = bp.tag_id WHERE t.language_id = ? GROUP BY t.name", [$domain->getLanguage()->getId()])->fetchAll();
  521.         if (!empty($tags)) {
  522.             $minimumCount = $maximumCount = false;
  523.             $minimumFontSize = 12;
  524.             $maximumFontSize = 24;
  525.             foreach ($tags as $tag) {
  526.                 if (!$minimumCount) {
  527.                     $minimumCount = (int)$tag['total'];
  528.                 } elseif ($minimumCount > (int)$tag['total']) {
  529.                     $minimumCount = (int)$tag['total'];
  530.                 }
  531.                 if (!$maximumCount) {
  532.                     $maximumCount = (int)$tag['total'];
  533.                 } elseif ($maximumCount < (int)$tag['total']) {
  534.                     $maximumCount = (int)$tag['total'];
  535.                 }
  536.             }
  537.             foreach ($tags as $index => $tag) {
  538.                 $tags[$index]['fontSize'] = (((int)$tag['total'] / (count($tags) - 1)) * ($maximumFontSize - $minimumFontSize)) + $minimumFontSize;
  539.             }
  540.         }
  541.         return $this->twig->render('AtechNetCoreBundle/Module/blogTagCloud.html.twig', [
  542.             'tags' => $tags,
  543.         ]);
  544.     }
  545.     /**
  546.      * @return string rendered view
  547.      */
  548.     public function blockBlogFeatured(?string $link): string
  549.     {
  550.         $data = [];
  551.         $domain = $this->multiStore->getDomain();
  552.         $language = $this->multiStore->getDefaultLanguage();
  553.         $blogs = $this->entityManager->getRepository(BlogPage::class)->getFeaturedBlogs($language);
  554.         if (count($blogs)) {
  555.             foreach ($blogs as $blog) {
  556.                 $blogMeta = $blog->getBlogPage()->getMetaByLanguage($language);
  557.                 $blogCategoryId = $blogMeta->getCategoryPage() && $blogMeta->getCategoryPage()->getId() > 0 ? $blogMeta->getCategoryPage()->getId() : $this->multiStore->getBlogCategoryIdByDomainId($domain->getId());
  558.                 $data['blogs'][] = [
  559.                     'id' => $blog->getBlogPage()->getId(),
  560.                     'title' => $blogMeta->getTitle(),
  561.                     'link' => $this->url->link('blog', [
  562.                         'blog_id' => $blog->getBlogPage()->getId(),
  563.                         'blog_category_id' => $blogCategoryId,
  564.                     ]),
  565.                     'active' => !is_null($link) && $blogMeta->getLink() == $link,
  566.                 ];
  567.             }
  568.             $data['featuredBlog'] = true;
  569.         }
  570.         return $this->twig->render('AtechNetCoreBundle/Module/blogFeatured.html.twig', $data);
  571.     }
  572.     /**
  573.      * @param object|string $photo
  574.      * @param string $directory
  575.      * @return Image
  576.      */
  577.     protected function getImage($photo, string $directory = 'product'): Image
  578.     {
  579.         return new Image($this->cloudFlareApiConfig, $photo, $directory);
  580.     }
  581. }