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

UserAssociationQuery   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 5
dl 0
loc 37
ccs 0
cts 21
cp 0
rs 10
c 0
b 0
f 0

2 Methods

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