CurriculumItemRelUserRepository.php 1014 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace Entity\Repository;
  3. use Doctrine\ORM\EntityRepository;
  4. use Doctrine\Common\Collections\Criteria;
  5. /**
  6. * CurriculumItemRelUserRepository
  7. *
  8. */
  9. class CurriculumItemRelUserRepository extends EntityRepository
  10. {
  11. /**
  12. * Get all users that are registered in the course. No matter the status
  13. * @param \Entity\CurriculumItem $item
  14. * @param \Entity\User $user
  15. * @return bool
  16. */
  17. public function isAllowToInsert(\Entity\CurriculumItem $item, \Entity\User $user)
  18. {
  19. $max = $item->getMaxRepeat();
  20. $count = $this->createQueryBuilder('a')
  21. ->select('COUNT(a)')
  22. ->where('a.itemId = :itemId')
  23. ->andWhere('a.userId = :userId')
  24. ->setParameters(
  25. array(
  26. 'itemId' => $item->getId(),
  27. 'userId' => $user->getUserId()
  28. )
  29. )
  30. ->getQuery()
  31. ->getSingleScalarResult();
  32. return $count <= $max ? true : false;
  33. }
  34. }