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

ProviderActiveQuery   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 5
dl 0
loc 44
ccs 0
cts 14
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 10 2
A prepare() 0 7 1
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