This repository has been archived by the owner on Oct 26, 2020. It is now read-only.
forked from humhub/mail
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMailModule.php
98 lines (80 loc) · 2.66 KB
/
MailModule.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
<?php
/**
* MailModule provides messaging functions inside the application.
*
* @package humhub.modules.mail
* @since 0.5
*/
class MailModule extends HWebModule
{
public function init()
{
$this->setImport(array(
'mail.models.*',
'mail.controllers.*',
'mail.behaviors.*',
'mail.forms.*',
));
}
/**
* On User delete, also delete all comments
*
* @param type $event
*/
public static function onUserDelete($event)
{
Yii::import('application.modules.mail.models.*');
// Delete all message entries
foreach (MessageEntry::model()->findAllByAttributes(array('user_id' => $event->sender->id)) as $messageEntry) {
$messageEntry->delete();
}
// Leaves all my conversations
foreach (UserMessage::model()->findAllByAttributes(array('user_id' => $event->sender->id)) as $userMessage) {
$userMessage->message->leave($event->sender->id);
}
return true;
}
/**
* On run of integrity check command, validate all module data
*
* @param type $event
*/
public static function onIntegrityCheck($event)
{
$integrityChecker = $event->sender;
#$integrityChecker->showTestHeadline("Validating Mail Module (" . Message::model()->count() . " entries)");
}
/**
* On build of the TopMenu, check if module is enabled
* When enabled add a menu item
*
* @param type $event
*/
public static function onTopMenuInit($event)
{
if (Yii::app()->user->isGuest) {
return;
}
$event->sender->addItem(array(
'label' => Yii::t('MailModule.base', 'Messages'),
'url' => Yii::app()->createUrl('//mail/mail/index', array()),
'icon' => '<i class="fa fa-envelope"></i>',
'isActive' => (Yii::app()->controller->module && Yii::app()->controller->module->id == 'mail'),
'sortOrder' => 300,
));
}
public static function onNotificationAddonInit($event)
{
if (Yii::app()->user->isGuest) {
return;
}
$event->sender->addWidget('application.modules.mail.widgets.MailNotificationWidget', array(), array('sortOrder' => 90));
}
public static function onProfileHeaderControlsInit($event)
{
if (Yii::app()->user->isGuest || $event->sender->user->id == Yii::app()->user->id) {
return;
}
$event->sender->addWidget('application.modules.mail.widgets.NewMessageButtonWidget', array('guid' => $event->sender->user->guid, 'type' => 'success'), array('sortOrder' => 90));
}
}