forked from humhub-contrib/linklist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Module.php
145 lines (125 loc) · 4.02 KB
/
Module.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?php
namespace humhub\modules\linklist;
use Yii;
use humhub\modules\linklist\models\Link;
use humhub\modules\linklist\models\Category;
use humhub\modules\space\models\Space;
use humhub\modules\user\models\User;
use humhub\modules\content\components\ContentContainerActiveRecord;
use humhub\modules\content\components\ContentContainerModule;
class Module extends ContentContainerModule
{
/**
* @inheritdoc
*/
public function getContentContainerTypes()
{
return [
User::className(),
Space::className(),
];
}
/**
* @inheritdoc
*/
public function getContentContainerConfigUrl(ContentContainerActiveRecord $container)
{
return $container->createUrl('/linklist/linklist/config');
}
/**
* @inheritdoc
*/
public function disable()
{
foreach (Category::find()->all() as $category) {
$category->delete();
}
parent::disable();
}
/**
* @inheritdoc
*/
public function enableContentContainer(ContentContainerActiveRecord $container)
{
$container->setSetting('enableDeadLinkValidation', 0, 'linklist');
$container->setSetting('enableWidget', 0, 'linklist');
parent::enableContentContainer($container);
}
/**
* @inheritdoc
*/
public function disableContentContainer(ContentContainerActiveRecord $container)
{
parent::disableContentContainer($container);
foreach (Category::find()->contentContainer($container)->all() as $content) {
$content->delete();
}
foreach (Link::find()->contentContainer($container)->all() as $content) {
$content->delete();
}
}
/**
* Defines what to do if a spaces sidebar is initialzed.
*
* @param type $event
*/
public static function onSpaceSidebarInit($event)
{
$space = $event->sender->space;
if ($space->isModuleEnabled('linklist')) {
$event->sender->addWidget(widgets\Sidebar::className(), array('contentContainer' => $space), array(
'sortOrder' => 200,
));
}
}
/**
* On build of a Space Navigation, check if this module is enabled.
* When enabled add a menu item
*
* @param type $event
*/
public static function onSpaceMenuInit($event)
{
$space = $event->sender->space;
if ($space->isModuleEnabled('linklist') && $space->isMember()) {
$event->sender->addItem(array(
'label' => Yii::t('LinklistModule.base', 'Linklist'),
'url' => $space->createUrl('/linklist/linklist'),
'icon' => '<i class="fa fa-link"></i>',
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'linklist')
));
}
}
/**
* On build of a Profile Navigation, check if this module is enabled.
* When enabled add a menu item
*
* @param type $event
*/
public static function onProfileMenuInit($event)
{
$user = $event->sender->user;
// Is Module enabled on this workspace?
if ($user->isModuleEnabled('linklist') && !Yii::$app->user->isGuest && $user->id == Yii::$app->user->id) {
$event->sender->addItem(array(
'label' => Yii::t('LinklistModule.base', 'Linklist'),
'url' => $user->createUrl('/linklist/linklist'),
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'linklist'),
));
}
}
/**
* Defines what to do if a spaces sidebar is initialzed.
*
* @param type $event
*/
public static function onProfileSidebarInit($event)
{
$user = $event->sender->user;
if ($user->isModuleEnabled('linklist')) {
$event->sender->addWidget(widgets\Sidebar::className(), array('contentContainer' => $user), array(
'sortOrder' => 200,
));
}
}
}