|
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\NotMemberOfOrganizationException; |
|
16
|
|
|
use rhosocial\organization\Member; |
|
17
|
|
|
use rhosocial\organization\web\organization\Module; |
|
18
|
|
|
use rhosocial\user\User; |
|
19
|
|
|
use Yii; |
|
20
|
|
|
use yii\base\Action; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Class RemoveMemberAction |
|
24
|
|
|
* @package rhosocial\organization\web\organization\controllers\my |
|
25
|
|
|
* @version 1.0 |
|
26
|
|
|
* @author vistart <[email protected]> |
|
27
|
|
|
*/ |
|
28
|
|
|
class RemoveMemberAction extends Action |
|
29
|
|
|
{ |
|
30
|
|
|
public $removeMemberSuccessMessage; |
|
31
|
|
|
public $removeMemberFailedMessage; |
|
32
|
|
|
|
|
33
|
|
|
protected function initMessages() |
|
34
|
|
|
{ |
|
35
|
|
|
if (!is_string($this->removeMemberSuccessMessage)) { |
|
36
|
|
|
$this->removeMemberSuccessMessage = Yii::t('organization' ,'Member Removed.'); |
|
37
|
|
|
} |
|
38
|
|
|
if (!is_string($this->removeMemberFailedMessage)) { |
|
39
|
|
|
$this->removeMemberFailedMessage = Yii::t('organization', 'Failed to Remove.'); |
|
40
|
|
|
} |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function init() |
|
44
|
|
|
{ |
|
45
|
|
|
$this->initMessages(); |
|
46
|
|
|
parent::init(); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Check access. |
|
51
|
|
|
* @param Organization $org |
|
52
|
|
|
* @param string|integer $id User ID. If access checking passed, it will be re-assigned with the User model. |
|
53
|
|
|
* @param User $user |
|
54
|
|
|
* @return boolean |
|
55
|
|
|
* @throws NotMemberOfOrganizationException |
|
56
|
|
|
*/ |
|
57
|
|
|
public static function checkAccess($org, &$id, $user) |
|
58
|
|
|
{ |
|
59
|
|
|
AddMemberAction::checkAccess($org, $user); |
|
60
|
|
|
$member = Member::find()->organization($org)->user($id)->one(); |
|
61
|
|
|
/* @var $member Member */ |
|
62
|
|
|
if (!$member) { |
|
63
|
|
|
throw new NotMemberOfOrganizationException(); |
|
64
|
|
|
} |
|
65
|
|
|
$id = $member->memberUser; |
|
66
|
|
|
return true; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @param $org |
|
71
|
|
|
* @param $user |
|
72
|
|
|
* @return \yii\web\Response |
|
73
|
|
|
*/ |
|
74
|
|
|
public function run($org, $user) |
|
75
|
|
|
{ |
|
76
|
|
|
$org = Module::getOrganization($org); |
|
77
|
|
|
$id = $user; |
|
78
|
|
|
if (!static::checkAccess($org, $user, Yii::$app->user->identity)) { |
|
|
|
|
|
|
79
|
|
|
return $this->controller->redirect(['index']); |
|
|
|
|
|
|
80
|
|
|
} |
|
81
|
|
|
if ($org->removeMember($user)) { |
|
|
|
|
|
|
82
|
|
|
Yii::$app->session->setFlash(Module::SESSION_KEY_RESULT, Module::RESULT_SUCCESS); |
|
83
|
|
|
Yii::$app->session->setFlash(Module::SESSION_KEY_MESSAGE, '(' . $id . ') ' . $this->removeMemberSuccessMessage); |
|
84
|
|
|
return $this->controller->redirect(['member', 'org' => $org->getID()]); |
|
85
|
|
|
} |
|
86
|
|
|
Yii::$app->session->setFlash(Module::SESSION_KEY_RESULT, Module::RESULT_FAILED); |
|
87
|
|
|
Yii::$app->session->setFlash(Module::SESSION_KEY_MESSAGE, '(' . $id . ') ' . $this->removeMemberFailedMessage); |
|
88
|
|
|
return $this->controller->redirect(['member', 'org' => $org->getID()]); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: