<?php

namespace KupShop\ElninoBundle\Wrapper;

use KupShop\CatalogBundle\Entity\Section;
use Query\Operator;

class SectionWrapper extends \KupShop\CatalogBundle\Feed\Wrapper\SectionWrapper
{
    /**
     * Abra ID sekce.
     */
    public function field_abra_id()
    {
        if (!isset($this->sections->_abra)) {
            $IDs = [];
            /** @var Section $section */
            foreach ($this->sections as $section) {
                $IDs[] = $section->getId();
            }

            $qb = sqlQueryBuilder()->select('id_section', 'id_abra')
                ->from('abra_sections')
                ->where(Operator::inIntArray($IDs, 'id_section'));

            $this->sections->_abra = sqlFetchAll($qb, ['id_section' => 'id_abra']);
        }

        return $this->sections->_abra[$this->object->getId()] ?? null;
    }
}
