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\Profile; |
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 UpdateAction |
24
|
|
|
* @package rhosocial\organization\web\organization\controllers\my |
25
|
|
|
* @version 1.0 |
26
|
|
|
* @author vistart <[email protected]> |
27
|
|
|
*/ |
28
|
|
|
class UpdateAction extends Action |
29
|
|
|
{ |
30
|
|
|
public $updateSuccessMessage; |
31
|
|
|
public $updateFailedMessage; |
32
|
|
|
|
33
|
|
|
protected function initMessages() |
34
|
|
|
{ |
35
|
|
|
if (!is_string($this->updateSuccessMessage)) { |
36
|
|
|
$this->updateSuccessMessage = Yii::t('user' ,'Updated.'); |
37
|
|
|
} |
38
|
|
|
if (!is_string($this->updateFailedMessage)) { |
39
|
|
|
$this->updateFailedMessage = Yii::t('user', 'Failed to Update.'); |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function init() |
44
|
|
|
{ |
45
|
|
|
$this->initMessages(); |
46
|
|
|
parent::init(); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Check access. |
51
|
|
|
* @param $org |
52
|
|
|
* @param $user |
53
|
|
|
* @return bool |
54
|
|
|
* @throws UnauthorizedManageProfileException |
55
|
|
|
*/ |
56
|
|
|
public static function checkAccess($org, $user) |
57
|
|
|
{ |
58
|
|
|
MemberAction::checkAccess($org, $user); |
59
|
|
|
if (!Yii::$app->authManager->checkAccess($user->getGUID(), (new ManageProfile)->name, ['organization' => $org])) { |
60
|
|
|
throw new UnauthorizedManageProfileException(); |
61
|
|
|
} |
62
|
|
|
return true; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param $id |
67
|
|
|
* @return string |
68
|
|
|
*/ |
69
|
|
|
public function run($id) |
70
|
|
|
{ |
71
|
|
|
$org = Module::getOrganization($id); |
72
|
|
|
$user = Yii::$app->user->identity; |
73
|
|
|
static::checkAccess($org, $user); |
74
|
|
|
|
75
|
|
|
$profile = $org->profile; |
76
|
|
|
if (!$profile) { |
77
|
|
|
$profile = $org->createProfile(); |
78
|
|
|
} |
79
|
|
|
$profile->scenario = Profile::SCENARIO_UPDATE; |
80
|
|
|
if ($profile->load(Yii::$app->request->post())) { |
81
|
|
|
if ($profile->save()) { |
82
|
|
|
Yii::$app->session->setFlash(Module::SESSION_KEY_RESULT, Module::RESULT_SUCCESS); |
83
|
|
|
Yii::$app->session->setFlash(Module::SESSION_KEY_MESSAGE, '(' . $org->getID() . ') ' . $this->updateSuccessMessage); |
84
|
|
|
return $this->controller->redirect(['update', 'id' => $org->getID()]); |
|
|
|
|
85
|
|
|
} |
86
|
|
|
Yii::$app->session->setFlash(Module::SESSION_KEY_RESULT, Module::RESULT_FAILED); |
87
|
|
|
Yii::$app->session->setFlash(Module::SESSION_KEY_MESSAGE, '(' . $org->getID() . ') ' . $this->updateFailedMessage); |
88
|
|
|
} |
89
|
|
|
return $this->controller->render('update', ['organization' => $org, 'model' => $profile]); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: