EditController.php 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace Muzich\AdminBundle\Controller\Moderate_tag;
  3. use Admingenerated\MuzichAdminBundle\BaseModerate_tagController\EditController as BaseEditController;
  4. use Muzich\CoreBundle\Managers\TagManager;
  5. use Symfony\Component\HttpFoundation\RedirectResponse;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  8. class EditController extends BaseEditController
  9. {
  10. protected function getTagContext($pk)
  11. {
  12. //$Tag = $this->getObject($pk); Error ?!
  13. $Tag = $tag = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneBy(array(
  14. 'id' => $pk,
  15. 'tomoderate' => true
  16. ));
  17. if (!$Tag) {
  18. throw new NotFoundHttpException("The Muzich\CoreBundle\Entity\Tag with id $pk can't be found");
  19. }
  20. return $Tag;
  21. }
  22. public function acceptAction($pk)
  23. {
  24. $tag = $this->getTagContext($pk);
  25. $tagManager = new TagManager();
  26. $tagManager->moderateTag($this->getDoctrine(), $tag, true);
  27. if (!$this->getRequest()->isXmlHttpRequest())
  28. {
  29. $this->get('session')->setFlash('success', $this->get('translator')->trans("object.edit.success", array(), 'Admingenerator') );
  30. return new RedirectResponse($this->generateUrl("Muzich_AdminBundle_Moderate_tag_list" ));
  31. }
  32. return $this->getJsonEmptyResponse();
  33. }
  34. protected function getJsonEmptyResponse()
  35. {
  36. $response = new Response(json_encode(array()));
  37. $response->headers->set('Content-Type', 'application/json; charset=utf-8');
  38. return $response;
  39. }
  40. public function refuseAction($pk)
  41. {
  42. $tag = $this->getTagContext($pk);
  43. $tagManager = new TagManager();
  44. $tagManager->moderateTag($this->getDoctrine(), $tag, false);
  45. $uids = json_decode($tag->getPrivateids(), true);
  46. $users = $this->getDoctrine()->getManager()
  47. ->createQuery('
  48. SELECT u FROM MuzichCoreBundle:User u
  49. WHERE u.id IN (:uids)'
  50. )
  51. ->setParameter('uids', $uids)
  52. ->getResult()
  53. ;
  54. foreach ($users as $user)
  55. {
  56. $user->addModeratedTagCount();
  57. $this->getDoctrine()->getManager()->persist($user);
  58. }
  59. $this->getDoctrine()->getManager()->flush();
  60. if (!$this->getRequest()->isXmlHttpRequest())
  61. {
  62. $this->get('session')->setFlash('success', $this->get('translator')->trans("object.edit.success", array(), 'Admingenerator') );
  63. return new RedirectResponse($this->generateUrl("Muzich_AdminBundle_Moderate_tag_list" ));
  64. }
  65. return $this->getJsonEmptyResponse();
  66. }
  67. }