Completed
Push — master ( 2fb092...058edd )
by Craig
06:38
created

RouteController::viewInternal()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 6
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Routes.
4
 *
5
 * @copyright Zikula contributors (Zikula)
6
 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
7
 * @author Zikula contributors <[email protected]>.
8
 * @link http://www.zikula.org
9
 * @link http://zikula.org
10
 * @version Generated by ModuleStudio 0.7.1 (http://modulestudio.de).
11
 */
12
13
namespace Zikula\RoutesModule\Controller;
14
15
use Zikula\RoutesModule\Controller\Base\AbstractRouteController;
16
17
use RuntimeException;
18
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
19
use Symfony\Component\HttpFoundation\Request;
20
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
21
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
22
use Zikula\ThemeModule\Engine\Annotation\Theme;
23
use Zikula\RoutesModule\Entity\RouteEntity;
24
25
/**
26
 * Route controller class providing navigation and interaction functionality.
27
 */
28
class RouteController extends AbstractRouteController
29
{
30
    /**
31
     * {@inheritdoc}
32
     *
33
     * @Route("/admin/routes",
34
     *        methods = {"GET"}
35
     * )
36
     * @Theme("admin")
37
     *
38
     * @param Request $request Current request instance
39
     *
40
     * @return Response Output
41
     *
42
     * @throws AccessDeniedException Thrown if the user doesn't have required permissions
43
     */
44
    public function adminIndexAction(Request $request)
45
    {
46
        return parent::adminIndexAction($request);
47
    }
48
    
49
    /**
50
     * {@inheritdoc}
51
     *
52
     * @Route("/routes",
53
     *        methods = {"GET"}
54
     * )
55
     *
56
     * @param Request $request Current request instance
57
     *
58
     * @return Response Output
59
     *
60
     * @throws AccessDeniedException Thrown if the user doesn't have required permissions
61
     */
62
    public function indexAction(Request $request)
63
    {
64
        return parent::indexAction($request);
65
    }
66
    /**
67
     * {@inheritdoc}
68
     *
69
     * @Route("/admin/routes/view/{sort}/{sortdir}/{pos}/{num}.{_format}",
70
     *        requirements = {"sortdir" = "asc|desc|ASC|DESC", "pos" = "\d+", "num" = "\d+", "_format" = "html|kml"},
71
     *        defaults = {"sort" = "", "sortdir" = "asc", "pos" = 1, "num" = 10, "_format" = "html"},
72
     *        methods = {"GET"}
73
     * )
74
     * @Theme("admin")
75
     *
76
     * @param Request $request Current request instance
77
     * @param string $sort         Sorting field
78
     * @param string $sortdir      Sorting direction
79
     * @param int    $pos          Current pager position
80
     * @param int    $num          Amount of entries to display
81
     *
82
     * @return Response Output
83
     *
84
     * @throws AccessDeniedException Thrown if the user doesn't have required permissions
85
     */
86
    public function adminViewAction(Request $request, $sort, $sortdir, $pos, $num)
87
    {
88
        return parent::adminViewAction($request, $sort, $sortdir, $pos, $num);
89
    }
90
    
91
    /**
92
     * {@inheritdoc}
93
     *
94
     * @Route("/routes/view/{sort}/{sortdir}/{pos}/{num}.{_format}",
95
     *        requirements = {"sortdir" = "asc|desc|ASC|DESC", "pos" = "\d+", "num" = "\d+", "_format" = "html|kml"},
96
     *        defaults = {"sort" = "", "sortdir" = "asc", "pos" = 1, "num" = 10, "_format" = "html"},
97
     *        methods = {"GET"}
98
     * )
99
     *
100
     * @param Request $request Current request instance
101
     * @param string $sort         Sorting field
102
     * @param string $sortdir      Sorting direction
103
     * @param int    $pos          Current pager position
104
     * @param int    $num          Amount of entries to display
105
     *
106
     * @return Response Output
107
     *
108
     * @throws AccessDeniedException Thrown if the user doesn't have required permissions
109
     */
110
    public function viewAction(Request $request, $sort, $sortdir, $pos, $num)
111
    {
112
        return parent::viewAction($request, $sort, $sortdir, $pos, $num);
113
    }
114
    /**
115
     * {@inheritdoc}
116
     *
117
     * @Route("/admin/route/{id}.{_format}",
118
     *        requirements = {"id" = "\d+", "_format" = "html|kml|ics"},
119
     *        defaults = {"_format" = "html"},
120
     *        methods = {"GET"}
121
     * )
122
     * @Theme("admin")
123
     *
124
     * @param Request $request Current request instance
125
     * @param RouteEntity $route Treated route instance
126
     *
127
     * @return Response Output
128
     *
129
     * @throws AccessDeniedException Thrown if the user doesn't have required permissions
130
     * @throws NotFoundHttpException Thrown by param converter if item to be displayed isn't found
131
     */
132
    public function adminDisplayAction(Request $request, RouteEntity $route)
133
    {
134
        return parent::adminDisplayAction($request, $route);
135
    }
136
    
137
    /**
138
     * {@inheritdoc}
139
     *
140
     * @Route("/route/{id}.{_format}",
141
     *        requirements = {"id" = "\d+", "_format" = "html|kml|ics"},
142
     *        defaults = {"_format" = "html"},
143
     *        methods = {"GET"}
144
     * )
145
     *
146
     * @param Request $request Current request instance
147
     * @param RouteEntity $route Treated route instance
148
     *
149
     * @return Response Output
150
     *
151
     * @throws AccessDeniedException Thrown if the user doesn't have required permissions
152
     * @throws NotFoundHttpException Thrown by param converter if item to be displayed isn't found
153
     */
154
    public function displayAction(Request $request, RouteEntity $route)
155
    {
156
        return parent::displayAction($request, $route);
157
    }
158
    /**
159
     * {@inheritdoc}
160
     *
161
     * @Route("/admin/route/edit/{id}.{_format}",
162
     *        requirements = {"id" = "\d+", "_format" = "html"},
163
     *        defaults = {"id" = "0", "_format" = "html"},
164
     *        methods = {"GET", "POST"}
165
     * )
166
     * @Theme("admin")
167
     *
168
     * @param Request $request Current request instance
169
     *
170
     * @return Response Output
171
     *
172
     * @throws AccessDeniedException Thrown if the user doesn't have required permissions
173
     * @throws NotFoundHttpException Thrown by form handler if item to be edited isn't found
174
     * @throws RuntimeException      Thrown if another critical error occurs (e.g. workflow actions not available)
175
     */
176
    public function adminEditAction(Request $request)
177
    {
178
        return parent::adminEditAction($request);
179
    }
180
    
181
    /**
182
     * {@inheritdoc}
183
     *
184
     * @Route("/route/edit/{id}.{_format}",
185
     *        requirements = {"id" = "\d+", "_format" = "html"},
186
     *        defaults = {"id" = "0", "_format" = "html"},
187
     *        methods = {"GET", "POST"}
188
     * )
189
     *
190
     * @param Request $request Current request instance
191
     *
192
     * @return Response Output
193
     *
194
     * @throws AccessDeniedException Thrown if the user doesn't have required permissions
195
     * @throws NotFoundHttpException Thrown by form handler if item to be edited isn't found
196
     * @throws RuntimeException      Thrown if another critical error occurs (e.g. workflow actions not available)
197
     */
198
    public function editAction(Request $request)
199
    {
200
        return parent::editAction($request);
201
    }
202
    /**
203
     * {@inheritdoc}
204
     *
205
     * @Route("/admin/route/delete/{id}.{_format}",
206
     *        requirements = {"id" = "\d+", "_format" = "html"},
207
     *        defaults = {"_format" = "html"},
208
     *        methods = {"GET", "POST"}
209
     * )
210
     * @Theme("admin")
211
     *
212
     * @param Request $request Current request instance
213
     * @param RouteEntity $route Treated route instance
214
     *
215
     * @return Response Output
216
     *
217
     * @throws AccessDeniedException Thrown if the user doesn't have required permissions
218
     * @throws NotFoundHttpException Thrown by param converter if item to be deleted isn't found
219
     * @throws RuntimeException      Thrown if another critical error occurs (e.g. workflow actions not available)
220
     */
221
    public function adminDeleteAction(Request $request, RouteEntity $route)
222
    {
223
        return parent::adminDeleteAction($request, $route);
224
    }
225
    
226
    /**
227
     * {@inheritdoc}
228
     *
229
     * @Route("/route/delete/{id}.{_format}",
230
     *        requirements = {"id" = "\d+", "_format" = "html"},
231
     *        defaults = {"_format" = "html"},
232
     *        methods = {"GET", "POST"}
233
     * )
234
     *
235
     * @param Request $request Current request instance
236
     * @param RouteEntity $route Treated route instance
237
     *
238
     * @return Response Output
239
     *
240
     * @throws AccessDeniedException Thrown if the user doesn't have required permissions
241
     * @throws NotFoundHttpException Thrown by param converter if item to be deleted isn't found
242
     * @throws RuntimeException      Thrown if another critical error occurs (e.g. workflow actions not available)
243
     */
244
    public function deleteAction(Request $request, RouteEntity $route)
245
    {
246
        return parent::deleteAction($request, $route);
247
    }
248
249
    /**
250
     * {@inheritdoc}
251
     *
252
     * @Route("/admin/routes/reload",
253
     *        methods = {"GET", "POST"}
254
     * )
255
     * @Theme("admin")
256
     *
257
     * @param Request $request Current request instance
258
     *
259
     * @return Response Output
260
     *
261
     * @throws AccessDeniedException Thrown if the user doesn't have required permissions
262
     */
263
    public function adminReloadAction(Request $request)
264
    {
265
        //return parent::adminReloadAction($request);
0 ignored issues
show
Unused Code Comprehensibility introduced by
78% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
266
267
        $objectType = 'route';
268
        if (!$this->hasPermission($this->name . ':' . ucfirst($objectType) . ':', '::', ACCESS_ADMIN)) {
269
            throw new AccessDeniedException();
270
        }
271
272
        $cacheClearer = $this->get('zikula.cache_clearer');
273
        $routeDumperHelper = $this->get('zikula_routes_module.route_dumper_helper');
274
275
        $cacheClearer->clear('symfony.routing');
276
277
        $this->addFlash('status', $this->__('Done! Routes reloaded.'));
278
279
        // reload **all** JS routes
280
        $result = $routeDumperHelper->dumpJsRoutes();
281 View Code Duplication
        if ($result == '') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
282
            $this->addFlash('status', $this->__f('Done! Exposed JS Routes dumped to %s.', ['%s' => 'web/js/fos_js_routes.js']));
283
        } else {
284
            $this->addFlash('error', $this->__f('Error! There was an error dumping exposed JS Routes: %s', ['%s' => $result]));
285
        }
286
287
        return $this->redirectToRoute('zikularoutesmodule_route_adminview');
288
    }
289
290
    /**
291
     * {@inheritdoc}
292
     *
293
     * @Route("/routes/reload",
294
     *        methods = {"GET", "POST"}
295
     * )
296
     *
297
     * @param Request $request Current request instance
298
     *
299
     * @return Response Output
300
     *
301
     * @throws AccessDeniedException Thrown if the user doesn't have required permissions
302
     */
303
    public function reloadAction(Request $request)
304
    {
305
        throw new AccessDeniedException();
306
    }
307
308
    /**
309
     * {@inheritdoc}
310
     *
311
     * @Route("/admin/routes/renew",
312
     *        methods = {"GET", "POST"}
313
     * )
314
     * @Theme("admin")
315
     *
316
     * @param Request $request Current request instance
317
     *
318
     * @return Response Output
319
     *
320
     * @throws AccessDeniedException Thrown if the user doesn't have required permissions
321
     */
322
    public function adminRenewAction(Request $request)
323
    {
324
        $objectType = 'route';
325
        if (!$this->hasPermission($this->name . ':' . ucfirst($objectType) . ':', '::', ACCESS_ADMIN)) {
326
            throw new AccessDeniedException();
327
        }
328
329
        // Renew the routing settings.
330
        $this->get('zikula_routes_module.multilingual_routing_helper')->reloadMultilingualRoutingSettings();
331
332
        $this->addFlash('status', $this->__('Done! Routing settings renewed.'));
333
334
        return $this->redirectToRoute('zikularoutesmodule_route_adminview');
335
    }
336
337
    /**
338
     * {@inheritdoc}
339
     *
340
     * @Route("/routes/renew",
341
     *        methods = {"GET", "POST"}
342
     * )
343
     *
344
     * @param Request $request Current request instance
345
     *
346
     * @return Response Output
347
     *
348
     * @throws AccessDeniedException Thrown if the user doesn't have required permissions
349
     */
350
    public function renewAction(Request $request)
351
    {
352
        return parent::renewAction($request);
353
    }
354
355
    /**
356
     * Process status changes for multiple items.
357
     *
358
     * This function processes the items selected in the admin view page.
359
     * Multiple items may have their state changed or be deleted.
360
     *
361
     * @Route("/routes/handleSelectedEntries",
362
     *        methods = {"POST"}
363
     * )
364
     * @Theme("admin")
365
     *
366
     * @param Request $request Current request instance
367
     *
368
     * @return bool true on sucess, false on failure
369
     *
370
     * @throws RuntimeException Thrown if executing the workflow action fails
371
     */
372
    public function adminHandleSelectedEntriesAction(Request $request)
373
    {
374
        return parent::adminHandleSelectedEntriesAction($request);
375
    }
376
    /**
377
     * Process status changes for multiple items.
378
     *
379
     * This function processes the items selected in the admin view page.
380
     * Multiple items may have their state changed or be deleted.
381
     *
382
     * @Route("/routes/handleSelectedEntries",
383
     *        methods = {"POST"}
384
     * )
385
     *
386
     * @param Request $request Current request instance
387
     *
388
     * @return bool true on sucess, false on failure
389
     *
390
     * @throws RuntimeException Thrown if executing the workflow action fails
391
     */
392
    public function handleSelectedEntriesAction(Request $request)
393
    {
394
        return parent::handleSelectedEntriesAction($request);
395
    }
396
397
    /**
398
     * Dumps the routes exposed to javascript to '/web/js/fos_js_routes.js'.
399
     *
400
     * @Route("/routes/dump/{lang}",
401
     *        name = "zikularoutesmodule_route_dumpjsroutes",
402
     *        methods = {"GET"}
403
     * )
404
     * @Theme("admin")
405
     *
406
     * @param Request $request Current request instance
407
     *
408
     * @return Response Output
409
     *
410
     * @throws AccessDeniedException Thrown if the user doesn't have required permissions
411
     */
412
    public function dumpJsRoutesAction(Request $request, $lang = null)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
413
    {
414
        $objectType = 'route';
415
        if (!$this->hasPermission($this->name . ':' . ucfirst($objectType) . ':', '::', ACCESS_ADMIN)) {
416
            throw new AccessDeniedException();
417
        }
418
419
        $routeDumperHelper = $this->get('zikula_routes_module.route_dumper_helper');
420
        $result = $routeDumperHelper->dumpJsRoutes($lang);
421
422 View Code Duplication
        if ($result == '') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
423
            $this->addFlash('status', $this->__f('Done! Exposed JS Routes dumped to %s.', ['%s' => 'web/js/fos_js_routes.js']));
424
        } else {
425
            $this->addFlash('error', $this->__f('Error! There was an error dumping exposed JS Routes: %s', ['%s' => $result]));
426
        }
427
428
        return $this->redirectToRoute('zikularoutesmodule_route_adminview');
429
    }
430
}
431