Passed
Push — master ( c7d7ec...eff4fb )
by Sam
15:35
created

getAccessibleSubQuery()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
dl 0
loc 7
rs 10
c 1
b 0
f 0
cc 3
nc 2
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application\Repository;
6
7
use Application\Model\FacilitatorDocument;
8
use Application\Model\User;
9
10
use Ecodev\Felix\Repository\LimitedAccessSubQuery;
11
12
/**
13
 * @extends AbstractRepository<FacilitatorDocument>
14
 */
15
class FacilitatorDocumentRepository extends AbstractRepository implements LimitedAccessSubQuery
16
{
17
    /**
18
     * Returns pure SQL to get ID of all objects that are accessible to given user.
19
     *
20
     * A user can access a file if at least one of the following condition is true:
21
     *
22
     * - he is facilitator or administrator
23
     *
24
     * @param null|User $user
25
     */
26
    public function getAccessibleSubQuery(?\Ecodev\Felix\Model\User $user): string
27
    {
28
        if ($user && in_array($user->getRole(), [User::ROLE_FACILITATOR, User::ROLE_ADMINISTRATOR], true)) {
29
            return $this->getAllIdsQuery();
30
        }
31
32
        return 'SELECT id FROM facilitator_document WHERE facilitator_document.is_active';
33
    }
34
}
35