Completed
Push — master ( 6d29c5...d7e703 )
by Patrick
01:36
created

VolunteerAPI::addRequiredFilter()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 3
dl 0
loc 18
rs 9.6666
c 0
b 0
f 0
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