| 
				
			 | 
			
			
				@@ -0,0 +1,83 @@ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				1
			 | 
			
			
				+<?php 
			 | 
		
	
		
			
			| 
				
			 | 
			
				2
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				3
			 | 
			
			
				+namespace Muzich\AdminBundle\Controller\Moderate_comment; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				4
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				5
			 | 
			
			
				+use Muzich\CoreBundle\lib\Controller as BaseController; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				6
			 | 
			
			
				+use Muzich\CoreBundle\Managers\CommentsManager; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				7
			 | 
			
			
				+use Symfony\Component\HttpFoundation\RedirectResponse; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				8
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				9
			 | 
			
			
				+class EditController extends BaseController 
			 | 
		
	
		
			
			| 
				
			 | 
			
				10
			 | 
			
			
				+{ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				11
			 | 
			
			
				+   
			 | 
		
	
		
			
			| 
				
			 | 
			
				12
			 | 
			
			
				+  protected function getElementContext($element_id) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				13
			 | 
			
			
				+  { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				14
			 | 
			
			
				+    $Element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element') 
			 | 
		
	
		
			
			| 
				
			 | 
			
				15
			 | 
			
			
				+      ->findOneById($element_id); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				16
			 | 
			
			
				+    if (!$Element) { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				17
			 | 
			
			
				+        throw new NotFoundHttpException("The Muzich\CoreBundle\Entity\Element with id $element_id can't be found"); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				18
			 | 
			
			
				+    } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				19
			 | 
			
			
				+    return $Element; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				20
			 | 
			
			
				+  } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				21
			 | 
			
			
				+   
			 | 
		
	
		
			
			| 
				
			 | 
			
				22
			 | 
			
			
				+  public function acceptAction($element_id, $date) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				23
			 | 
			
			
				+  { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				24
			 | 
			
			
				+    $element = $this->getElementContext($element_id);  
			 | 
		
	
		
			
			| 
				
			 | 
			
				25
			 | 
			
			
				+    $cm = new CommentsManager($element->getComments()); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				26
			 | 
			
			
				+    // On nettoie le commentaire et on récupère les ids des "signaleurs" 
			 | 
		
	
		
			
			| 
				
			 | 
			
				27
			 | 
			
			
				+    $ids = $cm->cleanAlertsOnComment($date); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				28
			 | 
			
			
				+    $element->setComments($cm->get()); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				29
			 | 
			
			
				+    $element->setCountCommentReport($cm->countCommentAlert()); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				30
			 | 
			
			
				+     
			 | 
		
	
		
			
			| 
				
			 | 
			
				31
			 | 
			
			
				+    $this->getDoctrine()->getEntityManager()->persist($element); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				32
			 | 
			
			
				+     
			 | 
		
	
		
			
			| 
				
			 | 
			
				33
			 | 
			
			
				+    // On récupère les user qui ont signalés ce commentaire 
			 | 
		
	
		
			
			| 
				
			 | 
			
				34
			 | 
			
			
				+    $users = $this->getDoctrine()->getEntityManager() 
			 | 
		
	
		
			
			| 
				
			 | 
			
				35
			 | 
			
			
				+      ->createQuery(' 
			 | 
		
	
		
			
			| 
				
			 | 
			
				36
			 | 
			
			
				+        SELECT u FROM MuzichCoreBundle:User u 
			 | 
		
	
		
			
			| 
				
			 | 
			
				37
			 | 
			
			
				+        WHERE u.id IN (:uids)' 
			 | 
		
	
		
			
			| 
				
			 | 
			
				38
			 | 
			
			
				+      ) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				39
			 | 
			
			
				+      ->setParameter('uids', $ids) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				40
			 | 
			
			
				+      ->getResult() 
			 | 
		
	
		
			
			| 
				
			 | 
			
				41
			 | 
			
			
				+    ; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				42
			 | 
			
			
				+     
			 | 
		
	
		
			
			| 
				
			 | 
			
				43
			 | 
			
			
				+    // Pour chacun on augmente le compteur de signalements inutiles 
			 | 
		
	
		
			
			| 
				
			 | 
			
				44
			 | 
			
			
				+    foreach ($users as $user) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				45
			 | 
			
			
				+    { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				46
			 | 
			
			
				+      $user->addBadReport(); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				47
			 | 
			
			
				+      $this->getDoctrine()->getEntityManager()->persist($user); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				48
			 | 
			
			
				+    } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				49
			 | 
			
			
				+     
			 | 
		
	
		
			
			| 
				
			 | 
			
				50
			 | 
			
			
				+    $this->getDoctrine()->getEntityManager()->flush(); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				51
			 | 
			
			
				+     
			 | 
		
	
		
			
			| 
				
			 | 
			
				52
			 | 
			
			
				+    $this->get('session')->setFlash('success', $this->get('translator')->trans("object.edit.success", array(), 'Admingenerator') ); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				53
			 | 
			
			
				+    return new RedirectResponse($this->generateUrl("Muzich_AdminBundle_Moderate_comment_list" )); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				54
			 | 
			
			
				+  } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				55
			 | 
			
			
				+   
			 | 
		
	
		
			
			| 
				
			 | 
			
				56
			 | 
			
			
				+  public function refuseAction($element_id, $date) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				57
			 | 
			
			
				+  { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				58
			 | 
			
			
				+    $element = $this->getElementContext($element_id);  
			 | 
		
	
		
			
			| 
				
			 | 
			
				59
			 | 
			
			
				+    $cm = new CommentsManager($element->getComments()); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				60
			 | 
			
			
				+    $comment = $cm->get($cm->getIndexWithDate($date)); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				61
			 | 
			
			
				+    // On supprime le commentaire 
			 | 
		
	
		
			
			| 
				
			 | 
			
				62
			 | 
			
			
				+    $cm->deleteWithDate($date); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				63
			 | 
			
			
				+    $element->setComments($cm->get()); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				64
			 | 
			
			
				+    $element->setCountCommentReport($cm->countCommentAlert()); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				65
			 | 
			
			
				+     
			 | 
		
	
		
			
			| 
				
			 | 
			
				66
			 | 
			
			
				+    // On récupère l'auteur du commentaire pour lui incrémenté son compteur 
			 | 
		
	
		
			
			| 
				
			 | 
			
				67
			 | 
			
			
				+    // de contenu modéré 
			 | 
		
	
		
			
			| 
				
			 | 
			
				68
			 | 
			
			
				+    $user = $this->getDoctrine()->getEntityManager()->getRepository('MuzichCoreBundle:User') 
			 | 
		
	
		
			
			| 
				
			 | 
			
				69
			 | 
			
			
				+      ->findOneBy(array( 
			 | 
		
	
		
			
			| 
				
			 | 
			
				70
			 | 
			
			
				+        'id' => $comment['u']['i'] 
			 | 
		
	
		
			
			| 
				
			 | 
			
				71
			 | 
			
			
				+      )); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				72
			 | 
			
			
				+     
			 | 
		
	
		
			
			| 
				
			 | 
			
				73
			 | 
			
			
				+    $user->addModeratedCommentCount(); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				74
			 | 
			
			
				+     
			 | 
		
	
		
			
			| 
				
			 | 
			
				75
			 | 
			
			
				+    $this->getDoctrine()->getEntityManager()->persist($user); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				76
			 | 
			
			
				+    $this->getDoctrine()->getEntityManager()->persist($element); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				77
			 | 
			
			
				+    $this->getDoctrine()->getEntityManager()->flush(); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				78
			 | 
			
			
				+     
			 | 
		
	
		
			
			| 
				
			 | 
			
				79
			 | 
			
			
				+    $this->get('session')->setFlash('success', $this->get('translator')->trans("object.edit.success", array(), 'Admingenerator') ); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				80
			 | 
			
			
				+    return new RedirectResponse($this->generateUrl("Muzich_AdminBundle_Moderate_comment_list" )); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				81
			 | 
			
			
				+  } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				82
			 | 
			
			
				+   
			 | 
		
	
		
			
			| 
				
			 | 
			
				83
			 | 
			
			
				+} 
			 |