|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file contains the code that powers the RfX Analysis page of XTools. |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace AppBundle\Controller; |
|
7
|
|
|
|
|
8
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
|
9
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
|
10
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
11
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
|
12
|
|
|
use Xtools\ProjectRepository; |
|
13
|
|
|
use Xtools\Page; |
|
14
|
|
|
use Xtools\PageRepository; |
|
15
|
|
|
use Xtools\UserRepository; |
|
16
|
|
|
use Xtools\RFX; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* This controller handles the RfX Analysis tool. |
|
20
|
|
|
*/ |
|
21
|
|
|
class RfXAnalysisController extends Controller |
|
22
|
|
|
{ |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Get the name of the tool's index route. |
|
26
|
|
|
* @return string |
|
27
|
|
|
* @codeCoverageIgnore |
|
28
|
|
|
*/ |
|
29
|
|
|
public function getIndexRoute() |
|
30
|
|
|
{ |
|
31
|
|
|
return 'RfXAnalysis'; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Renders the index page for the RfX Tool |
|
36
|
|
|
* |
|
37
|
|
|
* @param Request $request Given by Symfony |
|
38
|
|
|
* @param string $project Optional project. |
|
39
|
|
|
* @param string $type Optional RfX type |
|
40
|
|
|
* |
|
41
|
|
|
* @Route("/rfx", name="RfXAnalysis") |
|
42
|
|
|
* @Route("/rfx/", name="RfXAnalysisSlash") |
|
43
|
|
|
* @Route("/rfx/index.php", name="rfxAnalysisIndexPhp") |
|
44
|
|
|
* @Route("/rfx/{project}", name="rfxAnalysisProject") |
|
45
|
|
|
* @Route("/rfx/{project}/{type}", name="rfxAnalysisProjectType") |
|
46
|
|
|
* |
|
47
|
|
|
* @return Response|RedirectResponse |
|
|
|
|
|
|
48
|
|
|
*/ |
|
49
|
|
|
public function indexAction(Request $request, $project = null, $type = null) |
|
|
|
|
|
|
50
|
|
|
{ |
|
51
|
|
|
if ($request->get('projecttype') |
|
52
|
|
|
&& (strpos($request->get('projecttype'), '|') !== false) |
|
53
|
|
|
) { |
|
54
|
|
|
$projectType = explode('|', $request->get('projecttype'), 2); |
|
55
|
|
|
$projectQuery = $projectType[0]; |
|
56
|
|
|
$typeQuery = $projectType[1]; |
|
57
|
|
|
} else { |
|
58
|
|
|
$projectQuery = $request->get('project'); |
|
59
|
|
|
$typeQuery = $request->get('type'); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
$username = $request->get('username'); |
|
63
|
|
|
|
|
64
|
|
|
if ($projectQuery != '' && $typeQuery != '' && $username != '') { |
|
65
|
|
|
return $this->redirectToRoute( |
|
66
|
|
|
'rfxAnalysisResult', |
|
67
|
|
|
[ |
|
68
|
|
|
'project' => $projectQuery, |
|
69
|
|
|
'type' => $typeQuery, |
|
70
|
|
|
'username' => $username |
|
71
|
|
|
] |
|
72
|
|
|
); |
|
73
|
|
|
} elseif ($projectQuery != '' && $typeQuery != '') { |
|
74
|
|
|
return $this->redirectToRoute( |
|
75
|
|
|
'rfxAnalysisProjectType', |
|
76
|
|
|
[ |
|
77
|
|
|
'project' => $projectQuery, |
|
78
|
|
|
'type' => $typeQuery |
|
79
|
|
|
] |
|
80
|
|
|
); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
$rfx = $this->getParameter('rfx'); |
|
84
|
|
|
|
|
85
|
|
|
$projectFields = []; |
|
86
|
|
|
|
|
87
|
|
|
foreach (array_keys($rfx) as $row) { |
|
88
|
|
|
$projectFields[$row] = $rfx[$row]['pages']; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
// replace this example code with whatever you need |
|
92
|
|
|
return $this->render( |
|
93
|
|
|
'rfxAnalysis/index.html.twig', |
|
94
|
|
|
[ |
|
95
|
|
|
'xtPageTitle' => 'tool-rfx', |
|
96
|
|
|
'xtSubtitle' => 'tool-rfx-desc', |
|
97
|
|
|
'xtPage' => 'rfx', |
|
98
|
|
|
'project' => $projectQuery, |
|
99
|
|
|
'available' => $projectFields, |
|
100
|
|
|
] |
|
101
|
|
|
); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* Renders the output page for the RfX Tool |
|
106
|
|
|
* @Route("/rfx/{project}/{type}/{username}", name="rfxAnalysisResult") |
|
107
|
|
|
* @param string $project Optional project. |
|
108
|
|
|
* @param string $type Type of RfX we are processing. |
|
109
|
|
|
* @param string $username Username of the person we're analizing. |
|
110
|
|
|
* @return Response|RedirectResponse |
|
111
|
|
|
* @codeCoverageIgnore |
|
112
|
|
|
*/ |
|
113
|
|
|
public function resultAction($project, $type, $username) |
|
114
|
|
|
{ |
|
115
|
|
|
$projectData = ProjectRepository::getProject($project, $this->container); |
|
116
|
|
|
|
|
117
|
|
|
if (!$projectData->exists()) { |
|
118
|
|
|
$this->addFlash('notice', ['invalid-project', $project]); |
|
|
|
|
|
|
119
|
|
|
return $this->redirectToRoute('rfx'); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
$db = $projectData->getDatabaseName(); |
|
|
|
|
|
|
123
|
|
|
$domain = $projectData->getDomain(); |
|
124
|
|
|
|
|
125
|
|
|
if ($this->getParameter('rfx')[$domain] === null) { |
|
126
|
|
|
$this->addFlash('notice', ['invalid-project-cant-use', $project]); |
|
127
|
|
|
return $this->redirectToRoute('rfx'); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
// Construct the page name |
|
131
|
|
|
if (!isset($this->getParameter('rfx')[$domain]['pages'][$type])) { |
|
132
|
|
|
$pagename = ''; |
|
133
|
|
|
} else { |
|
134
|
|
|
$pagename = $this->getParameter('rfx')[$domain]['pages'][$type]; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
$user = UserRepository::getUser($username, $this->container); |
|
138
|
|
|
|
|
139
|
|
|
$pagename .= '/'.$user->getUsername(); |
|
140
|
|
|
$page = new Page($projectData, $pagename); |
|
141
|
|
|
$pageRepo = new PageRepository(); |
|
142
|
|
|
$pageRepo->setContainer($this->container); |
|
143
|
|
|
$page->setRepository($pageRepo); |
|
144
|
|
|
|
|
145
|
|
|
$text = $page->getWikitext(); |
|
146
|
|
|
|
|
147
|
|
|
if (!isset($text)) { |
|
148
|
|
|
$this->addFlash('notice', ['no-result', $pagename]); |
|
149
|
|
|
return $this->redirectToRoute( |
|
150
|
|
|
'rfxAnalysisProject', |
|
151
|
|
|
[ |
|
152
|
|
|
'project' => $projectData->getDatabaseName() |
|
153
|
|
|
] |
|
154
|
|
|
); |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
$rfx = new RFX( |
|
158
|
|
|
$text, |
|
159
|
|
|
$this->getParameter('rfx')[$domain]['sections'], |
|
160
|
|
|
'User' |
|
161
|
|
|
); |
|
162
|
|
|
$support = $rfx->getSection('support'); |
|
163
|
|
|
$oppose = $rfx->getSection('oppose'); |
|
164
|
|
|
$neutral = $rfx->getSection('neutral'); |
|
165
|
|
|
$dup = $rfx->getDuplicates(); |
|
166
|
|
|
|
|
167
|
|
|
$total = count($support) + count($oppose) + count($neutral); |
|
168
|
|
|
|
|
169
|
|
|
if ($total === 0) { |
|
170
|
|
|
$this->addFlash('notice', ['no-result', $pagename]); |
|
171
|
|
|
return $this->redirectToRoute( |
|
172
|
|
|
'rfxAnalysisProject', |
|
173
|
|
|
[ |
|
174
|
|
|
'project' => $projectData->getDatabaseName(), |
|
175
|
|
|
] |
|
176
|
|
|
); |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
$end = $rfx->getEndDate(); |
|
180
|
|
|
|
|
181
|
|
|
// replace this example code with whatever you need |
|
182
|
|
|
return $this->render( |
|
183
|
|
|
'rfxAnalysis/result.html.twig', |
|
184
|
|
|
[ |
|
185
|
|
|
'xtTitle' => $user->getUsername(), |
|
186
|
|
|
'xtPage' => 'rfx', |
|
187
|
|
|
'project' => $projectData, |
|
188
|
|
|
'user' => $user, |
|
189
|
|
|
'page' => $page, |
|
190
|
|
|
'type' => $type, |
|
191
|
|
|
'support' => $support, |
|
192
|
|
|
'oppose' => $oppose, |
|
193
|
|
|
'neutral' => $neutral, |
|
194
|
|
|
'total' => $total, |
|
195
|
|
|
'duplicates' => $dup, |
|
196
|
|
|
'enddate' => $end, |
|
197
|
|
|
] |
|
198
|
|
|
); |
|
199
|
|
|
} |
|
200
|
|
|
} |
|
201
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths