applyAuditAttributeConditions()   A
last analyzed

Complexity

Conditions 4
Paths 8

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 0
cts 12
cp 0
rs 9.7998
c 0
b 0
f 0
cc 4
nc 8
nop 0
crap 20
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://github.com/flipboxfactory/craft-ember/blob/master/LICENSE
6
 * @link       https://github.com/flipboxfactory/craft-ember/
7
 */
8
9
namespace flipbox\craft\ember\queries;
10
11
use craft\helpers\Db;
12
use yii\db\Expression;
13
14
/**
15
 * @author Flipbox Factory <[email protected]>
16
 * @since 2.0.0
17
 */
18
trait AuditAttributesTrait
19
{
20
    /**
21
     * @var string|string[]|null The element UID(s). Prefix UIDs with "not " to exclude them.
22
     */
23
    public $uid;
24
25
    /**
26
     * @var mixed When the resulting elements must have been created.
27
     */
28
    public $dateCreated;
29
30
    /**
31
     * @var mixed When the resulting elements must have been last updated.
32
     */
33
    public $dateUpdated;
34
35
    /**
36
     * Adds an additional WHERE condition to the existing one.
37
     * The new condition and the existing one will be joined using the `AND` operator.
38
     * @param string|array|Expression $condition the new WHERE condition. Please refer to [[where()]]
39
     * on how to specify this parameter.
40
     * @param array $params the parameters (name => value) to be bound to the query.
41
     * @return $this the query object itself
42
     * @see where()
43
     * @see orWhere()
44
     */
45
    abstract public function andWhere($condition, $params = []);
46
47
    /**
48
     * @inheritdoc
49
     * return static
50
     */
51
    public function uid($value)
52
    {
53
        $this->uid = $value;
54
55
        return $this;
56
    }
57
58
    /**
59
     * @inheritdoc
60
     * return static
61
     */
62
    public function dateCreated($value)
63
    {
64
        $this->dateCreated = $value;
65
66
        return $this;
67
    }
68
69
    /**
70
     * @inheritdoc
71
     * return static
72
     */
73
    public function dateUpdated($value)
74
    {
75
        $this->dateUpdated = $value;
76
77
        return $this;
78
    }
79
80
    /**
81
     *
82
     */
83
    protected function applyAuditAttributeConditions()
84
    {
85
        if ($this->uid !== null) {
86
            $this->andWhere(Db::parseParam('uid', $this->uid));
87
        }
88
89
        if ($this->dateCreated !== null) {
90
            $this->andWhere(Db::parseDateParam('dateCreated', $this->dateCreated));
91
        }
92
93
        if ($this->dateUpdated !== null) {
94
            $this->andWhere(Db::parseDateParam('dateUpdated', $this->dateUpdated));
95
        }
96
    }
97
}
98