-
Notifications
You must be signed in to change notification settings - Fork 0
/
DefaultController.php
95 lines (84 loc) · 3.39 KB
/
DefaultController.php
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
namespace AppBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
class DefaultController extends Controller
{
/**
* @Route("/", name="homepage")
*/
public function indexAction(Request $request)
{
$texts = $this->getDoctrine()
->getRepository('AppBundle:Text')
->findAll();
/*
return $this->render('FrontPage/index.html.twig', array(
'texts' => $texts,
));
*
*/
return $this->render('FrontPage/landing_page.html.twig');
}
/**
* @Route("/utils/subcategory/{parent}", name="get_subcategory")
*/
public function getSubcategory(Request $request, $parent) {
if($request->isXmlHttpRequest()) {
$repository = $this->getDoctrine()->getRepository("\AppBundle\Entity\Category");
$categories = $repository->findBy(array('parent' => $parent));
$a_categories = array_map(function($value) {
return array($value->getId(), $value->getName());
}, $categories);
return new JsonResponse(array(
'sub_categories' => $a_categories,
));
} else {
return $this->redirectToRoute('homepage');
}
}
/**
* Action which retrieves information associated with a sense
* @Route("/utils/data-by-sense/{id_sense}")
*/
public function getDataBySenseAction(Request $request, $id_sense) {
if($request->isXmlHttpRequest()) {
$sense = $this->getDoctrine()
->getRepository('AppBundle:Sense')
->find($id_sense);
$polarity = 0;
$a_categories = array();
$selected_parent = -1;
$selected_leaf = -1;
if($sense) {
$polarity = $sense->getScore();
$cats = $sense->getCategories();
if(count($cats) > 0) {
$category = $cats[0];
if($category->getParent()) {
$categories = $this->getDoctrine()
->getRepository("AppBundle:Category")
->findBy(array('parent' => $category->getParent()->getId()));
$a_categories = array_map(function($value) {
return array($value->getId(), $value->getName());
}, $categories);
$selected_leaf = $category->getId();
$selected_parent = $category->getParent()->getId();
} else {
$selected_parent = $category->getId();
}
}
}
return new JsonResponse(array(
'sub_categories' => $a_categories,
'polarity' => $polarity,
'selected_parent' => $selected_parent,
'selected_leaf' => $selected_leaf,
));
} else {
return $this->redirectToRoute('homepage');
}
}
}