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