Completed
Push — master ( b27204...a2c64d )
by Nate
05:15 queued 02:48
created

UserAssociationQuery::prepare()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 0
cts 14
cp 0
rs 9.7333
c 0
b 0
f 0
cc 3
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\queries;
10
11
use craft\helpers\Db;
12
use flipbox\craft\ember\queries\CacheableActiveQuery;
13
use flipbox\craft\ember\queries\UserAttributeTrait;
14
use flipbox\organizations\records\UserAssociation;
15
16
/**
17
 * @author Flipbox Factory <[email protected]>
18
 * @since 1.0.0
19
 *
20
 * @method UserAssociation one($db = null)
21
 * @method UserAssociation[] all($db = null)
22
 * @method UserAssociation[] getCachedResult($db = null)
23
 */
24
class UserAssociationQuery extends CacheableActiveQuery
25
{
26
    use UserAttributeTrait,
27
        OrganizationAttributeTrait;
28
29
    /**
30
     * @inheritdoc
31
     */
32
    public function init()
33
    {
34
        $this->from([
35
            UserAssociation::tableName() . ' ' . UserAssociation::tableAlias()
36
        ]);
37
38
        parent::init();
39
    }
40
41
    /**
42
     * @inheritdoc
43
     */
44
    public function prepare($builder)
45
    {
46
        if ($this->user !== null) {
47
            $this->andWhere(
48
                Db::parseParam('userId', $this->parseUserValue($this->user))
49
            );
50
        }
51
52
        if ($this->organization !== null) {
53
            $this->andWhere(
54
                Db::parseParam('organizationId', $this->parseOrganizationValue($this->organization))
55
            );
56
        }
57
58
        return parent::prepare($builder);
59
    }
60
}
61