mediawiki-extensions-Echo/model/Notification.php
bsitu fc5c341692 Add first version of EventLogging schema to Echo
Change-Id: I4b6033ffc2ec8d1597f2b447f100c58a8c3a7f3e
2013-03-01 15:53:07 -08:00

86 lines
1.8 KiB
PHP

<?php
class EchoNotification {
protected $id = false;
protected $user = false;
protected $event = false;
protected $timestamp = false;
protected $readTimestamp = null;
/**
* Do not use this constructor.
*/
protected function __construct() {
}
/**
* Creates an EchoNotification object
* @param $info array Named arguments:
* event: (required) The EchoEvent being notified about.
* user: (required) The User being notified.
*
* @throws MWException
* @return EchoNotification
*/
public static function create( $info = array() ) {
$obj = new EchoNotification;
static $validFields = array( 'event', 'user' );
$obj->timestamp = wfTimestampNow();
foreach ( $validFields as $field ) {
if ( isset( $info[$field] ) ) {
$obj->$field = $info[$field];
} else {
throw new MWException( "Field $field is required" );
}
}
if ( !$obj->user instanceof User &&
!$obj->user instanceof StubObject
) {
throw new MWException( "Invalid user parameter: " . get_class( $obj->user ) );
}
if ( !$obj->event instanceof EchoEvent ) {
throw new MWException( "Invalid event parameter" );
}
$obj->insert();
return $obj;
}
/**
* Adds this new notification object to the backend storage.
*/
protected function insert() {
global $wgEchoBackend;
$row = array(
'notification_event' => $this->event->getId(),
'notification_user' => $this->user->getId(),
'notification_timestamp' => $this->timestamp,
'notification_read_timestamp' => $this->readTimestamp,
);
$wgEchoBackend->createNotification( $row );
}
/**
* Getter method
* @return EchoEvent The event for this notification
*/
public function getEvent() {
return $this->event;
}
/**
* Getter method
* @return User The recipient of this notification
*/
public function getUser() {
return $this->user;
}
}