/
ScheduleTemplate.php
264 lines (227 loc) · 9.32 KB
/
ScheduleTemplate.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
<?php
namespace AppBundle\Action\Schedule2016;
use AppBundle\Action\AbstractActionTrait;
use AppBundle\Action\GameOfficial\AssignWorkflow;
use AppBundle\Action\GameOfficial\GameOfficialDetailsFinder;
use AppBundle\Action\RegPerson\RegPersonFinder;
use AppBundle\Action\AbstractTemplate;
class ScheduleTemplate extends AbstractTemplate
{
use AbstractActionTrait;
protected $showOfficials;
protected $showOfficialDetails;
protected $gameOfficialDetailsFinder;
protected $scheduleTitle;
protected $assignWorkflow;
/** @var RegPersonFinder */
protected $regPersonFinder;
protected $regPersonId;
protected $regPersonTeamIds;
protected $regPersonPersonsIds;
public function __construct(
$scheduleTitle,
$showOfficials = false,
$showOfficialDetails = false,
AssignWorkflow $assignWorkflow = null,
GameOfficialDetailsFinder $gameOfficialDetailsFinder = null
) {
$this->showOfficials = $showOfficials;
$this->showOfficialDetails = $showOfficialDetails;
$this->gameOfficialDetailsFinder = $gameOfficialDetailsFinder;
$this->scheduleTitle = $scheduleTitle;
$this->assignWorkflow = $assignWorkflow;
}
public function setRegPersonFinder(RegPersonFinder $regPersonFinder)
{
$this->regPersonFinder = $regPersonFinder;
}
// Depreciated
public function setTitle($title = 'Game Schedule')
{
$this->scheduleTitle = $title;
}
public function render(array $games)
{
$gameCount = count($games);
$this->showOfficials = $this->isGranted('ROLE_REFEREE') ? $this->showOfficials : false;
$this->showOfficialDetails = $this->isGranted('ROLE_REFEREE') ? $this->showOfficialDetails : false;
$html = null;
if($this->showOfficialDetails){ // for Assignor Instructions
$html .= null;
} elseif ($this->showOfficials ) { // for Referee instructions
$html .=
<<<EOT
<div id="clear-fix">
<legend>Instructions for Referees</legend>
<ul class="cerad-common-help ul_bullets">
<li>Click on "<a href="{$this->generateUrl('schedule_official_2016')}">Request Assignments</a>" under the "Referees" menu item above.</li>
<li>On any open match, click on the position you'd like to request, e.g. REF, AR1, AR2</li>
<li>Click "Submit" button"</li>
<li>Check back on your schedule under "<a href="{$this->generateUrl('schedule_my_2016')}">My Schedule</a>" under the "My Stuff" menu item above to see the assignments.
<li>Detailed instructions for self-assigning are available <a href="{$this->generateUrl('detailed_instruction')}" target="_blank">by clicking here</a>.</ul>
</ul>
</div>
<hr>
EOT;
}
$html .= <<<EOD
<table id="schedule" class="schedule" border="1">
<thead>
<tr><th colspan="20" class="text-center">{$this->scheduleTitle} - Game Count: {$gameCount}</th></tr>
<tr>
<th class="schedule-game" >Game</th>
<th class="schedule-dow" >Day</th>
<th class="schedule-time" >Time</th>
<th class="schedule-field">Field</th>
<th class="schedule-group">Group</th>
<th class="schedule-slot" >Slot</th>
<th class="schedule-teams">Home / Away</th>
EOD;
if ($this->showOfficials) {
$html .= <<<EOD
<th class="schedule-officials">Officials</th>
EOD;
}
$html .= <<<EOD
</tr>
</thead>
<tbody>
{$this->renderScheduleRows($games)}
</tbody>
</table>
</div>
<br />
</div
EOD;
return $html;
}
/**
* @param ScheduleGame[] $games
* @return string
*/
private function renderScheduleRows($games)
{
$this->regPersonId = $regPersonId = $this->getUserRegPersonId();
$this->regPersonTeamIds = $this->regPersonFinder->findRegPersonTeamIds ($regPersonId);
$this->regPersonPersonsIds = $this->regPersonFinder->findRegPersonPersonIds($regPersonId);
$html = null;
foreach($games as $game) {
$homeTeam = $game->homeTeam;
$awayTeam = $game->awayTeam;
$homeTeamName = $this->escape($homeTeam->regTeamName);
$awayTeamName = $this->escape($awayTeam->regTeamName);
if (isset($this->regPersonTeamIds[$homeTeam->regTeamId])) {
$homeTeamName = sprintf('<span class="my-team">%s</span>',$homeTeamName);
}
if (isset($this->regPersonTeamIds[$awayTeam->regTeamId])) {
$awayTeamName = sprintf('<span class="my-team">%s</span>',$awayTeamName);
}
// Id for returning
$trId = 'game-' . $game->gameId;
// Link for editing game
$gameNumber = $game->gameNumber;
if ($this->isGranted('ROLE_USER')) {
$params = [
'projectId' => $game->projectId,
'gameNumber' => $game->gameNumber,
'back' => $this->getCurrentRouteName(), // $this->generateUrl($this->getCurrentRouteName()) . '#' . $trId,
];
$url = $this->generateUrl('game_report_update',$params);
$gameNumber = sprintf('<a href="%s">%s</a>',$url,$gameNumber);
}
$html .= <<<EOD
<tr id="{$trId}" class="game-status-{$game->status}">
<td class="schedule-game" >{$gameNumber}</td>
<td class="schedule-dow" >{$game->dow}</td>
<td class="schedule-time" >{$game->time}</td>
<td class="schedule-field"><a href="{$this->generateUrl('field_map')}" target=_blank}>{$game->fieldName}</a></td>
<td class="schedule-group">{$game->poolView}</td>
<td>{$homeTeam->poolTeamSlotView}<hr class="separator">{$awayTeam->poolTeamSlotView}</td>
<td class="text-left">{$homeTeamName}<hr class="separator">{$awayTeamName}</td>
EOD;
// TODO: Move all this to a ScheduleOfficialTemplate
if ($this->showOfficials) {
$html .= <<<EOD
<td class="schedule-referees text-left">
<table>
<tr>{$this->renderGameOfficial($game,$game->referee)}</tr>
<tr>{$this->renderGameOfficial($game,$game->ar1) }</tr>
<tr>{$this->renderGameOfficial($game,$game->ar2) }</tr>
</table>
</td>
EOD;
}
$html .= <<<EOD
</tr>
EOD;
}
return $html;
}
private function renderGameOfficial(ScheduleGame $game, ScheduleGameOfficial $gameOfficial)
{
// Escape and hilite name
$gameOfficialName = $this->escape($gameOfficial->regPersonName);
if (isset($this->regPersonPersonsIds[$gameOfficial->regPersonId])) {
$class = $gameOfficial->regPersonId === $this->regPersonId ? 'my-slot' : 'my-slot-crew';
$gameOfficialName = sprintf('<span class="%s">%s</span>',$class,$gameOfficialName);
}
$params = [
'projectId' => $game->projectId,
'gameNumber' => $game->gameNumber,
'slot' => $gameOfficial->slot,
'back' => $this->getCurrentRouteName(),
];
$assignRouteName = $this->showOfficialDetails ?
'game_official_assign_by_assignor':
'game_official_assign_by_assignee';
$assignUrl = $this->generateUrl($assignRouteName,$params);
$slotView = $gameOfficial->slotView;
if ($this->isGranted('view',$gameOfficial)) {
$slotView = sprintf('<a href="%s">%s</a>',$assignUrl,$slotView);
}
$assignState = $gameOfficial->assignState;
$assignStateView = $this->assignWorkflow->assignStateAbbreviations[$assignState];
if ($assignState === 'Pending' && !$this->isGranted('ROLE_ASSIGNOR')) {
$assignState = 'Open';
$assignStateView = 'Open';
$gameOfficialName = null;
}
$html = <<<EOD
<td class="text-left game-official-state-{$assignState}">{$assignStateView}</td>
<td class="text-left">{$slotView}</td>
<td class="text-left">{$gameOfficialName}</td>
EOD;
if (!$this->showOfficialDetails) {
return $html;
}
$row = $this->gameOfficialDetailsFinder->findGameOfficialDetails($gameOfficial->regPersonId);
if (!$row) {
return $html;
}
$refereeBadge = substr($row['refereeBadge'],0,3);
return $html . <<<EOD
<td class="text-left">{$refereeBadge}</td>
<td class="text-right {$this->styleSectionConflict($row['orgView'],$game)}">{$row['orgView']}</td>
EOD;
}
private function styleSectionConflict($refOrg, $game)
{
$homeTeam = explode(' ',$game->homeTeam->regTeamName);
$awayTeam = explode(' ',$game->awayTeam->regTeamName);
if (isset($homeTeam[1])) {
$homeTeamOrg = $homeTeam[1];
} else return null;
if (isset($awayTeam[1])) {
$awayTeamOrg = $awayTeam[1];
} else return null;
if ($homeTeamOrg == 'BYE') return null;
if ($awayTeamOrg == 'BYE') return null;
$homeTeamSection = (integer) explode('-',$homeTeamOrg)[0];
$awayTeamSection = (integer) explode('-',$awayTeamOrg)[0];
$refSection = (integer) explode('/',$refOrg)[0];
if ( ($homeTeamSection == $refSection) or ($awayTeamSection == $refSection) ) {
return "bg-danger";
}
return '';
}
}