QueryFilterTrait   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 9
dl 0
loc 22
rs 10
c 1
b 0
f 1
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A getViewStatusFilter() 0 17 4
1
<?php
2
3
namespace Firesphere\SearchBackend\Traits\QueryTraits;
4
5
use SilverStripe\ORM\DataList;
6
use SilverStripe\Security\Group;
7
use SilverStripe\Security\Security;
8
9
/**
10
 *
11
 */
12
trait QueryFilterTrait
13
{
14
    /**
15
     * Add filtering on view status
16
     */
17
    public function getViewStatusFilter(): array
18
    {
19
        // Filter by what the user is allowed to see
20
        $viewIDs = ['null']; // null is always an option as that means publicly visible
21
        $member = Security::getCurrentUser();
22
        if ($member && $member->exists()) {
23
            // Member is logged in, thus allowed to see these
24
            $viewIDs[] = 'LoggedIn';
25
26
            /** @var DataList|Group[] $groups */
27
            $groups = Security::getCurrentUser()->Groups();
28
            if ($groups->count()) {
29
                $viewIDs = array_merge($viewIDs, $groups->column('Code'));
30
            }
31
        }
32
33
        return $viewIDs;
34
    }
35
}
36