2012-04-27 15:14:24 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
// @todo Fill in
|
|
|
|
class EchoNotifier {
|
|
|
|
/**
|
|
|
|
* Record an EchoNotification for an EchoEvent.
|
|
|
|
*
|
2012-09-02 09:30:38 +00:00
|
|
|
* @param $user User to notify.
|
|
|
|
* @param $event EchoEvent to notify about.
|
2012-04-27 15:14:24 +00:00
|
|
|
*/
|
|
|
|
public static function notifyWithNotification( $user, $event ) {
|
2012-08-31 21:50:46 +00:00
|
|
|
EchoNotification::create( array( 'user' => $user, 'event' => $event ) );
|
2012-12-19 02:16:52 +00:00
|
|
|
EchoNotificationController::resetNotificationCount( $user, DB_MASTER );
|
2012-04-27 15:14:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send a Notification to a user by email
|
|
|
|
*
|
2012-09-02 09:30:38 +00:00
|
|
|
* @param $user User to notify.
|
|
|
|
* @param $event EchoEvent to notify about.
|
|
|
|
* @return bool
|
2012-04-27 15:14:24 +00:00
|
|
|
*/
|
|
|
|
public static function notifyWithEmail( $user, $event ) {
|
2012-08-31 21:50:46 +00:00
|
|
|
if ( !$user->isEmailConfirmed() ) {
|
2012-05-17 15:36:18 +00:00
|
|
|
// No valid email address
|
|
|
|
return false;
|
|
|
|
}
|
2012-11-16 21:03:57 +00:00
|
|
|
// See if the user wants to receive emails for this type of event
|
|
|
|
if ( $user->getOption( 'echo-email-notifications' . $event->getType() ) ) {
|
|
|
|
global $wgEchoEnableEmailBatch, $wgEchoEventDetails, $wgPasswordSender, $wgPasswordSenderName;
|
|
|
|
|
|
|
|
// batched email notification
|
|
|
|
if ( $wgEchoEnableEmailBatch && $user->getOption( 'echo-email-frequency' ) > 0 ) {
|
|
|
|
// default priority is 10
|
|
|
|
$priority = 10;
|
|
|
|
if ( isset( $wgEchoEventDetails[$event->getType()]['priority'] ) ) {
|
|
|
|
$priority = $wgEchoEventDetails[$event->getType()]['priority'];
|
|
|
|
}
|
|
|
|
MWEchoEmailBatch::addToQueue( $user->getId(), $event->getId(), $priority );
|
|
|
|
return true;
|
2012-11-27 01:53:35 +00:00
|
|
|
}
|
2012-11-16 21:03:57 +00:00
|
|
|
// no email notification
|
|
|
|
if ( $user->getOption( 'echo-email-frequency' ) < 0 ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// instant email notification
|
|
|
|
$adminAddress = new MailAddress( $wgPasswordSender, $wgPasswordSenderName );
|
|
|
|
$address = new MailAddress( $user );
|
|
|
|
$email = EchoNotificationController::formatNotification( $event, $user, 'email' );
|
|
|
|
$subject = $email['subject'];
|
|
|
|
$body = $email['body'];
|
|
|
|
|
|
|
|
UserMailer::send( $address, $adminAddress, $subject, $body );
|
2012-11-27 01:53:35 +00:00
|
|
|
}
|
|
|
|
|
2012-09-02 09:30:38 +00:00
|
|
|
return true;
|
2012-04-27 15:14:24 +00:00
|
|
|
}
|
2012-08-30 16:04:39 +00:00
|
|
|
}
|