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\web\organization\controllers\my; |
14
|
|
|
|
15
|
|
|
use rhosocial\organization\exceptions\UnauthorizedManageProfileException; |
16
|
|
|
use rhosocial\organization\forms\SettingsForm; |
17
|
|
|
use rhosocial\organization\rbac\permissions\ManageProfile; |
18
|
|
|
use rhosocial\organization\web\organization\Module; |
19
|
|
|
use Yii; |
20
|
|
|
use yii\base\Action; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Class SettingsAction |
24
|
|
|
* @package rhosocial\organization\web\organization\controllers\my |
25
|
|
|
* @version 1.0 |
26
|
|
|
* @author vistart <[email protected]> |
27
|
|
|
*/ |
28
|
|
|
class SettingsAction extends Action |
29
|
|
|
{ |
30
|
|
|
public $updateSuccessMessage; |
31
|
|
|
public $updateFailedMessage; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Initialize messages. |
35
|
|
|
*/ |
36
|
|
|
protected function initMessages() |
37
|
|
|
{ |
38
|
|
|
if (!is_string($this->updateSuccessMessage)) { |
39
|
|
|
$this->updateSuccessMessage = Yii::t('user' ,'Updated.'); |
40
|
|
|
} |
41
|
|
|
if (!is_string($this->updateFailedMessage)) { |
42
|
|
|
$this->updateFailedMessage = Yii::t('user', 'Failed to Update.'); |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function init() |
47
|
|
|
{ |
48
|
|
|
$this->initMessages(); |
49
|
|
|
parent::init(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Check access. |
54
|
|
|
* @param $org |
55
|
|
|
* @param $user |
56
|
|
|
* @return bool |
57
|
|
|
* @throws UnauthorizedManageProfileException |
58
|
|
|
*/ |
59
|
|
|
public static function checkAccess($org, $user) |
60
|
|
|
{ |
61
|
|
|
MemberAction::checkAccess($org, $user); |
62
|
|
|
if (!Yii::$app->authManager->checkAccess($user->getGUID(), (new ManageProfile)->name, ['organization' => $org])) { |
63
|
|
|
throw new UnauthorizedManageProfileException(); |
64
|
|
|
} |
65
|
|
|
return true; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @return string |
70
|
|
|
*/ |
71
|
|
|
public function run($id) |
72
|
|
|
{ |
73
|
|
|
$organization = Module::getOrganization($id); |
74
|
|
|
$user = Yii::$app->user->identity; |
75
|
|
|
static::checkAccess($organization, $user); |
76
|
|
|
$model = new SettingsForm([ |
77
|
|
|
'organization' => $organization, |
78
|
|
|
]); |
79
|
|
|
if (Yii::$app->request->isPost && $model->load(Yii::$app->request->post())) { |
80
|
|
|
if ($model->validate() && $model->submit()) { |
81
|
|
|
Yii::$app->session->setFlash(Module::SESSION_KEY_RESULT, Module::RESULT_SUCCESS); |
82
|
|
|
Yii::$app->session->setFlash(Module::SESSION_KEY_MESSAGE, '(' . $organization->profile->name . ' ' . $organization->getID() . ') ' . $this->updateSuccessMessage); |
|
|
|
|
83
|
|
|
return $this->controller->redirect(['settings', 'id' => $organization->getID()]); |
|
|
|
|
84
|
|
|
} |
85
|
|
|
Yii::$app->session->setFlash(Module::SESSION_KEY_RESULT, Module::RESULT_FAILED); |
86
|
|
|
Yii::$app->session->setFlash(Module::SESSION_KEY_MESSAGE, '(' . $organization->profile->name . ' ' . $organization->getID() . ') ' . $this->updateFailedMessage); |
|
|
|
|
87
|
|
|
} |
88
|
|
|
return $this->controller->render('settings', [ |
89
|
|
|
'organization' => $organization, |
90
|
|
|
'model' => $model |
91
|
|
|
]); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.