|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @copyright Copyright (c) Flipbox Digital Limited |
|
5
|
|
|
* @license https://flipboxfactory.com/software/organization/license |
|
6
|
|
|
* @link https://www.flipboxfactory.com/software/organization/ |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace flipbox\organizations\cp\controllers; |
|
10
|
|
|
|
|
11
|
|
|
use Craft; |
|
12
|
|
|
use craft\controllers\ElementIndexesController; |
|
13
|
|
|
use craft\elements\User; |
|
14
|
|
|
use craft\events\RegisterElementHtmlAttributesEvent; |
|
15
|
|
|
use flipbox\organizations\events\handlers\RegisterOrganizationUserElementActions; |
|
16
|
|
|
use flipbox\organizations\events\handlers\RegisterOrganizationUserElementDefaultTableAttributes; |
|
17
|
|
|
use flipbox\organizations\events\handlers\RegisterOrganizationUserElementTableAttributes; |
|
18
|
|
|
use flipbox\organizations\events\handlers\SetOrganizationUserElementTableAttributeHtml; |
|
19
|
|
|
use yii\base\Event; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @author Flipbox Factory <[email protected]> |
|
23
|
|
|
* @since 1.0.0 |
|
24
|
|
|
*/ |
|
25
|
|
|
class UserIndexesController extends ElementIndexesController |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* @inheritdoc |
|
29
|
|
|
*/ |
|
30
|
|
|
public function init() |
|
31
|
|
|
{ |
|
32
|
|
|
Event::on( |
|
33
|
|
|
User::class, |
|
34
|
|
|
User::EVENT_REGISTER_ACTIONS, |
|
35
|
|
|
[ |
|
36
|
|
|
RegisterOrganizationUserElementActions::class, |
|
37
|
|
|
'handle' |
|
38
|
|
|
] |
|
39
|
|
|
); |
|
40
|
|
|
|
|
41
|
|
|
// Add attributes the user index |
|
42
|
|
|
Event::on( |
|
43
|
|
|
User::class, |
|
44
|
|
|
User::EVENT_REGISTER_DEFAULT_TABLE_ATTRIBUTES, |
|
45
|
|
|
[ |
|
46
|
|
|
RegisterOrganizationUserElementDefaultTableAttributes::class, |
|
47
|
|
|
'handle' |
|
48
|
|
|
] |
|
49
|
|
|
); |
|
50
|
|
|
|
|
51
|
|
|
// Add attributes the user index |
|
52
|
|
|
Event::on( |
|
53
|
|
|
User::class, |
|
54
|
|
|
User::EVENT_REGISTER_TABLE_ATTRIBUTES, |
|
55
|
|
|
[ |
|
56
|
|
|
RegisterOrganizationUserElementTableAttributes::class, |
|
57
|
|
|
'handle' |
|
58
|
|
|
] |
|
59
|
|
|
); |
|
60
|
|
|
|
|
61
|
|
|
// Add 'organizations' on the user html element |
|
62
|
|
|
Event::on( |
|
63
|
|
|
User::class, |
|
64
|
|
|
User::EVENT_SET_TABLE_ATTRIBUTE_HTML, |
|
65
|
|
|
[ |
|
66
|
|
|
SetOrganizationUserElementTableAttributeHtml::class, |
|
67
|
|
|
'handle' |
|
68
|
|
|
] |
|
69
|
|
|
); |
|
70
|
|
|
|
|
71
|
|
|
// Add 'organizations' on the user html element |
|
72
|
|
|
Event::on( |
|
73
|
|
|
User::class, |
|
74
|
|
|
User::EVENT_REGISTER_HTML_ATTRIBUTES, |
|
75
|
|
|
function (RegisterElementHtmlAttributesEvent $event) { |
|
76
|
|
|
$event->htmlAttributes['data-organization'] = $event->data['organization'] ?? null; |
|
77
|
|
|
}, |
|
78
|
|
|
[ |
|
79
|
|
|
'organization' => $this->getOrganizationFromRequest() |
|
80
|
|
|
] |
|
81
|
|
|
); |
|
82
|
|
|
|
|
83
|
|
|
parent::init(); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @inheritDoc |
|
88
|
|
|
*/ |
|
89
|
|
|
protected function includeActions(): bool |
|
90
|
|
|
{ |
|
91
|
|
|
return true; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @return mixed |
|
96
|
|
|
*/ |
|
97
|
|
|
private function getOrganizationFromRequest() |
|
98
|
|
|
{ |
|
99
|
|
|
return Craft::$app->getRequest()->getParam('organization'); |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|