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\NumberOfOrganizationsExceededException; |
16
|
|
|
use rhosocial\organization\forms\SetUpForm; |
17
|
|
|
use rhosocial\organization\web\organization\Module; |
18
|
|
|
use Yii; |
19
|
|
|
use yii\base\Action; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @version 1.0 |
23
|
|
|
* @author vistart <[email protected]> |
24
|
|
|
*/ |
25
|
|
|
class SetUpOrganizationAction extends Action |
26
|
|
|
{ |
27
|
|
|
public $organizationSetUpSuccessMessage; |
28
|
|
|
public $organizationSetUpFailedMessage; |
29
|
|
|
|
30
|
|
|
protected function initMessages() |
31
|
|
|
{ |
32
|
|
|
if (!is_string($this->organizationSetUpSuccessMessage)) { |
33
|
|
|
$this->organizationSetUpSuccessMessage = Yii::t('organization' ,'Organization Set Up.'); |
34
|
|
|
} |
35
|
|
|
if (!is_string($this->organizationSetUpFailedMessage)) { |
36
|
|
|
$this->organizationSetUpFailedMessage = Yii::t('organization', 'Organization Set Up Failed.'); |
37
|
|
|
} |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function init() |
41
|
|
|
{ |
42
|
|
|
$this->initMessages(); |
43
|
|
|
parent::init(); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function run() |
47
|
|
|
{ |
48
|
|
|
$user = Yii::$app->user->identity; |
49
|
|
|
if ($user->hasReachedOrganizationLimit()) { |
50
|
|
|
throw new NumberOfOrganizationsExceededException(); |
51
|
|
|
} |
52
|
|
|
$model = new SetUpForm(['user' => $user]); |
53
|
|
|
if ($model->load(Yii::$app->request->post())) { |
54
|
|
|
try { |
55
|
|
|
if (($result = $model->setUpOrganization()) === true) { |
56
|
|
|
Yii::$app->session->setFlash(Module::SESSION_KEY_RESULT, Module::RESULT_SUCCESS); |
57
|
|
|
Yii::$app->session->setFlash(Module::SESSION_KEY_MESSAGE, '(' . $model->getUser()->lastSetUpOrganization->getID() . ') ' . $this->organizationSetUpSuccessMessage); |
58
|
|
|
return $this->controller->redirect(['index']); |
|
|
|
|
59
|
|
|
} |
60
|
|
|
if ($result instanceof \Exception) { |
61
|
|
|
throw $result; |
62
|
|
|
} |
63
|
|
|
} catch (\Exception $ex) { |
64
|
|
|
Yii::error($ex->getMessage(), __METHOD__); |
65
|
|
|
Yii::$app->session->setFlash(Module::SESSION_KEY_RESULT, Module::RESULT_FAILED); |
66
|
|
|
Yii::$app->session->setFlash(Module::SESSION_KEY_MESSAGE, $this->organizationSetUpFailedMessage); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
return $this->controller->render('set-up-organization', ['model' => $model]); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
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: