forked from humhub-contrib/notes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NotesModule.php
99 lines (86 loc) · 2.52 KB
/
NotesModule.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
<?php
class NotesModule extends HWebModule
{
/**
* Inits the Module
*/
public function init()
{
$this->setImport(array(
'notes.models.*',
'notes.behaviors.*',
'notes.widgets.*',
'wall.*',
));
}
public function behaviors()
{
return array(
'SpaceModuleBehavior' => array(
'class' => 'application.modules_core.space.behaviors.SpaceModuleBehavior',
),
);
}
public function getConfigUrl()
{
return Yii::app()->createUrl('//notes/noteConfig/index');
}
/**
* On global module disable
*/
public function disable()
{
if (parent::disable()) {
foreach (Content::model()->findAllByAttributes(array('object_model' => 'Note')) as $content) {
$content->delete();
}
return true;
}
return false;
}
/**
* On disabling this module on a space, deleted all module -> space
* related content.
*
* Method sub is provided by "SpaceModuleBehavior"
*
* @param Space $space
*/
public function disableSpaceModule(Space $space)
{
foreach (Content::model()->findAllByAttributes(array('space_id' => $space->id, 'object_model' => 'Note')) as $content) {
$content->delete();
}
}
/**
* 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 = Yii::app()->getController()->getSpace();
// Is Module enabled on this workspace?
if ($space->isModuleEnabled('notes')) {
$event->sender->addItem(array(
'label' => Yii::t('NotesModule.base', 'Notes'),
'group' => 'modules',
'url' => Yii::app()->createUrl('/notes/note/show', array('guid' => $space->guid)),
'icon' => '<i class="fa fa-file-text"></i>',
'isActive' => (Yii::app()->controller->module && Yii::app()->controller->module->id == 'notes'),
));
}
}
/**
* On User delete, do some cleanup stuff
* Own Notes (Content) by the user are automatically deleted!
*
* @param type $event
*/
public static function onUserDelete($event)
{
NoteUserColors::model()->deleteAllByAttributes(array('user_id' => $event->sender->id));
return true;
}
}