VolunteerAPI   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 18
c 2
b 0
f 0
dl 0
loc 42
rs 10
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A addRequiredFilter() 0 17 3
A canCreate() 0 3 1
A __construct() 0 3 1
A isVolunteerAdmin() 0 8 2
1
<?php
2
3
class VolunteerAPI extends Http\Rest\DataTableAPI
4
{
5
    protected $isAdmin = null;
6
    protected $isLead = null;
7
8
    public function __construct($dataTableName, $idField = '_id')
9
    {
10
        parent::__construct('fvs', $dataTableName, $idField);
11
    }
12
13
    protected function isVolunteerAdmin($request)
14
    {
15
        $this->validateLoggedIn($request);
16
        if($this->isAdmin === null)
17
        {
18
            $this->isAdmin = $this->user->isInGroupNamed('VolunteerAdmins');
19
        }
20
        return $this->isAdmin;
21
    }
22
23
    protected function canCreate($request)
24
    {
25
        return $this->isVolunteerAdmin($request);
26
    }
27
28
    protected function addRequiredFilter($key, $id, $odata)
29
    {
30
        $filter = new \Data\Filter("$key eq '$id'");
31
        if($odata->filter !== false)
32
        {
33
            $clause = $odata->filter->getClause($key);
34
            if($clause !== null)
35
            {
36
                return false;
37
            }
38
            else
39
            {
40
                $filter->appendChild('and');
41
                $filter->appendChild($odata->filter);
42
            }
43
        }
44
        return $filter;
45
    }
46
}
47
/* vim: set tabstop=4 shiftwidth=4 expandtab: */
48