Passed
Push — master ( d7e703...d0dd1b )
by Patrick
09:55
created

VolunteerAdminPage   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 106
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 72
c 3
b 0
f 0
dl 0
loc 106
rs 10
wmc 13

3 Methods

Rating   Name   Duplication   Size   Complexity  
B addLinks() 0 56 8
A __construct() 0 16 1
A getAdminInfo() 0 20 4
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
            else
42
            {
43
                //Is this user the assistant for a department?
44
                $uid = $this->user->uid;
45
                $email = $this->user->mail;
46
                $filter = new \Data\Filter("others eq $uid or others eq $email");
47
                $dataTable = DataSetFactory::getDataTableByNames('fvs', 'departments');
48
                $depts = $dataTable->read($filter);
49
                $this->isLead = !empty($depts);
50
                $this->is_admin = true;
51
            }
52
        }
53
    }
54
55
    protected function addLinks()
56
    {
57
        $this->content['header']['sidebar'] = array();
58
        if($this->user === false || $this->user === null)
59
        {
60
            return;
61
        }
62
        $this->content['header']['sidebar']['Dashboard'] = array('icon' => 'fa-tachometer-alt', 'url' => 'index.php');
63
        if($this->isLead === false)
64
        {
65
            $this->content['header']['sidebar']['Events'] = array('icon' => 'fa-calendar-alt', 'url' => 'events.php');
66
            $this->content['header']['sidebar']['Departments'] = array('icon' => 'fa-building', 'url' => 'departments.php');
67
        }
68
        $charts_menu = array(
69
            'Shift Schedules' => 'shift_schedules.php',
70
            'Shift Stats' => 'shift_stats.php',
71
            'T-Shirts' => 'tshirts.php',
72
            'Participant Shifts' => 'vol_shifts.php',
73
            'Volunteers without Shifts' => 'no_shifts.php',
74
            'Empty Shifts' => 'report_empty_shifts.php',
75
            'Early Entry' => 'report_early_entry.php'
76
        );
77
        $shifts_menu = array(
78
            'Add/Edit Shifts' => 'shifts.php',
79
            'Pending Shifts' => 'pending.php',
80
            'Early Entry/Late Stay Approval' => 'ee.php'
81
        );
82
        $certApprovalCount = 0;
83
        $certTable = \DataSetFactory::getDataTableByNames('fvs', 'certifications');
84
        $userTable = \DataSetFactory::getDataTableByNames('fvs', 'participants');
85
        $certs = $certTable->read();
86
        $count = count($certs);
0 ignored issues
show
Bug introduced by
It seems like $certs 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

86
        $count = count(/** @scrutinizer ignore-type */ $certs);
Loading history...
87
        for($i = 0; $i < $count; $i++)
88
        {
89
            $filter = new \Data\Filter('certs.'.$certs[$i]['certID'].'.status eq pending');
90
            $users = $userTable->read($filter);
91
            $certApprovalCount += count($users);
92
        }
93
        $certBadge = '';
94
        if($certApprovalCount > 0)
95
        {
96
            $certBadge = '<span class="badge badge-secondary">'.$certApprovalCount.'</span>';
97
        }
98
        $this->content['header']['sidebar']['Roles'] = array('icon' => 'fa-address-card', 'url' => 'roles.php');
99
        $this->content['header']['sidebar']['Shifts'] = array('icon' => 'fa-tshirt', 'menu' => $shifts_menu);
100
        $this->content['header']['sidebar']['Volunteers'] = array('icon' => 'fa-user', 'url' => 'volunteers.php');
101
        $this->content['header']['sidebar']['Certification Approval '.$certBadge] = array('icon' => 'fa-stamp', 'url' => 'cert_approval.php');
102
        $this->content['header']['sidebar']['Reports'] = array('icon' => 'fa-chart-bar', 'menu' => $charts_menu);
103
        $this->content['header']['sidebar']['Contact'] = array('icon' => 'fa-envelope', 'url' => 'contact.php');
104
        if($this->user && $this->user->isInGroupNamed('VolunteerAdmins'))
105
        {
106
            $admin_menu = array(
107
                'Email Text' => 'emails.php',
108
                'Certifications' => 'certs.php'
109
            );
110
            $this->content['header']['sidebar']['Admin'] = array('icon' => 'fa-cog', 'menu' => $admin_menu);
111
        }
112
    }
113
}
114
/* vim: set tabstop=4 shiftwidth=4 expandtab: */
115