<commit_before><?php
namespace Ilios\CoreBundle\Entity\Repository;

use Doctrine\ORM\EntityRepository;

/**
 * Class InstructorGroupRepository
 * @package Ilios\CoreBundle\Entity\Repository
 */
class InstructorGroupRepository extends EntityRepository
{
    /**
     * @inheritdoc
     */
    public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
    {
        $qb = $this->_em->createQueryBuilder();


        $qb->select('DISTINCT i')->from('IliosCoreBundle:InstructorGroup', 'i');

        if (empty($orderBy)) {
            $orderBy = ['id' => 'ASC'];
        }

        if (is_array($orderBy)) {
            foreach ($orderBy as $sort => $order) {
                $qb->addOrderBy('i.'.$sort, $order);
            }
        }

        if (array_key_exists('courses', $criteria)) {
            $ids = is_array($criteria['courses']) ? $criteria['courses'] : [$criteria['courses']];
            $qb->leftJoin('i.ilmSessions', 'ilm');
            $qb->leftJoin('i.offerings', 'offering');
            $qb->leftJoin('ilm.session', 'session');
            $qb->leftJoin('offering.session', 'session2');
            $qb->leftJoin('session.course', 'course');
            $qb->leftJoin('session2.course', 'course2');
            $qb->andWhere(
                $qb->expr()->orX(
                    $qb->expr()->in('course.id', ':courses'),
                    $qb->expr()->in('course2.id', ':courses')
                )
            );
            $qb->setParameter(':courses', $ids);
        }

        if (array_key_exists('sessions', $criteria)) {
            $ids = is_array($criteria['sessions']) ? $criteria['sessions'] : [$criteria['sessions']];
            $qb->leftJoin('i.ilmSessions', 'ilm');
            $qb->leftJoin('i.offerings', 'offering');
            $qb->leftJoin('ilm.session', 'session');
            $qb->leftJoin('offering.session', 'session2');
            $qb->andWhere(
                $qb->expr()->orX(
                    $qb->expr()->in('session.id', ':sessions'),
                    $qb->expr()->in('session2.id', ':sessions')
                )
            );
            $qb->setParameter(':sessions', $ids);
        }

        if (array_key_exists('sessionTypes', $criteria)) {
            $ids = is_array($criteria['sessionTypes']) ? $criteria['sessionTypes'] : [$criteria['sessionTypes']];
            $qb->leftJoin('i.ilmSessions', 'ilm');
            $qb->leftJoin('i.offerings', 'offering');
            $qb->leftJoin('ilm.session', 'session');
            $qb->leftJoin('offering.session', 'session2');
            $qb->leftJoin('session.sessionType', 'sessionType');
            $qb->leftJoin('session2.sessionType', 'sessionType2');
            $qb->andWhere(
                $qb->expr()->orX(
                    $qb->expr()->in('sessionType.id', ':sessionTypes'),
                    $qb->expr()->in('sessionType2.id', ':sessionTypes')
                )
            );
            $qb->setParameter(':sessionTypes', $ids);
        }

        if (array_key_exists('instructors', $criteria)) {
            $ids = is_array($criteria['instructors']) ? $criteria['instructors'] : [$criteria['instructors']];
            $qb->join('i.users', 'instructor');
            $qb->andWhere($qb->expr()->in('instructor.id', ':instructors'));
            $qb->setParameter(':instructors', $ids);
        }

        if (array_key_exists('learningMaterials', $criteria)) {
            $ids = is_array($criteria['learningMaterials'])
                ? $criteria['learningMaterials'] : [$criteria['learningMaterials']];
            $qb->leftJoin('i.ilmSessions', 'ilm');
            $qb->leftJoin('i.offerings', 'offering');
            $qb->leftJoin('ilm.session', 'session');
            $qb->leftJoin('offering.session', 'session2');
            $qb->leftJoin('session.learningMaterials', 'slm');
            $qb->leftJoin('session2.learningMaterials', 'slm2');
            $qb->andWhere(
                $qb->expr()->orX(
                    $qb->expr()->in('slm.id', ':learningMaterials'),
                    $qb->expr()->in('slm2.id', ':learningMaterials')
                )
            );
            $qb->setParameter(':learningMaterials', $ids);
        }

        if (array_key_exists('topics', $criteria)) {
            $ids = is_array($criteria['topics'])
                ? $criteria['topics'] : [$criteria['topics']];
            // @todo implement. [ST 2015/11/30]
        }

        unset($criteria['courses']);
        unset($criteria['sessions']);
        unset($criteria['sessionTypes']);
        unset($criteria['instructors']);
        unset($criteria['topics']);
        unset($criteria['learningMaterials']);<commit_msg>filter instructorgroups by topics.<commit_after><?php
namespace Ilios\CoreBundle\Entity\Repository;

use Doctrine\ORM\EntityRepository;

/**
 * Class InstructorGroupRepository
 * @package Ilios\CoreBundle\Entity\Repository
 */
class InstructorGroupRepository extends EntityRepository
{
    /**
     * @inheritdoc
     */
    public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
    {
        $qb = $this->_em->createQueryBuilder();


        $qb->select('DISTINCT i')->from('IliosCoreBundle:InstructorGroup', 'i');

        if (empty($orderBy)) {
            $orderBy = ['id' => 'ASC'];
        }

        if (is_array($orderBy)) {
            foreach ($orderBy as $sort => $order) {
                $qb->addOrderBy('i.'.$sort, $order);
            }
        }

        if (array_key_exists('courses', $criteria)) {
            $ids = is_array($criteria['courses']) ? $criteria['courses'] : [$criteria['courses']];
            $qb->leftJoin('i.ilmSessions', 'ilm');
            $qb->leftJoin('i.offerings', 'offering');
            $qb->leftJoin('ilm.session', 'session');
            $qb->leftJoin('offering.session', 'session2');
            $qb->leftJoin('session.course', 'course');
            $qb->leftJoin('session2.course', 'course2');
            $qb->andWhere(
                $qb->expr()->orX(
                    $qb->expr()->in('course.id', ':courses'),
                    $qb->expr()->in('course2.id', ':courses')
                )
            );
            $qb->setParameter(':courses', $ids);
        }

        if (array_key_exists('sessions', $criteria)) {
            $ids = is_array($criteria['sessions']) ? $criteria['sessions'] : [$criteria['sessions']];
            $qb->leftJoin('i.ilmSessions', 'ilm');
            $qb->leftJoin('i.offerings', 'offering');
            $qb->leftJoin('ilm.session', 'session');
            $qb->leftJoin('offering.session', 'session2');
            $qb->andWhere(
                $qb->expr()->orX(
                    $qb->expr()->in('session.id', ':sessions'),
                    $qb->expr()->in('session2.id', ':sessions')
                )
            );
            $qb->setParameter(':sessions', $ids);
        }

        if (array_key_exists('sessionTypes', $criteria)) {
            $ids = is_array($criteria['sessionTypes']) ? $criteria['sessionTypes'] : [$criteria['sessionTypes']];
            $qb->leftJoin('i.ilmSessions', 'ilm');
            $qb->leftJoin('i.offerings', 'offering');
            $qb->leftJoin('ilm.session', 'session');
            $qb->leftJoin('offering.session', 'session2');
            $qb->leftJoin('session.sessionType', 'sessionType');
            $qb->leftJoin('session2.sessionType', 'sessionType2');
            $qb->andWhere(
                $qb->expr()->orX(
                    $qb->expr()->in('sessionType.id', ':sessionTypes'),
                    $qb->expr()->in('sessionType2.id', ':sessionTypes')
                )
            );
            $qb->setParameter(':sessionTypes', $ids);
        }

        if (array_key_exists('instructors', $criteria)) {
            $ids = is_array($criteria['instructors']) ? $criteria['instructors'] : [$criteria['instructors']];
            $qb->join('i.users', 'instructor');
            $qb->andWhere($qb->expr()->in('instructor.id', ':instructors'));
            $qb->setParameter(':instructors', $ids);
        }

        if (array_key_exists('learningMaterials', $criteria)) {
            $ids = is_array($criteria['learningMaterials'])
                ? $criteria['learningMaterials'] : [$criteria['learningMaterials']];
            $qb->leftJoin('i.ilmSessions', 'ilm');
            $qb->leftJoin('i.offerings', 'offering');
            $qb->leftJoin('ilm.session', 'session');
            $qb->leftJoin('offering.session', 'session2');
            $qb->leftJoin('session.learningMaterials', 'slm');
            $qb->leftJoin('session2.learningMaterials', 'slm2');
            $qb->andWhere(
                $qb->expr()->orX(
                    $qb->expr()->in('slm.id', ':learningMaterials'),
                    $qb->expr()->in('slm2.id', ':learningMaterials')
                )
            );
            $qb->setParameter(':learningMaterials', $ids);
        }

        if (array_key_exists('topics', $criteria)) {
            $ids = is_array($criteria['topics'])
                ? $criteria['topics'] : [$criteria['topics']];
            $qb->leftJoin('i.ilmSessions', 'ilm');
            $qb->leftJoin('i.offerings', 'offering');
            $qb->leftJoin('ilm.session', 'session');
            $qb->leftJoin('offering.session', 'session2');
            $qb->leftJoin('session.topics', 'topic');
            $qb->leftJoin('session2.topics', 'topic2');
            $qb->andWhere(
                $qb->expr()->orX(
                    $qb->expr()->in('topic.id', ':topics'),
                    $qb->expr()->in('topic2.id', ':topics')
                )
            );
            $qb->setParameter(':topics', $ids);
        }

        unset($criteria['courses']);
        unset($criteria['sessions']);
        unset($criteria['sessionTypes']);
        unset($criteria['instructors']);
        unset($criteria['learningMaterials']);
        unset($criteria['topics']);
{'fraction_non_alphanumeric': 0.19787276740919124, 'fraction_numerical': 0.004013646397752358, 'mean_word_length': 2.1411913016073116, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 149, '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': '2144093', 'n_tokens_mistral': 3145, 'n_tokens_neox': 3024, 'n_words': 374}