<?php

namespace Query;

use Doctrine\DBAL\Connection;

class Parameter
{
    public static function inSections(array $sectionIds)
    {
        return function (QueryBuilder $qb) use ($sectionIds) {
            $qb->leftJoin('pa', 'parameters_sections', 'pas', 'pa.id = pas.id_parameter');
            $qb->setParameter('sectionIds', $sectionIds, Connection::PARAM_INT_ARRAY);

            return $qb->expr()->in('pas.id_section', ':sectionIds');
        };
    }

    public static function inProducers(array $producerIds)
    {
        return function (QueryBuilder $qb) use ($producerIds) {
            $qb->leftJoin('pa', 'parameters_producers', 'pap', 'pa.id = pap.id_parameter');
            $qb->setParameter('producerIds', $producerIds, Connection::PARAM_INT_ARRAY);

            return $qb->expr()->in('pap.id_producer', ':producerIds');
        };
    }
}
