AreasAPI::canUpdate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
class AreasAPI extends ProfilesAdminDataAPI
3
{
4
    public function __construct()
5
    {
6
        parent::__construct('profiles', 'area', 'short_name');
7
    }
8
9
    public function setup($app)
10
    {
11
        parent::setup($app);
12
        $app->get('/{name}/leads', array($this, 'getLeads'));
13
    }
14
15
    protected function canCreate($request)
16
    {
17
        $this->validateIsAdmin($request);
18
        return true;
19
    }
20
21
    protected function canUpdate($request, $entity)
22
    {
23
        $this->validateIsAdmin($request);
24
        return true;
25
    }
26
27
    public function getLeads($request, $response, $args)
28
    {
29
        $this->validateLoggedIn($request);
30
        $dataTable = \Flipside\DataSetFactory::getDataTableByNames('profiles', 'position');
31
        $odata = $request->getAttribute('odata', new \Flipside\ODataParams(array()));
32
        if($args['name'] === '*')
33
        {
34
            $leads = $dataTable->read($odata->filter, $odata->select, $odata->top,
35
                                  $odata->skip, $odata->orderby);
36
        }
37
        else
38
        {
39
            $leads = $dataTable->read(new \Flipside\Data\Filter("area eq '".$args['name']."'"), $odata->select, $odata->top,
40
                                  $odata->skip, $odata->orderby);
41
        }
42
        if(empty($leads))
43
        {
44
            return $response->withStatus(404);
45
        }
46
        return $response->withJson($leads);
47
    }
48
}
49
/* vim: set tabstop=4 shiftwidth=4 expandtab: */
50