123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- <?php
- namespace Entity\Repository;
- use Doctrine\ORM\EntityRepository;
- use Doctrine\Common\Collections\Criteria;
- use Doctrine\ORM\NoResultException;
- /**
- * JuryRepository
- *
- */
- class JuryRepository extends EntityRepository
- {
- /**
- * Get all users that are registered in the course. No matter the status
- *
- * @param \Entity\Course $course
- * @return \Entity\Jury
- */
- public function getJuryByPresidentId($userId)
- {
- $qb = $this->createQueryBuilder('a');
- //Selecting user info
- $qb->select('DISTINCT u');
- // Loading EntityUser
- $qb->from('Entity\Jury', 'u');
- // Selecting members
- $qb->innerJoin('u.members', 'c');
- // Inner join with the table c_quiz_question_rel_category.
- $qb->innerJoin('c.role', 'r');
- //@todo check app settings
- //$qb->add('orderBy', 'u.lastname ASC');
- $wherePart = $qb->expr()->andx();
- //Get only users subscribed to this course
- $wherePart->add($qb->expr()->eq('r.role', $qb->expr()->literal('ROLE_JURY_PRESIDENT')));
- $wherePart->add($qb->expr()->eq('c.userId', $userId));
- $qb->where($wherePart);
- $q = $qb->getQuery();
- try {
- return $q->getSingleResult();
- } catch (NoResultException $e) {
- return false;
- }
- }
- /**
- *
- * @param $userId
- * @return \Entity\Jury
- */
- public function getJuryByUserId($userId)
- {
- $qb = $this->createQueryBuilder('a');
- //Selecting user info
- $qb->select('DISTINCT u');
- // Loading EntityUser
- $qb->from('Entity\Jury', 'u');
- // Selecting members
- $qb->innerJoin('u.members', 'c');
- // Inner join with the table c_quiz_question_rel_category.
- $qb->innerJoin('c.role', 'r');
- //@todo check app settings
- //$qb->add('orderBy', 'u.lastname ASC');
- $wherePart = $qb->expr()->andx();
- //Get user
- $wherePart->add($qb->expr()->eq('c.userId', $userId));
- $qb->where($wherePart);
- $q = $qb->getQuery();
- try {
- return $q->getSingleResult();
- } catch (NoResultException $e) {
- return false;
- }
- }
- /**
- * @param int $juryId
- * @param array skip this roles
- *
- * @return bool|mixed
- */
- public function getStudentsByJury($juryId, $skipRoles = array())
- {
- $qb = $this->createQueryBuilder('a');
- //Selecting user info
- $qb->select('DISTINCT u');
- // Loading EntityUser
- $qb->from('Entity\Jury', 'u');
- // Selecting members
- $qb->innerJoin('u.members', 'c');
- // Inner join with the table c_quiz_question_rel_category.
- $qb->innerJoin('c.role', 'r');
- $qb->innerJoin('c.students', 's');
- //@todo check app settings
- //$qb->add('orderBy', 'u.lastname ASC');
- $wherePart = $qb->expr()->andx();
- // Get jury
- $wherePart->add($qb->expr()->eq('u.id', $juryId));
- if (!empty($skipRoles)) {
- foreach ($skipRoles as $role) {
- $wherePart->add($qb->expr()->neq('r.role', $qb->expr()->literal($role)));
- }
- }
- $qb->where($wherePart);
- $q = $qb->getQuery();
- try {
- return $q->getSingleResult();
- } catch (NoResultException $e) {
- return false;
- }
- }
- }
|