Completed
Pull Request — master (#12)
by
unknown
13:18
created

Identity::behaviors()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 6
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * HIAM module for MRDP database compatibility
4
 *
5
 * @link      https://github.com/hiqdev/hiam-mrdp
6
 * @package   hiam-mrdp
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2016, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiam\mrdp\models;
12
13
use hiam\behaviors\SaveReferralParams;
14
15
/**
16
 * Identity model for MRDP database.
17
 *
18
 * @property string $roles
19
 * @property string $seller
20
 * @property integer $seller_id
21
 */
22
class Identity extends \hiam\models\Identity
23
{
24
    public $roles;
25
    public $seller;
26
    public $seller_id;
27
    public $email_confirmed;
28
    public $email_new;
29
    public $send_me_news;
30
    public $referralParams;
31
32
    protected $activeStates = ['ok', 'active'];
33
34
    public function behaviors()
35
    {
36
        return array_merge(parent::behaviors(), [
37
            'save-referral-params' => [
38
                'class' => SaveReferralParams::class,
39
            ],
40
        ]);
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function rules()
47
    {
48
        return array_merge(parent::rules(), [
49
            ['seller_id',       'integer'],
50
51
            ['seller',          'trim'],
52
            ['seller',          'string', 'min' => 2, 'max' => 64],
53
54
            ['roles',           'trim'],
55
            ['email_confirmed', 'email'],
56
            ['send_me_news',    'boolean'],
57
        ]);
58
    }
59
60
    public function isActive()
61
    {
62
        return \in_array($this->state, $this->activeStates, true);
63
    }
64
65
    public function isEmailConfirmed()
66
    {
67
        return !empty($this->email_confirmed);
68
    }
69
70
    public function setNewUnconfirmedEmail(string $newEmail): bool
71
    {
72
        $this->email_new = $newEmail;
73
74
        return true;
75
    }
76
77
    public function setConfirmedEmail(string $email)
78
    {
79
        $this->state = 'ok';
80
        $this->email = $email;
81
        $this->email_confirmed = $email;
82
        $this->save();
83
    }
84
}
85