CourseRepository.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace Entity\Repository;
  3. use Doctrine\ORM\EntityRepository;
  4. use Doctrine\Common\Collections\Criteria;
  5. /**
  6. * CourseRepository
  7. *
  8. */
  9. class CourseRepository extends EntityRepository
  10. {
  11. /**
  12. * Get all users that are registered in the course. No matter the status
  13. *
  14. * @param \Entity\Course $course
  15. * @return \Doctrine\ORM\QueryBuilder
  16. */
  17. public function getSubscribedUsers(\Entity\Course $course)
  18. {
  19. $qb = $this->createQueryBuilder('a');
  20. //Selecting user info
  21. $qb->select('DISTINCT u');
  22. // Loading EntityUser
  23. $qb->from('Entity\User', 'u');
  24. //Selecting courses for users
  25. $qb->innerJoin('u.courses', 'c');
  26. //@todo check app settings
  27. $qb->add('orderBy', 'u.lastname ASC');
  28. $wherePart = $qb->expr()->andx();
  29. //Get only users subscribed to this course
  30. $wherePart->add($qb->expr()->eq('c.cId', $course->getId()));
  31. //$wherePart->add($qb->expr()->eq('c.status', $status));
  32. $qb->where($wherePart);
  33. //$q = $qb->getQuery();
  34. //return $q->execute();
  35. return $qb;
  36. }
  37. /**
  38. * Gets students subscribed in the course
  39. *
  40. * @param \Entity\Course $course
  41. *
  42. * @return \Doctrine\ORM\QueryBuilder
  43. */
  44. public function getSubscribedStudents(\Entity\Course $course)
  45. {
  46. $qb = $this->getSubscribedUsers($course);
  47. $wherePart = $qb->expr()->andx();
  48. $wherePart->add($qb->expr()->eq('c.status', STUDENT));
  49. return $qb;
  50. }
  51. /**
  52. * Gets the students subscribed in the course
  53. * @param \Entity\Course $course
  54. *
  55. * @return \Doctrine\ORM\QueryBuilder
  56. */
  57. public function getSubscribedCoaches(\Entity\Course $course)
  58. {
  59. $qb = $this->getSubscribedUsers($course);
  60. //Do something
  61. return $qb;
  62. }
  63. /**
  64. *
  65. * Gets the teachers subscribed in the course
  66. * @param \Entity\Course $course
  67. *
  68. * @return \Doctrine\ORM\QueryBuilder
  69. */
  70. public function getSubscribedTeachers(\Entity\Course $course)
  71. {
  72. $qb = $this->getSubscribedUsers($course);
  73. $wherePart = $qb->expr()->andx();
  74. $wherePart->add($qb->expr()->eq('c.status', COURSEMANAGER));
  75. return $qb;
  76. }
  77. }