-
Notifications
You must be signed in to change notification settings - Fork 2
/
FavoriteModule.php
executable file
·117 lines (107 loc) · 3.4 KB
/
FavoriteModule.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
<?php
/**
* This module provides favorite support for content and content addons
* Each wall entry will get a favorite button.
*
* @author Anton Kurnitzky
*/
class FavoriteModule extends HWebModule
{
/**
* On User delete, also delete all corresponding favorites of this user
*
* @param type $event
*/
public static function onUserDelete($event)
{
foreach (Favorite::model()->findAllByAttributes(array('created_by' => $event->sender->id)) as $favorite) {
$favorite->delete();
}
}
/**
* On delete of a content object, also delete all corresponding favorites
*
* @param $event
*/
public static function onContentDelete($event)
{
foreach (Favorite::model()->findAllByAttributes(array('object_id' => $event->sender->id, 'object_model' => get_class($event->sender))) as $favorites) {
$favorites->delete();
}
}
/**
* On delete of a content addon object, e.g. a poll
* also delete all favorites
*
* @param $event
*/
public static function onContentAddonDelete($event)
{
foreach (Favorite::model()->findAllByAttributes(array('object_id' => $event->sender->id, 'object_model' => get_class($event->sender))) as $favorites) {
$favorites->delete();
}
}
/**
* On run of integrity check command, validate all module data
*
* @param type $event
*/
public static function onIntegrityCheck($event)
{
$integrityChecker = $event->sender;
$integrityChecker->showTestHeadline("Validating Favorite Module (" . Favorite::model()->count() . " entries)");
}
/**
* On initializing the wall entry controls also add the favorite link widget
*
* @param type $event
*/
public static function onWallEntryLinksInit($event)
{
$event->sender->addWidget('application.modules.favorite.widgets.FavoriteLinkWidget', array('object' => $event->sender->object), array('sortOrder' => 10));
}
/**
* On init of the wall entry addons, add a overview of existing favorites
*
* @param type $event
*/
public static function onWallEntryAddonInit($event)
{
}
/**
* Show a favorite menu inside the Space-Menu
* Here the user can see all his favorites inside this space
*
* @param type $event
*/
public static function onSpaceMenuInit($event)
{
$space = Yii::app()->getController()->getSpace();
if ($space->isModuleEnabled('favorite')) {
$event->sender->addItem(array(
'label' => Yii::t('FavoriteModule.base', 'Favorite'),
'group' => 'modules',
'url' => $space->createUrl('//favorite/favoriteWall/show'),
'icon' => '<i class="fa fa-star"></i>',
'isActive' => (Yii::app()->controller->module && Yii::app()->controller->module->id == 'favorite'),
'sortOrder' => 105,
));
}
}
public function init()
{
// import the module-level models and components
$this->setImport(array(
'favorite.models.*',
'favorite.behaviors.*',
));
}
public function behaviors()
{
return array(
'SpaceModuleBehavior' => array(
'class' => 'application.modules_core.space.behaviors.SpaceModuleBehavior',
),
);
}
}