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\exceptions\OrganizationNotFoundException; |
17
|
|
|
use rhosocial\organization\web\organization\Module; |
18
|
|
|
use rhosocial\organization\Organization; |
19
|
|
|
use rhosocial\user\User; |
20
|
|
|
use Yii; |
21
|
|
|
use yii\base\Action; |
22
|
|
|
use yii\data\ActiveDataProvider; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @version 1.0 |
26
|
|
|
* @author vistart <[email protected]> |
27
|
|
|
*/ |
28
|
|
|
class MemberAction extends Action |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* Check access. |
32
|
|
|
* Check whether the organization is valid or not. |
33
|
|
|
* The organization is null or new record, it will be considered as invalid. If so, the OrganizationNotFoundException |
34
|
|
|
* will be thrown. |
35
|
|
|
* |
36
|
|
|
* Check whether the organization has the member ($user). |
37
|
|
|
* If not, the NotMemberOfOrganizationException will be thrown. |
38
|
|
|
* |
39
|
|
|
* @param Organization $org |
40
|
|
|
* @param User $user |
41
|
|
|
* @return boolean |
42
|
|
|
* @throws OrganizationNotFoundException |
43
|
|
|
* @throws NotMemberOfOrganizationException |
44
|
|
|
*/ |
45
|
|
|
public static function checkAccess($org, $user) |
46
|
|
|
{ |
47
|
|
|
if (!$org || $org->getIsNewRecord()) { |
48
|
|
|
throw new OrganizationNotFoundException(); |
49
|
|
|
} |
50
|
|
|
if (!$org->hasMember($user)) { |
51
|
|
|
throw new NotMemberOfOrganizationException(); |
52
|
|
|
} |
53
|
|
|
return true; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Run action. |
58
|
|
|
* List all members of the organization or department. |
59
|
|
|
* @param Organization|string|integer $org |
60
|
|
|
* @return string rendering results. |
61
|
|
|
*/ |
62
|
|
|
public function run($org) |
63
|
|
|
{ |
64
|
|
|
$organization = Module::getOrganization($org); |
65
|
|
|
$user = Yii::$app->user->identity; |
66
|
|
|
static::checkAccess($organization, $user); |
67
|
|
|
$searchModel = $organization->getNoInitMember()->getSearchModel(); |
68
|
|
|
$searchModel->query = $searchModel->query->organization($organization); |
69
|
|
|
$dataProvider = new ActiveDataProvider([ |
|
|
|
|
70
|
|
|
'query' => $organization->getMembers(), |
71
|
|
|
'pagination' => [ |
72
|
|
|
'pageParam' => 'member-param', |
73
|
|
|
'defaultPageSize' => 20, |
74
|
|
|
'pageSizeParam' => 'member-per-param', |
75
|
|
|
], |
76
|
|
|
'sort' => [ |
77
|
|
|
'sortParam' => 'member-sort', |
78
|
|
|
'attributes' => [ |
79
|
|
|
'user_id', |
80
|
|
|
], |
81
|
|
|
], |
82
|
|
|
]); |
83
|
|
|
$dataProvider = $searchModel->search(Yii::$app->request->get()); |
84
|
|
|
return $this->controller->render('member', [ |
85
|
|
|
'dataProvider' => $dataProvider, |
86
|
|
|
'searchModel' => $searchModel, |
87
|
|
|
'organization' => $organization, |
88
|
|
|
'user' => Yii::$app->user->identity |
89
|
|
|
]); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.