EditController.php 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace Muzich\AdminBundle\Controller\Moderate_element;
  3. use Admingenerated\MuzichAdminBundle\BaseModerate_elementController\EditController as BaseEditController;
  4. use Muzich\CoreBundle\Propagator\EventElement;
  5. use Symfony\Component\HttpFoundation\RedirectResponse;
  6. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  7. class EditController extends BaseEditController
  8. {
  9. protected function getElementContext($pk)
  10. {
  11. $Element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
  12. ->findOneById($pk);
  13. if (!$Element) {
  14. throw new NotFoundHttpException("The Muzich\CoreBundle\Entity\Element with id $pk can't be found");
  15. }
  16. return $Element;
  17. }
  18. public function acceptAction($pk)
  19. {
  20. $element = $this->getElementContext($pk);
  21. $user_ids = $element->getReportIds();
  22. $element->setReportIds(null);
  23. $element->setCountReport(null);
  24. $this->getDoctrine()->getEntityManager()->persist($element);
  25. $users = $this->getDoctrine()->getEntityManager()
  26. ->createQuery('
  27. SELECT u FROM MuzichCoreBundle:User u
  28. WHERE u.id IN (:uids)'
  29. )
  30. ->setParameter('uids', $user_ids)
  31. ->getResult()
  32. ;
  33. foreach ($users as $user)
  34. {
  35. $user->addBadReport();
  36. $this->getDoctrine()->getEntityManager()->persist($user);
  37. }
  38. $this->getDoctrine()->getEntityManager()->flush();
  39. $this->get('session')->setFlash('success', $this->get('translator')->trans("object.edit.success", array(), 'Admingenerator') );
  40. return new RedirectResponse($this->generateUrl("Muzich_AdminBundle_Moderate_element_list" ));
  41. }
  42. public function refuseAction($pk)
  43. {
  44. $element = $this->getElementContext($pk);
  45. $event = new EventElement($this->container);
  46. $event->elementRemoved($element);
  47. $element->getOwner()->addModeratedElementCount();
  48. $this->getDoctrine()->getEntityManager()->persist($element->getOwner());
  49. $this->getDoctrine()->getEntityManager()->remove($element);
  50. $this->getDoctrine()->getEntityManager()->flush();
  51. $this->get('session')->setFlash('success', $this->get('translator')->trans("object.edit.success", array(), 'Admingenerator') );
  52. return new RedirectResponse($this->generateUrl("Muzich_AdminBundle_Moderate_element_list" ));
  53. }
  54. }