|
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
|
|
|
* @param Organization $org |
|
33
|
|
|
* @param User $user |
|
34
|
|
|
* @return boolean |
|
35
|
|
|
* @throws NotMemberOfOrganizationException |
|
36
|
|
|
*/ |
|
37
|
|
|
public static function checkAccess($org, $user) |
|
38
|
|
|
{ |
|
39
|
|
|
if (!$org) { |
|
40
|
|
|
throw new OrganizationNotFoundException(); |
|
41
|
|
|
} |
|
42
|
|
|
if (!$org->hasMember($user)) { |
|
43
|
|
|
throw new NotMemberOfOrganizationException(); |
|
44
|
|
|
} |
|
45
|
|
|
return true; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* |
|
50
|
|
|
* @param Organization|string|integer $org |
|
51
|
|
|
*/ |
|
52
|
|
|
public function run($org) |
|
53
|
|
|
{ |
|
54
|
|
|
$organization = Module::getOrganization($org); |
|
55
|
|
|
$user = Yii::$app->user->identity; |
|
56
|
|
|
static::checkAccess($organization, $user); |
|
57
|
|
|
$dataProvider = new ActiveDataProvider([ |
|
58
|
|
|
'query' => $organization->getMembers(), |
|
59
|
|
|
'pagination' => [ |
|
60
|
|
|
'pageParam' => 'member-param', |
|
61
|
|
|
'pageSizeParam' => 'member-per-param', |
|
62
|
|
|
], |
|
63
|
|
|
'sort' => [ |
|
64
|
|
|
'sortParam' => 'member-sort', |
|
65
|
|
|
'attributes' => [ |
|
66
|
|
|
'id', |
|
67
|
|
|
], |
|
68
|
|
|
], |
|
69
|
|
|
]); |
|
70
|
|
|
|
|
71
|
|
|
return $this->controller->render('member', ['dataProvider' => $dataProvider]); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|