EditController.php 2.2KB

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