JuryRepository.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. namespace Entity\Repository;
  3. use Doctrine\ORM\EntityRepository;
  4. use Doctrine\Common\Collections\Criteria;
  5. use Doctrine\ORM\NoResultException;
  6. /**
  7. * JuryRepository
  8. *
  9. */
  10. class JuryRepository extends EntityRepository
  11. {
  12. /**
  13. * Get all users that are registered in the course. No matter the status
  14. *
  15. * @param \Entity\Course $course
  16. * @return \Entity\Jury
  17. */
  18. public function getJuryByPresidentId($userId)
  19. {
  20. $qb = $this->createQueryBuilder('a');
  21. //Selecting user info
  22. $qb->select('DISTINCT u');
  23. // Loading EntityUser
  24. $qb->from('Entity\Jury', 'u');
  25. // Selecting members
  26. $qb->innerJoin('u.members', 'c');
  27. // Inner join with the table c_quiz_question_rel_category.
  28. $qb->innerJoin('c.role', 'r');
  29. //@todo check app settings
  30. //$qb->add('orderBy', 'u.lastname ASC');
  31. $wherePart = $qb->expr()->andx();
  32. //Get only users subscribed to this course
  33. $wherePart->add($qb->expr()->eq('r.role', $qb->expr()->literal('ROLE_JURY_PRESIDENT')));
  34. $wherePart->add($qb->expr()->eq('c.userId', $userId));
  35. $qb->where($wherePart);
  36. $q = $qb->getQuery();
  37. try {
  38. return $q->getSingleResult();
  39. } catch (NoResultException $e) {
  40. return false;
  41. }
  42. }
  43. /**
  44. *
  45. * @param $userId
  46. * @return \Entity\Jury
  47. */
  48. public function getJuryByUserId($userId)
  49. {
  50. $qb = $this->createQueryBuilder('a');
  51. //Selecting user info
  52. $qb->select('DISTINCT u');
  53. // Loading EntityUser
  54. $qb->from('Entity\Jury', 'u');
  55. // Selecting members
  56. $qb->innerJoin('u.members', 'c');
  57. // Inner join with the table c_quiz_question_rel_category.
  58. $qb->innerJoin('c.role', 'r');
  59. //@todo check app settings
  60. //$qb->add('orderBy', 'u.lastname ASC');
  61. $wherePart = $qb->expr()->andx();
  62. //Get user
  63. $wherePart->add($qb->expr()->eq('c.userId', $userId));
  64. $qb->where($wherePart);
  65. $q = $qb->getQuery();
  66. try {
  67. return $q->getSingleResult();
  68. } catch (NoResultException $e) {
  69. return false;
  70. }
  71. }
  72. /**
  73. * @param int $juryId
  74. * @param array skip this roles
  75. *
  76. * @return bool|mixed
  77. */
  78. public function getStudentsByJury($juryId, $skipRoles = array())
  79. {
  80. $qb = $this->createQueryBuilder('a');
  81. //Selecting user info
  82. $qb->select('DISTINCT u');
  83. // Loading EntityUser
  84. $qb->from('Entity\Jury', 'u');
  85. // Selecting members
  86. $qb->innerJoin('u.members', 'c');
  87. // Inner join with the table c_quiz_question_rel_category.
  88. $qb->innerJoin('c.role', 'r');
  89. $qb->innerJoin('c.students', 's');
  90. //@todo check app settings
  91. //$qb->add('orderBy', 'u.lastname ASC');
  92. $wherePart = $qb->expr()->andx();
  93. // Get jury
  94. $wherePart->add($qb->expr()->eq('u.id', $juryId));
  95. if (!empty($skipRoles)) {
  96. foreach ($skipRoles as $role) {
  97. $wherePart->add($qb->expr()->neq('r.role', $qb->expr()->literal($role)));
  98. }
  99. }
  100. $qb->where($wherePart);
  101. $q = $qb->getQuery();
  102. try {
  103. return $q->getSingleResult();
  104. } catch (NoResultException $e) {
  105. return false;
  106. }
  107. }
  108. }