<?php

namespace KupShop\ElninoBundle\Util;

use Query\Operator;

class Sortiment
{
    protected $perfumesSections;

    public function getPerfumesSections()
    {
        if (is_null($this->perfumesSections)) {
            $id_sections = sqlFetchAll(sqlQueryBuilder()->select('id')
                ->from('sections')
                ->where(Operator::equals(['name' => translate('perfumes_category', 'elnino')])), ['id' => 'id']);

            $this->perfumesSections = $id_sections;

            foreach ($id_sections as $id_section) {
                $descendants = getDescendantCategories($id_section);
                $this->perfumesSections = array_merge($this->perfumesSections, array_reverse($descendants, true));
            }
        }

        return $this->perfumesSections;
    }
}
