-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathAbusController.php
More file actions
75 lines (62 loc) · 2.49 KB
/
AbusController.php
File metadata and controls
75 lines (62 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
namespace CTRV\CommonBundle\Controller;
use Doctrine\ORM\EntityRepository;
use Symfony\Component\HttpFoundation\Response;
use CTRV\CommonBundle\DependencyInjection\Constants;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use JMS\SecurityExtraBundle\Annotation\Secure;
use CTRV\CommonBundle\Entity\Abuse;
/**
* Abuse controller.
*
* @Route("/abuse")
*/
class AbusController extends Controller
{
/**
* @Route("/list",name="abuse")
* @Template()
* Retourne la liste de tous les Abus
*/
public function allAbuseAction(){
$currentCity = $this->get("session_service")->getCity();
$city = $this->getDoctrine()->getEntityManager()->getRepository('CTRVCommonBundle:City')->find($currentCity->getId());
if ($currentCity == null) {
$this->get('session')->getFlashBag()->add('error', $this->get('translator')->trans('session.city.not_found'));
$this->redirect($this->generateUrl("home"));
}
$page = intval ($this->getRequest()->get("page",1));
//pagination
$nb_entities = $abuses = $this->getDoctrine()->getRepository('CTRVCommonBundle:Abuse')->getAllAbuseNumber($city);
$nb_entities_page = Constants::abuse_number_per_page;
$nb_pages = ceil($nb_entities/$nb_entities_page);
$offset = ($page-1) * $nb_entities_page;
$abusesPublicMessage = $this->getDoctrine()->getRepository("CTRVCommonBundle:Abuse")->getAllPublicMessageAbuses($city, $offset, $nb_entities_page);
$abusesComment = $this->getDoctrine()->getRepository("CTRVCommonBundle:Abuse")->getAllCommentAbuses($city, $offset, $nb_entities_page);
$abuses = $abusesPublicMessage;
$abuses = array_merge($abuses, $abusesComment );
return array (
'entities' => $abuses,
'nb_pages' => $nb_pages,
'page' => $page,
'nb_entities' => $nb_entities
);
}
/**
* Supprimer un abus
*
* @Route("/{id}/delete", name="abuse_delete" ) //requirements={"id" = "\d+"}
* @Method("POST")
* @Template()
*/
public function deleteAction($id) {
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('CTRVCommonBundle:Comment')->find($id);
$em->remove($entity);
$em->flush();
return new Response(json_encode(array('result'=>true)));
}
}