Completed
Push — master ( ab125f...3d5e2b )
by Ryan
02:42
created

StatusFilterQuery::handle()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 14
c 1
b 0
f 0
rs 9.2
cc 4
eloc 7
nc 8
nop 2
1
<?php namespace Anomaly\UsersModule\User\Table\Filter;
2
3
use Anomaly\Streams\Platform\Ui\Table\Component\Filter\Contract\FilterInterface;
4
use Anomaly\Streams\Platform\Ui\Table\Component\Filter\Query\GenericFilterQuery;
5
use Illuminate\Database\Eloquent\Builder;
6
7
/**
8
 * Class StatusFilterQuery
9
 *
10
 * @link          http://anomaly.is/streams-platform
11
 * @author        AnomalyLabs, Inc. <[email protected]>
12
 * @author        Ryan Thompson <[email protected]>
13
 * @package       Anomaly\UsersModule\User\Table\Filter
14
 */
15
class StatusFilterQuery extends GenericFilterQuery
16
{
17
18
    /**
19
     * Handle the filter query.
20
     *
21
     * @param Builder         $query
22
     * @param FilterInterface $filter
23
     */
24
    public function handle(Builder $query, FilterInterface $filter)
25
    {
26
        if ($filter->getValue() == 'active') {
27
            $query->where('enabled', true)->where('activated', true);
28
        }
29
30
        if ($filter->getValue() == 'inactive') {
31
            $query->where('enabled', true)->where('activated', false);
32
        }
33
34
        if ($filter->getValue() == 'disabled') {
35
            $query->where('enabled', false);
36
        }
37
    }
38
}
39