Passed
Push — master ( 032ee0...c833e7 )
by Patrick
13:14
created

groupSignup.php (1 issue)

Labels
Severity
1
<?php
2
require_once('class.VolunteerPage.php');
3
require_once('app/VolunteerAutoload.php');
4
5
$page = new VolunteerPage('Burning Flipside - Flipside Volunteer System');
6
$page->addJS('js/groupSignup.js');
7
8
$page->body = '<div class="row"><h1>Group Signup</h1></div>';
9
10
if(!isset($_GET['id']))
11
{
12
    $page->body .= 'Error! Missing Group ID. You must have followed a bad link!';
13
    $page->printPage();
14
    return;
15
}
16
17
$groupID = $_GET['id'];
18
$dataTable = DataSetFactory::getDataTableByNames('fvs', 'shifts');
19
$filter = new \Data\Filter('signupLink eq '.$groupID);
20
$shifts = $dataTable->read($filter);
21
if(empty($shifts))
22
{
23
    $page->body .= 'Error! Could not locate shifts. You must have followed an old link!';
24
    $page->printPage();
25
    return;
26
}
27
28
$filled = array();
29
$available = array();
30
$alreadySignedUp = false;
31
32
$count = count($shifts);
0 ignored issues
show
It seems like $shifts can also be of type boolean; however, parameter $var of count() does only seem to accept Countable|array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

32
$count = count(/** @scrutinizer ignore-type */ $shifts);
Loading history...
33
for($i = 0; $i < $count; $i++)
34
{
35
    $shifts[$i] = new \VolunteerShift(false, $shifts[$i]);
36
    if($shifts[$i]->status === 'filled' || $shifts[$i]->status === 'pending')
37
    {
38
        array_push($filled, $shifts[$i]);
39
        if($page->user && $shifts[$i]->participant === $page->user->uid)
40
        {
41
            $alreadySignedUp = true;
42
        }
43
    }
44
    else
45
    {
46
        array_push($available, $shifts[$i]);
47
    }
48
}
49
$page->body .= '<div class="row"><h3>Filled Shifts</h3></div><div class="row"><table class="table"><tr><th>Role</th><th>Participant</th></tr>';
50
foreach($filled as $shift)
51
{
52
  $page->body .= '<tr><td>'.$shift->role->display_name.'</td><td>'.$shift->webParticipantName.'</td></tr>';
53
}
54
$page->body .= '</table></div>';
55
$page->body .= '<div class="row"><h3>Unfilled Shifts</h3></div><div class="row"><table class="table"><tr><th>Role</th><th>Sign Up</th></tr>';
56
foreach($available as $shift)
57
{
58
    $cell = '<i>You already have a shift!</i>';
59
    if($alreadySignedUp === false)
60
    {
61
        $cell = '<button type="button" class="btn btn-primary" onClick="signUp(\''.$shift->_id.'\');">Sign Up</button>';
62
    } 
63
    $page->body .= '<tr><td>'.$shift->role->display_name.'</td><td>'.$cell.'</td></tr>';
64
}
65
$page->body .= '</table></div>';
66
$page->printPage();
67
/* vim: set tabstop=4 shiftwidth=4 expandtab: */
68