Completed
Push — master ( 19b2ae...0e0de4 )
by Nate
04:43
created

TokenActiveQuery::prepare()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 0
cts 8
cp 0
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://flipboxfactory.com/software/patron/license
6
 * @link       https://www.flipboxfactory.com/software/patron/
7
 */
8
9
namespace flipbox\patron\queries;
10
11
use flipbox\craft\ember\queries\ActiveQuery;
12
use flipbox\craft\ember\queries\AuditAttributesTrait;
13
use flipbox\craft\ember\queries\UserAttributeTrait;
14
use flipbox\patron\Patron;
15
use flipbox\patron\records\Token;
16
17
/**
18
 * @author Flipbox Factory <[email protected]>
19
 * @since 1.0.0
20
 */
21
class TokenActiveQuery extends ActiveQuery
22
{
23
    use TokenAttributesTrait,
24
        TokenProviderAttributeTrait,
25
        TokenEnvironmentAttributeTrait,
26
        UserAttributeTrait,
27
        AuditAttributesTrait;
28
29
    /**
30
     * @inheritdoc
31
     */
32
    public function init()
33
    {
34
        $this->orderBy = [
35
            Token::tableName() . '.enabled' => SORT_DESC,
36
            Token::tableName() . '.dateExpires' => SORT_DESC,
37
            Token::tableName() . '.dateUpdated' => SORT_DESC
38
        ];
39
40
        $this->from = [Token::tableName() . ' ' . Token::tableAlias()];
41
42
        parent::init();
43
44
        if ($this->environment === null) {
45
            $this->environment = Patron::getInstance()->getSettings()->getEnvironment();
46
        }
47
    }
48
49
    /*******************************************
50
     * FIXED ORDER
51
     *******************************************/
52
53
    /**
54
     * @inheritdoc
55
     * @throws \ReflectionException
56
     */
57
    public function prepare($builder)
58
    {
59
        $this->applyTokenConditions();
60
        $this->applyProviderConditions();
61
        $this->applyEnvironmentConditions();
62
        $this->applyAuditAttributeConditions();
63
64
        return parent::prepare($builder);
65
    }
66
}
67