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