deleteWithChildrenAction()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 12
rs 9.4285
cc 1
eloc 7
nc 1
nop 4
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