JuryMembersRepository.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 JuryMembersRepository extends EntityRepository
  11. {
  12. /**
  13. * @param int $userId
  14. * @param int $juryMemberId "id" field of the jury_members table
  15. * @return string
  16. */
  17. public function assignUserToJuryMember($userId, $juryMemberId)
  18. {
  19. $member = $this->find($juryMemberId);
  20. if ($member) {
  21. $criteria = array('userId' => $userId, 'juryMemberId'=> $juryMemberId);
  22. $em = $this->getEntityManager();
  23. $result = $em->getRepository('Entity\JuryMemberRelUser')->findOneBy($criteria);
  24. if (empty($result)) {
  25. $object = new \Entity\JuryMemberRelUser();
  26. $object->setMember($member);
  27. $object->setUserId($userId);
  28. $em->persist($object);
  29. $em->flush();
  30. return '1';
  31. }
  32. }
  33. return '0';
  34. }
  35. /**
  36. * @param int $userId
  37. * @param int $juryMemberId "id" field of the jury_members table
  38. * @return string
  39. */
  40. public function removeUserToJuryMember($userId, $juryMemberId)
  41. {
  42. $em = $this->getEntityManager();
  43. $member = $em->getRepository('Entity\JuryMembers')->find($juryMemberId);
  44. if ($member) {
  45. $criteria = array('userId' => $userId, 'juryMemberId'=> $juryMemberId);
  46. $result = $em->getRepository('Entity\JuryMemberRelUser')->findOneBy($criteria);
  47. if (!empty($result)) {
  48. $em->remove($result);
  49. $em->flush();
  50. return '1';
  51. }
  52. }
  53. return '0';
  54. }
  55. }