Completed
Push — master ( d2c836...c465dd )
by Nate
13:57 queued 11:38
created

OrganizationTypeAssociationQuery::prepare()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 0
cts 10
cp 0
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 4
nop 1
crap 12
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://flipboxfactory.com/software/organization/license
6
 * @link       https://www.flipboxfactory.com/software/organization/
7
 */
8
9
namespace flipbox\organizations\db;
10
11
use craft\helpers\Db;
12
use flipbox\craft\sortable\associations\db\SortableAssociationQuery;
13
use flipbox\organizations\records\OrganizationTypeAssociation;
14
15
/**
16
 * @author Flipbox Factory <[email protected]>
17
 * @since 1.0.0
18
 *
19
 * @method OrganizationTypeAssociation one($db = null)
20
 * @method OrganizationTypeAssociation[] all($db = null)
21
 * @method OrganizationTypeAssociation[] getCachedResult($db = null)
22
 */
23
class OrganizationTypeAssociationQuery extends SortableAssociationQuery
24
{
25
    /**
26
     * @var int|int[]|false|null The source Id(s). Prefix Ids with "not " to exclude them.
27
     */
28
    public $typeId;
29
30
    /**
31
     * @var int|int[]|false|null The target Id(s). Prefix Ids with "not " to exclude them.
32
     */
33
    public $organizationId;
34
35
    /**
36
     * @inheritdoc
37
     */
38
    public function init()
39
    {
40
        parent::init();
41
42
        if ($this->from === null) {
43
            $this->from([
44
                OrganizationTypeAssociation::tableName() . ' ' . OrganizationTypeAssociation::tableAlias()
45
            ]);
46
        }
47
    }
48
49
    /**
50
     * @inheritdoc
51
     */
52
    protected function fixedOrderColumn(): string
53
    {
54
        return 'typeId';
55
    }
56
57
    /**
58
     * @inheritdoc
59
     * return static
60
     */
61
    public function organization($value)
62
    {
63
        return $this->organizationId($value);
64
    }
65
66
    /**
67
     * @inheritdoc
68
     * return static
69
     */
70
    public function organizationId($value)
71
    {
72
        $this->organizationId = $value;
73
        return $this;
74
    }
75
76
    /**
77
     * @inheritdoc
78
     * return static
79
     */
80
    public function type($value)
81
    {
82
        return $this->typeId($value);
83
    }
84
85
    /**
86
     * @inheritdoc
87
     * return static
88
     */
89
    public function typeId($value)
90
    {
91
        $this->typeId = $value;
92
        return $this;
93
    }
94
95
    /**
96
     * @inheritdoc
97
     */
98
    public function prepare($builder)
99
    {
100
        if ($this->typeId !== null) {
101
            $this->andWhere(Db::parseParam('typeId', $this->typeId));
102
        }
103
104
        if ($this->organizationId !== null) {
105
            $this->andWhere(Db::parseParam('organizationId', $this->organizationId));
106
        }
107
108
        return parent::prepare($builder);
109
    }
110
}
111