<?php

namespace AppBundle\Repository;

use Doctrine\ORM\EntityRepository;

/**
 * TraitCategoricalEntryRepository
 *
 * This class was generated by the PhpStorm "Php Annotations" Plugin. Add your own custom
 * repository methods below.
 */
class TraitCategoricalEntryRepository extends EntityRepository
{
    public function getNumber(): int
    {
        $query = $this->getEntityManager()->createQuery('SELECT COUNT(t.id) FROM AppBundle\Entity\TraitCategoricalEntry t WHERE t.deletionDate IS NULL ');
        return $query->getSingleScalarResult();
    }
}

<?php

namespace AppBundle\Repository;

use Doctrine\ORM\EntityRepository;

/**
 * TraitCategoricalEntryRepository
 *
 * This class was generated by the PhpStorm "Php Annotations" Plugin. Add your own custom
 * repository methods below.
 */
class TraitCategoricalEntryRepository extends EntityRepository
{
    public function getNumber(): int
    {
        $query = $this->getEntityManager()->createQuery('SELECT COUNT(t.id) FROM AppBundle\Entity\TraitCategoricalEntry t WHERE t.deletionDate IS NULL ');
        return $query->getSingleScalarResult();
    }

    public function getValues($trait_type_id, $fennec_ids){
        $qb = $this->getEntityManager()->createQueryBuilder();
        if($fennec_ids !== null){
            $qb->select('IDENTITY(t.fennec) AS id', 't.value')
                ->from('AppBundle\Entity\TraitNumericalEntry', 't')
                ->where('IDENTITY(t.traitType) = :trait_type_id')
                ->setParameter('trait_type_id', $trait_type_id)
                ->andWhere('t.deletionDate IS NOT NULL')
                ->add('where', $qb->expr()->in('t.fennec', $fennec_ids));
        } else {
            $qb->select('IDENTITY(t.fennec) AS id', 'value.value')
                ->from('AppBundle\Entity\TraitCategoricalEntry', 't')
                ->innerJoin('AppBundle\Entity\TraitCategoricalValue', 'value', 'WITH', 't.traitCategoricalValue = value.id')
                ->where('t.traitType = :trait_type_id')
                ->setParameter('trait_type_id', $trait_type_id)
                ->expr()->isNotNull('t.deletionDate');
        }
        $query = $qb->getQuery();
        $result = $query->getResult();

        $values = array();
        for($i=0;$i<sizeof($result);$i++) {
            if(!array_key_exists($result[$i]['value'], $values)){
                $values[$result[$i]['value']] = array();
            }
            $values[$result[$i]['value']][] = $result[$i]['id'];
        }

        foreach ($values as $key => $value){
            $values[$key] = array_values(array_unique($value));
        }
        return $values;
    }
}

Implement function for getting categorical trait values
Implement function for getting categorical trait values
