X-Git-Url: https://git.rapsys.eu/.gitweb.cgi/airbundle/blobdiff_plain/6176927836d9b190c78d59e1a986b3e7ee79e065..c49fd2c87a55bbd865ca22265e56255a0596c804:/Repository/UserRepository.php?ds=sidebyside diff --git a/Repository/UserRepository.php b/Repository/UserRepository.php index 8b490c4..8991bf4 100644 --- a/Repository/UserRepository.php +++ b/Repository/UserRepository.php @@ -102,22 +102,127 @@ class UserRepository extends \Doctrine\ORM\EntityRepository { } /** - * Find all user's pseudonym from session applications + * Find all applicant by session * - * @param $session The Session instance + * @param $session The Session */ - public function findAllPseudonymBySession($session) { + public function findAllApplicantBySession($session) { //Get entity manager $em = $this->getEntityManager(); //Fetch sessions $ret = $this->getEntityManager() - ->createQuery('SELECT u.id, u.pseudonym FROM RapsysAirBundle:Application a INNER JOIN RapsysAirBundle:User u WHERE u.id = a.user AND a.session = :session') + ->createQuery('SELECT u.id, u.pseudonym FROM RapsysAirBundle:Application a JOIN RapsysAirBundle:User u WITH u.id = a.user WHERE a.session = :session') ->setParameter('session', $session) ->getResult(); //Process result - $ret = array_column($ret, 'pseudonym', 'id'); + $ret = array_column($ret, 'id', 'pseudonym'); + + //Send result + return $ret; + } + + /** + * Find all organizer grouped by translated group + * + * @param $translator The TranslatorInterface instance + * @return array|null The organizer array or null + */ + public function findOrganizerGroupedByGroup(TranslatorInterface $translator) { + //Get entity manager + $em = $this->getEntityManager(); + + //Get quote strategy + $qs = $em->getConfiguration()->getQuoteStrategy(); + $dp = $em->getConnection()->getDatabasePlatform(); + + //Get quoted table names + //XXX: this allow to make this code table name independent + $tables = [ + 'RapsysAirBundle:GroupUser' => $qs->getJoinTableName($em->getClassMetadata('RapsysAirBundle:User')->getAssociationMapping('groups'), $em->getClassMetadata('RapsysAirBundle:User'), $dp), + 'RapsysAirBundle:Group' => $qs->getTableName($em->getClassMetadata('RapsysAirBundle:Group'), $dp), + 'RapsysAirBundle:User' => $qs->getTableName($em->getClassMetadata('RapsysAirBundle:User'), $dp), + //XXX: Set limit used to workaround mariadb subselect optimization + ':limit' => PHP_INT_MAX, + "\t" => '', + "\n" => ' ' + ]; + + //Set the request + $req = <<addScalarResult('id', 'id', 'integer') + ->addScalarResult('pseudonym', 'pseudonym', 'string') + ->addScalarResult('g_id', 'g_id', 'integer') + ->addScalarResult('g_title', 'g_title', 'string') + ->addIndexByScalar('id'); + + //Fetch result + $res = $em + ->createNativeQuery($req, $rsm) + ->getResult(); + + //Init return + $ret = []; + + //Process result + foreach($res as $data) { + //Get translated group + $group = $translator->trans($data['g_title']?:'User'); + + //Init group subarray + if (!isset($ret[$group])) { + $ret[$group] = []; + } + + //Set data + $ret[$group][$data['id']] = $data['pseudonym']; + } + + //Send result + return $ret; + + header('Content-Type: text/plain'); + var_dump($ret); + exit; + + //Get entity manager + $em = $this->getEntityManager(); + + //Fetch sessions + $ret = $this->getEntityManager() + ->createQuery('SELECT u.id, u.pseudonym, g.title FROM RapsysAirBundle:User u JOIN RapsysAirBundle:GroupUser gu WITH gu.user = u.id JOIN RapsysAirBundle:Group g WITH g.id = gu.group GROUP BY u.id ORDER BY g.id DESC') + ->getResult(); + + header('Content-Type: text/plain'); + var_dump($ret); + exit; + + //Process result + $ret = array_column($ret, 'id', 'pseudonym'); //Send result return $ret;