|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by PhpStorm. |
|
4
|
|
|
* User: kate |
|
5
|
|
|
* Date: 17.02.16 |
|
6
|
|
|
* Time: 9:30 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace AppBundle\Controller; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
use AppBundle\MenuItem\RecursiveMenuItemIterator; |
|
13
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
14
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
|
15
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
|
16
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
17
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
18
|
|
|
use AppBundle\Entity\Cat as CategoryEntity; |
|
19
|
|
|
|
|
20
|
|
|
class SiteController extends Controller |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @Route("/", name="homepage") |
|
24
|
|
|
*/ |
|
25
|
|
|
public function indexAction(Request $request) |
|
26
|
|
|
{ |
|
27
|
|
|
return $this->render("AppBundle::site/index.html.twig"); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @Route("/menu", name="menu") |
|
32
|
|
|
*/ |
|
33
|
|
|
public function menuAction(Request $request) |
|
34
|
|
|
{ |
|
35
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
36
|
|
|
$categoryEntity = $em->getRepository('AppBundle\Entity\Category'); |
|
37
|
|
|
$categories = $categoryEntity->childrenHierarchy(); |
|
38
|
|
|
return $this->render("AppBundle::includes/menu.html.twig", ['links' => $categories]); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @Route("/tree", name="tree") |
|
43
|
|
|
*/ |
|
44
|
|
|
public function treeAction(Request $request) |
|
45
|
|
|
{ |
|
46
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
47
|
|
|
$repo = $em->getRepository('AppBundle\Entity\Category'); |
|
48
|
|
|
$query = $em |
|
49
|
|
|
->createQueryBuilder() |
|
50
|
|
|
->select('node') |
|
51
|
|
|
->from('AppBundle\Entity\Category', 'node') |
|
52
|
|
|
->orderBy('node.root, node.lft', 'ASC') |
|
53
|
|
|
->where('node.root = 1') |
|
54
|
|
|
->getQuery() |
|
55
|
|
|
; |
|
56
|
|
|
$options = array('decorate' => true); |
|
57
|
|
|
$tree = $repo->buildTree($query->getArrayResult(), $options); |
|
58
|
|
|
return $this->render("AppBundle::tree.html.twig", ['tree' => $tree]); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
} |