forked from stunningpixels/yearbook
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Vote.php
59 lines (52 loc) · 1.4 KB
/
Vote.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
<?php
require_once '../Composer/vendor/autoload.php';
require_once 'Configuration.php';
require_once 'Controllers/Authenticator.php';
if (!Authenticator::IsLoggedIn())
{
Redirect('/login');
return;
}
$TaskStates = TaskState::GetTaskStates();
if ($TaskStates[TaskIds::Vote]->Task->Status != Task::Available)
{
http_response_code(403);
return;
}
$AddSuccess = true;
if (isset($_POST['AwardId']) && isset($_POST['CandidateStudentId']))
{
try
{
$GLOBALS['YearbookModel']->LogAwardVote($_POST['AwardId'], $_POST['CandidateStudentId'], $_SESSION['StudentId']);
}
catch (MeekroDBException $DBException)
{
$AddSuccess = false;
}
}
$Template = new Twig_Environment(new Twig_Loader_Filesystem(array('Templates', 'Templates/Modules')), array('cache' => '../Cache', 'auto_reload' => true));
$Template->addFilter(
new Twig_Filter(
'AwardVotesAwardIdGroup',
function ($AwardVotes)
{
$AwardVoteGrouping = array();
foreach ($AwardVotes as $AwardVote)
{
$AwardVoteGrouping[$AwardVote->Award->AwardId][] = $AwardVote;
}
return $AwardVoteGrouping;
}
)
);
$Template->display(
'Vote.html',
array(
'TaskStates' => $TaskStates,
'Students' => $GLOBALS['YearbookModel']->FindStudents(),
'Awards' => $GLOBALS['YearbookModel']->FindApprovedAwards(),
'AwardVotes' => $GLOBALS['YearbookModel']->FindAwardVotesByVotingStudentId($_SESSION['StudentId']),
'OperationSuccessful' => $AddSuccess
)
);