1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: wechsler |
5
|
|
|
* Date: 29/01/2017 |
6
|
|
|
* Time: 12:43 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Phase\TakeATicketBundle\Controller; |
10
|
|
|
|
11
|
|
|
use Phase\TakeATicket\DataSource\AbstractSql; |
12
|
|
|
use Phase\TakeATicket\Model\Platform; |
13
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
14
|
|
|
use Phase\TakeATicket\DataSource\Factory; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @property \Symfony\Component\DependencyInjection\Container container |
18
|
|
|
*/ |
19
|
|
|
abstract class BaseController extends Controller |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Use getDataStore() rather than accessing directly as this may not be populated |
23
|
|
|
* |
24
|
|
|
* @var AbstractSql |
25
|
|
|
*/ |
26
|
|
|
protected $dataSource; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @return AbstractSql |
30
|
|
|
*/ |
31
|
|
|
protected function getDataStore() |
32
|
|
|
{ |
33
|
|
|
if (!$this->dataSource) { |
34
|
|
|
$this->dataSource = Factory::datasourceFromDbConnection($this->get('database_connection')); |
35
|
|
|
$this->dataSource->setUpcomingCount($this->getUpcomingCount()); // FIXME reduce navel-gazing |
36
|
|
|
} |
37
|
|
|
return $this->dataSource; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Get display options from config, with overrides if possible |
42
|
|
|
* |
43
|
|
|
* @return array |
44
|
|
|
*/ |
45
|
|
|
protected function getDisplayOptions() |
46
|
|
|
{ |
47
|
|
|
$displayOptions = $this->container->hasParameter('displayOptions') ? |
48
|
|
|
$this->getParameter('displayOptions') : []; |
49
|
|
|
|
50
|
|
|
$displayOptions['upcomingCount'] = $this->getUpcomingCount(); |
51
|
|
|
$displayOptions['songInPreview'] = (bool)$this->getDataStore()->fetchSetting('songInPreview'); |
52
|
|
|
|
53
|
|
|
if ($this->isGranted('ROLE_ADMIN')) { |
54
|
|
|
$displayOptions['songInPreview'] = true; // force for logged-in users |
55
|
|
|
$displayOptions['isAdmin'] = true; // force for logged-in users |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
return $displayOptions; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @return int |
63
|
|
|
*/ |
64
|
|
|
protected function getUpcomingCount() |
65
|
|
|
{ |
66
|
|
|
return $this->getDataStore()->fetchSetting('upcomingCount') ?: 3; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return array |
71
|
|
|
*/ |
72
|
|
|
protected function defaultViewParams() |
73
|
|
|
{ |
74
|
|
|
//$protocol = $_SERVER['HTTPS'] ? 'https' : 'http'; |
|
|
|
|
75
|
|
|
$protocol = 'http'; // $_SERVER['HTTPS'] ? 'https' : 'http'; |
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @noinspection RealpathInSteamContextInspection |
78
|
|
|
*/ |
79
|
|
|
$allPlatforms = $this->dataSource->fetchAllPlatforms(); |
80
|
|
|
$platformNames = array_map(function (Platform $platform) { |
81
|
|
|
return $platform->getName(); |
82
|
|
|
}, $allPlatforms); |
83
|
|
|
|
84
|
|
|
/** @noinspection RealpathInSteamContextInspection */ |
85
|
|
|
$viewParams = [ |
86
|
|
|
//'serverInfo' => $protocol . '://' . $_SERVER['SERVER_ADDR'] . ':' . $_SERVER['SERVER_PORT'] . '/', |
|
|
|
|
87
|
|
|
'serverInfo' => $protocol . '://127.0.0.1:8000/', //FIXME get server name (from config if not in request?) |
88
|
|
|
'base_dir' => realpath($this->getParameter('kernel.root_dir') . '/..'), |
89
|
|
|
'allPlatforms' => $platformNames, |
90
|
|
|
]; |
91
|
|
|
$viewParams['displayOptions'] = $this->getDisplayOptions(); |
92
|
|
|
|
93
|
|
|
return $viewParams; |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
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.