<commit_before><?php

/**
 * This file is part of the ProductReview module for webcms2.
 * Copyright (c) @see LICENSE
 */

namespace FrontendModule\ProductreviewModule;

use Nette\Application\UI;
use Kdyby\BootstrapFormRenderer\BootstrapRenderer;
use WebCMS\ProductreviewModule\Entity\Product;
use WebCMS\ProductreviewModule\Entity\Accessoriescategory;
use WebCMS\ProductreviewModule\Entity\Accessory;

/**
 * Description of ToursPresenter
 *
 * @author <NAME> <<EMAIL>>
 */
class ProductsPresenter extends BasePresenter
{
    private $repository;

    private $product;

    private $products;

    private $accessories = array();

    private $accessoriescategory;

    private $accessoryRepository;

    private $accessoriescategoryRepository;
    
    protected function startup() 
    {
        parent::startup();

        $this->repository = $this->em->getRepository('WebCMS\ProductreviewModule\Entity\Product');
        $this->accessoriescategoryRepository = $this->em->getRepository('WebCMS\ProductreviewModule\Entity\Accessoriescategory');
        $this->accessoryRepository = $this->em->getRepository('WebCMS\ProductreviewModule\Entity\Accessory');
    }

    protected function beforeRender()
    {
        parent::beforeRender(); 
    }

    public function actionDefault($id)
    {
        $this->products = $this->repository->findBy(array(
            'page' => $this->actualPage
        ), array('productOrder' => 'ASC'));
        $this->accessoriescategory = $this->accessoriescategoryRepository->findBy(array(
            'page' => $this->actualPage
        ));

        $parameters = $this->getParameter();

        if (count($parameters['parameters']) > 0) {
            $slug = $parameters['parameters'][0];
            $this->product = $this->repository->findOneBy(array(
                'slug' => $slug
            ));

            $accessories = $this->product->getAccessories();

            foreach (explode(",", $accessories) as $accessory) {
                $this->accessories[] = $this->accessoryRepository->find($accessory);
            }
        }
    }

    public function renderDefault($id)
    {   
        if ($this->product) {
            $this->template->accessoriescategory = $this->accessoriescategory;
            $this->template->accessories = $this->accessories;
            $this->template->product = $this->product;

            $countOfCarouselPhotos = $this->em->getRepository('WebCMS\ProductreviewModule\Entity\Photo')->findBy(array(
                'product' => $this->product,
                'inCarousel' => 1<commit_msg>Added error handling if product doesn't exist<commit_after><?php

/**
 * This file is part of the ProductReview module for webcms2.
 * Copyright (c) @see LICENSE
 */

namespace FrontendModule\ProductreviewModule;

use Nette\Application\UI;
use Kdyby\BootstrapFormRenderer\BootstrapRenderer;
use WebCMS\ProductreviewModule\Entity\Product;
use WebCMS\ProductreviewModule\Entity\Accessoriescategory;
use WebCMS\ProductreviewModule\Entity\Accessory;

/**
 * Description of ToursPresenter
 *
 * @author <NAME> <<EMAIL>>
 */
class ProductsPresenter extends BasePresenter
{
    private $repository;

    private $product;

    private $products;

    private $accessories = array();

    private $accessoriescategory;

    private $accessoryRepository;

    private $accessoriescategoryRepository;
    
    protected function startup() 
    {
        parent::startup();

        $this->repository = $this->em->getRepository('WebCMS\ProductreviewModule\Entity\Product');
        $this->accessoriescategoryRepository = $this->em->getRepository('WebCMS\ProductreviewModule\Entity\Accessoriescategory');
        $this->accessoryRepository = $this->em->getRepository('WebCMS\ProductreviewModule\Entity\Accessory');
    }

    protected function beforeRender()
    {
        parent::beforeRender(); 
    }

    public function actionDefault($id)
    {
        $this->products = $this->repository->findBy(array(
            'page' => $this->actualPage
        ), array('productOrder' => 'ASC'));
        $this->accessoriescategory = $this->accessoriescategoryRepository->findBy(array(
            'page' => $this->actualPage
        ));

        $parameters = $this->getParameter();

        if (count($parameters['parameters']) > 0) {
            $slug = $parameters['parameters'][0];
            $this->product = $this->repository->findOneBy(array(
                'slug' => $slug
            ));

            if (!is_object($this->product))
                throw new \Nette\Application\BadRequestException();            

            $accessories = $this->product->getAccessories();

            foreach (explode(",", $accessories) as $accessory) {
                $this->accessories[] = $this->accessoryRepository->find($accessory);
            }
        }
    }

    public function renderDefault($id)
    {   
        if ($this->product) {
            $this->template->accessoriescategory = $this->accessoriescategory;
            $this->template->accessories = $this->accessories;
            $this->template->product = $this->product;

            $countOfCarouselPhotos = $this->em->getRepository('WebCMS\ProductreviewModule\Entity\Photo')->findBy(array(
                'product' => $this->product,
                'inCarousel' => 1
{'fraction_non_alphanumeric': 0.13493111907907152, 'fraction_numerical': 0.0015097188148707303, 'mean_word_length': 2.888481291269259, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 104, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5991964', 'n_tokens_mistral': 1448, 'n_tokens_neox': 1390, 'n_words': 242}