Completed
Push — master ( e45dbf...3a73d5 )
by Nate
05:43 queued 04:08
created

ProviderActiveQuery::init()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 7
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 6
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\db;
10
11
use craft\db\QueryAbortedException;
12
use flipbox\ember\db\traits\AuditAttributes;
13
use flipbox\ember\db\traits\FixedOrderBy;
14
use flipbox\patron\Patron;
15
use yii\db\ActiveQuery;
16
17
/**
18
 * @author Flipbox Factory <[email protected]>
19
 * @since 1.0.0
20
 */
21
class ProviderActiveQuery extends ActiveQuery
22
{
23
    use traits\ProviderAttributes,
24
        FixedOrderBy,
25
        AuditAttributes;
26
27
    /**
28
     * @inheritdoc
29
     */
30
    public function init()
31
    {
32
        parent::init();
33
34
        if ($this->environment === null) {
35
            $this->environment = Patron::getInstance()->getSettings()->getEnvironment();
36
        }
37
    }
38
39
    /**
40
     * @inheritdoc
41
     */
42
    public $orderBy = ['dateCreated' => SORT_DESC];
43
44
    /*******************************************
45
     * FIXED ORDER
46
     *******************************************/
47
48
    /**
49
     * @inheritdoc
50
     */
51
    protected function fixedOrderColumn(): string
52
    {
53
        return 'id';
54
    }
55
56
    /*******************************************
57
     * PREPARE
58
     *******************************************/
59
60
    /**
61
     * @inheritdoc
62
     *
63
     * @throws QueryAbortedException if it can be determined that there won’t be any results
64
     */
65
    public function prepare($builder)
66
    {
67
        $this->applyConditions();
68
        $this->applyAuditAttributeConditions();
69
        $this->applyOrderByParams($builder->db);
70
71
        return parent::prepare($builder);
72
    }
73
}
74