Completed
Push — master ( df6d12...eab9e2 )
by Patrick
01:41 queued 10s
created

VolunteerAdminPage::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 17
rs 9.7
c 0
b 0
f 0
1
<?php
2
require_once('class.FlipSession.php');
3
require_once('app/VolunteerAutoload.php');
4
require_once('../../class.SecurePage.php');
5
class VolunteerAdminPage extends \Http\FlipAdminPage
6
{
7
    use SecureWebPage;
8
9
    public $isLead;
10
    public $isAuthorized;
11
    public $secure_root;
12
13
    public function __construct($title)
14
    {
15
        $this->isLead = false;
16
        $this->isAuthorized = false;
17
        parent::__construct($title, 'VolunteerAdmins');
18
        $this->getAdminInfo();
19
        $this->addLinks();
20
        $this->addCSS('https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.7/css/select2.min.css');
21
        $this->addJS('https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.7/js/select2.min.js');
22
        //Neither Firefox nor Safari have support for datetime-local. This is roughly equivalent
23
        $this->addCSS('https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css');
24
        $this->addJS('https://cdn.jsdelivr.net/npm/flatpickr');
25
        $this->addJS('js/admin.js');
26
        $this->addJS('../js/dialog.js');
27
        $this->secure_root = $this->getSecureRoot();
28
        $this->content['loginUrl'] = $this->secure_root.'api/v1/login';
29
    }
30
31
    protected function getAdminInfo()
32
    {
33
        if($this->is_admin === false && $this->user)
34
        {
35
            //Is the user a lead or otherwise authorized to manipulate a department?
36
            $this->isLead = $this->user->isInGroupNamed('Leads');
37
            if($this->isLead)
38
            {
39
                 $this->is_admin = true;
40
            }
41
        }
42
    }
43
44
    protected function addLinks()
45
    {
46
        $this->content['header']['sidebar'] = array();
47
        if($this->user === false || $this->user === null)
48
        {
49
            return;
50
        }
51
        $this->content['header']['sidebar']['Dashboard'] = array('icon' => 'fa-tachometer-alt', 'url' => 'index.php');
52
        if($this->isLead === false)
53
        {
54
            $this->content['header']['sidebar']['Events'] = array('icon' => 'fa-calendar-alt', 'url' => 'events.php');
55
            $this->content['header']['sidebar']['Departments'] = array('icon' => 'fa-building', 'url' => 'departments.php');
56
        }
57
        $charts_menu = array(
58
            'Shift Schedules' => 'shift_schedules.php',
59
            'Shift Stats' => 'shift_stats.php',
60
            'T-Shirts' => 'tshirts.php',
61
            'Participant Shifts' => 'vol_shifts.php',
62
            'Volunteers without Shifts' => 'no_shifts.php'
63
        );
64
        $shifts_menu = array(
65
            'Add/Edit Shifts' => 'shifts.php',
66
            'Pending Shifts' => 'pending.php'
67
        );
68
        $this->content['header']['sidebar']['Roles'] = array('icon' => 'fa-address-card', 'url' => 'roles.php');
69
        $this->content['header']['sidebar']['Shifts'] = array('icon' => 'fa-tshirt', 'menu' => $shifts_menu);
70
        $this->content['header']['sidebar']['Volunteers'] = array('icon' => 'fa-user', 'url' => 'volunteers.php');
71
        $this->content['header']['sidebar']['Reports'] = array('icon' => 'fa-chart-bar', 'menu' => $charts_menu);
72
    }
73
}
74