|
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 rules() |
|
63
|
|
|
{ |
|
64
|
|
|
return [ |
|
65
|
|
|
['password', 'string', 'max' => 255], |
|
66
|
|
|
['password', 'required', 'when' => function ($model) { |
|
67
|
|
|
/* @var $model static */ |
|
68
|
|
|
return !empty($model->organization->joinPassword); |
|
69
|
|
|
}], |
|
70
|
|
|
['password', 'validatePassword', 'when' => function ($model) { |
|
71
|
|
|
/* @var $model static */ |
|
72
|
|
|
return !empty($model->organization->joinPassword); |
|
73
|
|
|
}], |
|
74
|
|
|
]; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @param $attribute |
|
79
|
|
|
* @param $params |
|
80
|
|
|
* @param $validator |
|
81
|
|
|
*/ |
|
82
|
|
|
public function validatePassword($attribute, $params, $validator) |
|
|
|
|
|
|
83
|
|
|
{ |
|
84
|
|
|
$value = $this->$attribute; |
|
85
|
|
|
if ($this->organization->joinPassword != $value) { |
|
86
|
|
|
$this->addError($attribute, Yii::t('organization', 'Incorrect Password.')); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.