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

ProviderActiveQuery::prepare()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 6
cp 0
rs 10
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 craft\db\QueryAbortedException;
12
use flipbox\craft\ember\queries\ActiveQuery;
13
use flipbox\craft\ember\queries\AuditAttributesTrait;
14
use flipbox\patron\Patron;
15
use flipbox\patron\records\Provider;
16
17
/**
18
 * @author Flipbox Factory <[email protected]>
19
 * @since 1.0.0
20
 */
21
class ProviderActiveQuery extends ActiveQuery
22
{
23
    use ProviderAttributesTrait,
24
        AuditAttributesTrait;
25
26
    /**
27
     * @inheritdoc
28
     */
29
    public $orderBy = [
30
        'enabled' => SORT_DESC,
31
        'dateUpdated' => SORT_DESC
32
    ];
33
34
    /**
35
     * @inheritdoc
36
     */
37
    public function init()
38
    {
39
        $this->from = [Provider::tableName() . ' ' . Provider::tableAlias()];
40
41
        parent::init();
42
43
        if ($this->environment === null) {
44
            $this->environment = Patron::getInstance()->getSettings()->getEnvironment();
45
        }
46
    }
47
48
    /*******************************************
49
     * PREPARE
50
     *******************************************/
51
52
    /**
53
     * @inheritdoc
54
     *
55
     * @throws QueryAbortedException if it can be determined that there won’t be any results
56
     */
57
    public function prepare($builder)
58
    {
59
        $this->applyProviderConditions();
60
        $this->applyAuditAttributeConditions();
61
62
        return parent::prepare($builder);
63
    }
64
}
65