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\RevokePreventedException; |
16
|
|
|
use rhosocial\organization\web\organization\Module; |
17
|
|
|
use Yii; |
18
|
|
|
use yii\base\Action; |
19
|
|
|
use yii\base\InvalidParamException; |
20
|
|
|
use yii\web\BadRequestHttpException; |
21
|
|
|
use yii\web\ServerErrorHttpException; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @version 1.0 |
25
|
|
|
* @author vistart <[email protected]> |
26
|
|
|
*/ |
27
|
|
|
class RevokeAction extends Action |
28
|
|
|
{ |
29
|
|
|
public $organizationRevokeSuccessMessage; |
30
|
|
|
public $organizationRevokeFailedMessage; |
31
|
|
|
|
32
|
|
|
protected function initMessages() |
33
|
|
|
{ |
34
|
|
|
if (!is_string($this->organizationRevokeSuccessMessage)) { |
35
|
|
|
$this->organizationRevokeSuccessMessage = Yii::t('organization', 'Successfully revoked.'); |
36
|
|
|
} |
37
|
|
|
if (!is_string($this->organizationRevokeFailedMessage)) { |
38
|
|
|
$this->organizationRevokeFailedMessage = Yii::t('organization', 'Failed to revoke.'); |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function init() |
43
|
|
|
{ |
44
|
|
|
$this->initMessages(); |
45
|
|
|
parent::init(); |
46
|
|
|
} |
47
|
|
|
/** |
48
|
|
|
* Revoke organization or department. |
49
|
|
|
* @param string|integer $id |
50
|
|
|
* @throws ServerErrorHttpException |
51
|
|
|
*/ |
52
|
|
|
public function run($id) |
53
|
|
|
{ |
54
|
|
|
try { |
55
|
|
|
Yii::$app->user->identity->revokeOrganization($id, true); |
56
|
|
|
} catch (InvalidParamException $ex) { |
57
|
|
|
throw new BadRequestHttpException(Yii::t('organization', $ex->getMessage())); |
58
|
|
|
} catch (RevokePreventedException $ex) { |
59
|
|
|
throw new BadRequestHttpException(Yii::t('organization', $ex->getMessage())); |
60
|
|
|
} catch (\Exception $ex) { |
61
|
|
|
throw new ServerErrorHttpException($ex->getMessage()); |
62
|
|
|
} |
63
|
|
|
Yii::$app->session->setFlash(Module::SESSION_KEY_RESULT, Module::RESULT_SUCCESS); |
64
|
|
|
Yii::$app->session->setFlash(Module::SESSION_KEY_MESSAGE, "($id) " . $this->organizationRevokeSuccessMessage); |
65
|
|
|
return $this->controller->redirect(['index']); |
|
|
|
|
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
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: