User::getSite()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
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\organization\records;
10
11
use craft\models\Site;
12
use craft\records\User as UserRecord;
13
use flipbox\organization\validators\UserAssociation;
14
use flipbox\spark\records\RecordWithId;
15
use yii\db\ActiveQueryInterface;
16
17
/**
18
 * @author Flipbox Factory <[email protected]>
19
 * @since 1.0.0
20
 *
21
 * @property int $id
22
 * @property int $userId
23
 * @property int $organizationId
24
 * @property int $siteId
25
 * @property int $sortOrder
26
 * @property UserRecord $user
27
 * @property Organization $organization
28
 * @property Site $site
29
 */
30
class User extends RecordWithId
31
{
32
33
    const TABLE_ALIAS = Organization::TABLE_ALIAS . '_users';
34
35
    /**
36
     * @inheritdoc
37
     */
38
    public function rules()
39
    {
40
41
        return array_merge(
42
            parent::rules(),
43
            [
44
                [
45
                    [
46
                        'userId'
47
                    ],
48
                    'unique',
49
                    'targetAttribute' => [
50
                        'userId',
51
                        'organizationId'
52
                    ]
53
                ],
54
                [
55
                    [
56
                        'userId'
57
                    ],
58
                    UserAssociation::class
59
                ]
60
            ]
61
        );
62
    }
63
64
    /**
65
     * Returns the user element.
66
     *
67
     * @return ActiveQueryInterface The relational query object.
68
     */
69
    public function getUser(): ActiveQueryInterface
70
    {
71
        return $this->hasOne(UserRecord::class, ['id' => 'userId']);
72
    }
73
74
    /**
75
     * Returns the organization element.
76
     *
77
     * @return ActiveQueryInterface The relational query object.
78
     */
79
    public function getOrganization(): ActiveQueryInterface
80
    {
81
        return $this->hasOne(Organization::class, ['id' => 'organizationId']);
82
    }
83
84
    /**
85
     * Returns the associated site.
86
     *
87
     * @return ActiveQueryInterface The relational query object.
88
     */
89
    public function getSite(): ActiveQueryInterface
90
    {
91
        return $this->hasOne(Site::class, ['id' => 'siteId']);
92
    }
93
}
94