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