EventElementComment.php 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace Muzich\CoreBundle\Propagator;
  3. use Muzich\CoreBundle\Propagator\EventPropagator;
  4. use Muzich\CoreBundle\Entity\Element;
  5. use Muzich\CoreBundle\Actions\User\Event as UserEventAction;
  6. use Muzich\CoreBundle\Entity\Event;
  7. /**
  8. * Description of EventElementScore
  9. *
  10. * @author bux
  11. */
  12. class EventElementComment extends EventPropagator
  13. {
  14. public function commentAdded(Element $element)
  15. {
  16. $em = $this->container->get('doctrine')->getEntityManager();
  17. try
  18. {
  19. $event = $em->createQuery(
  20. 'SELECT e FROM MuzichCoreBundle:Event e
  21. WHERE e.user = :uid AND e.type = :type'
  22. )->setParameters(array(
  23. 'uid' => $element->getOwner()->getId(),
  24. 'type' => Event::TYPE_COMMENT_ADDED_ELEMENT
  25. ))->getSingleResult()
  26. ;
  27. $new = false;
  28. }
  29. catch (\Doctrine\ORM\NoResultException $e)
  30. {
  31. $event = new Event();
  32. $new = true;
  33. }
  34. $uea = new UserEventAction($element->getOwner(), $event);
  35. if ($new)
  36. {
  37. $uea->createEvent(
  38. Event::TYPE_COMMENT_ADDED_ELEMENT,
  39. $element->getId()
  40. );
  41. }
  42. else
  43. {
  44. $uea->updateEvent($element->getId());
  45. }
  46. $em->persist($event);
  47. }
  48. }