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-07-17 20:39:45 +00:00
|
|
|
EchoNotificationController::resetNotificationCount( $user );
|
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-27 01:53:35 +00:00
|
|
|
global $wgEchoEnableEmailBatch, $wgEchoEventDetails, $wgPasswordSender, $wgPasswordSenderName;
|
2012-05-17 15:36:18 +00:00
|
|
|
|
2012-11-27 01:53:35 +00:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
// no email notification
|
|
|
|
if ( $user->getOption( 'echo-email-frequency' ) < 0 ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// instant email notification
|
2012-05-17 15:36:18 +00:00
|
|
|
$adminAddress = new MailAddress( $wgPasswordSender, $wgPasswordSenderName );
|
|
|
|
$address = new MailAddress( $user );
|
|
|
|
$email = EchoNotificationController::formatNotification( $event, $user, 'email' );
|
|
|
|
$subject = $email['subject'];
|
|
|
|
$body = $email['body'];
|
|
|
|
|
2012-08-30 16:04:39 +00:00
|
|
|
UserMailer::send( $address, $adminAddress, $subject, $body );
|
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
|
|
|
}
|