1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* _ __ __ _____ _____ ___ ____ _____ |
5
|
|
|
* | | / // // ___//_ _// || __||_ _| |
6
|
|
|
* | |/ // /(__ ) / / / /| || | | | |
7
|
|
|
* |___//_//____/ /_/ /_/ |_||_| |_| |
8
|
|
|
* @link https://vistart.me/ |
9
|
|
|
* @copyright Copyright (c) 2016 - 2017 vistart |
10
|
|
|
* @license https://vistart.me/license/ |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace rhosocial\organization\forms; |
14
|
|
|
|
15
|
|
|
use rhosocial\organization\Organization; |
16
|
|
|
use Yii; |
17
|
|
|
use yii\base\InvalidConfigException; |
18
|
|
|
use yii\base\Model; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Class JoinOrganizationForm |
22
|
|
|
* @package rhosocial\organization\forms |
23
|
|
|
* @version 1.0 |
24
|
|
|
* @author vistart <[email protected]> |
25
|
|
|
*/ |
26
|
|
|
class JoinOrganizationForm extends Model |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @var Organization |
30
|
|
|
*/ |
31
|
|
|
public $organization; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
public $password = ''; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @inheritdoc |
40
|
|
|
* @throws InvalidConfigException |
41
|
|
|
*/ |
42
|
|
|
public function init() |
43
|
|
|
{ |
44
|
|
|
if (!$this->organization) { |
45
|
|
|
throw new InvalidConfigException("The organization should not be empty."); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @inheritdoc |
51
|
|
|
*/ |
52
|
|
|
public function attributeLabels() |
53
|
|
|
{ |
54
|
|
|
return [ |
55
|
|
|
'password' => Yii::t('organization', 'Password'), |
56
|
|
|
]; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @inheritdoc |
61
|
|
|
*/ |
62
|
|
|
public function attributeHints() |
63
|
|
|
{ |
64
|
|
|
return [ |
65
|
|
|
'password' => Yii::t('organization', 'You need to provide password.'), |
66
|
|
|
]; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @inheritdoc |
71
|
|
|
*/ |
72
|
|
|
public function rules() |
73
|
|
|
{ |
74
|
|
|
return [ |
75
|
|
|
['password', 'safe', 'when' => function ($model) { |
76
|
|
|
/* @var $model static */ |
77
|
|
|
return empty($model->organization->joinPassword); |
78
|
|
|
}], |
79
|
|
|
['password', 'string', 'max' => 255, 'when' => function ($model) { |
80
|
|
|
/* @var $model static */ |
81
|
|
|
return !empty($model->organization->joinPassword); |
82
|
|
|
}], |
83
|
|
|
['password', 'required', 'when' => function ($model) { |
84
|
|
|
/* @var $model static */ |
85
|
|
|
return !empty($model->organization->joinPassword); |
86
|
|
|
}], |
87
|
|
|
['password', 'validatePassword', 'when' => function ($model) { |
88
|
|
|
/* @var $model static */ |
89
|
|
|
return !empty($model->organization->joinPassword); |
90
|
|
|
}], |
91
|
|
|
]; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @param $attribute |
96
|
|
|
* @param $params |
97
|
|
|
* @param $validator |
98
|
|
|
*/ |
99
|
|
|
public function validatePassword($attribute, $params, $validator) |
|
|
|
|
100
|
|
|
{ |
101
|
|
|
$value = $this->$attribute; |
102
|
|
|
if ($this->organization->joinPassword != $value) { |
103
|
|
|
$this->addError($attribute, Yii::t('organization', 'Incorrect Password.')); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.