AdminCommentsController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 2
Bugs 1 Features 1
Metric Value
wmc 3
c 2
b 1
f 1
lcom 1
cbo 7
dl 0
loc 34
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A gEm() 0 4 1
A deleteWithChildrenAction() 0 12 1
A deleteAction() 0 12 1
1
<?php
2
3
namespace Mykees\CommentBundle\Controller;
4
5
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6
use Symfony\Component\HttpFoundation\Request;
7
8
class AdminCommentsController extends Controller
9
{
10
	private function gEm()
11
	{
12
		return $this->getDoctrine()->getManager();
13
	}
14
15
	public function deleteWithChildrenAction($model, $model_id, $comment_id, Request $request)
16
	{
17
		$manager = $this->get('mykees.comment.query.manager');
18
		$comments = $manager->findCommentsByModelAndId($model, $model_id,true);
19
		$children_ids = $manager->getChildren($comments[$comment_id]);
20
21
		array_push($children_ids,$comment_id);
22
23
		$manager->deleteByCommentIds($children_ids);
24
25
		return $this->redirect($request->headers->get('referer'));
26
	}
27
28
29
	public function deleteAction($id, Request $request)
30
	{
31
		$class = $this->container->getParameter('mykees_comment.comment.class');
32
		$explose_class = explode('\\',$class);
33
		$repository = $explose_class[0].$explose_class[1].':'.$explose_class[3];
34
		$comment = $this->gEm()->getRepository($repository)->find($id);
35
36
		$this->gEm()->remove($comment);
37
		$this->gEm()->flush();
38
39
		return $this->redirect($request->headers->get('referer'));
40
	}
41
}
42