2012-04-27 15:14:24 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class EchoNotification {
|
2012-08-01 19:53:05 +00:00
|
|
|
protected $id = false;
|
2012-04-27 15:14:24 +00:00
|
|
|
protected $user = false;
|
|
|
|
protected $event = false;
|
|
|
|
protected $timestamp = false;
|
2012-08-01 19:53:05 +00:00
|
|
|
protected $readTimestamp = null;
|
2012-04-27 15:14:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Do not use this constructor.
|
|
|
|
*/
|
|
|
|
protected function __construct() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an EchoNotification object
|
|
|
|
* @param $info Named arguments:
|
|
|
|
* event: (required) The EchoEvent being notified about.
|
|
|
|
* user: (required) The User being notified.
|
|
|
|
*
|
|
|
|
* @return The created EchoNotification.
|
|
|
|
*/
|
|
|
|
public static function create( $info = array() ) {
|
|
|
|
$obj = new EchoNotification;
|
|
|
|
static $validFields = array( 'event', 'user' );
|
|
|
|
|
|
|
|
$obj->timestamp = wfTimestampNow();
|
|
|
|
|
|
|
|
foreach( $validFields as $field ) {
|
2012-08-30 16:04:39 +00:00
|
|
|
if ( isset( $info[$field] ) ) {
|
2012-04-27 15:14:24 +00:00
|
|
|
$obj->$field = $info[$field];
|
|
|
|
} else {
|
|
|
|
throw new MWException( "Field $field is required" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! $obj->user instanceof User &&
|
|
|
|
! $obj->user instanceof StubObject
|
|
|
|
) {
|
2012-08-30 16:04:39 +00:00
|
|
|
throw new MWException( "Invalid user parameter: ".get_class( $obj->user ) );
|
2012-04-27 15:14:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( !$obj->event instanceof EchoEvent ) {
|
|
|
|
throw new MWException( "Invalid event parameter" );
|
|
|
|
}
|
|
|
|
|
|
|
|
$obj->insert();
|
|
|
|
|
|
|
|
return $obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds this new object to the database.
|
|
|
|
*/
|
|
|
|
protected function insert() {
|
|
|
|
$dbw = wfGetDB( DB_MASTER );
|
|
|
|
|
|
|
|
$row = array(
|
|
|
|
'notification_event' => $this->event->getId(),
|
|
|
|
'notification_user' => $this->user->getId(),
|
|
|
|
'notification_timestamp' => $dbw->timestamp( $this->timestamp ),
|
2012-08-01 19:53:05 +00:00
|
|
|
'notification_read_timestamp' => $this->readTimestamp,
|
2012-04-27 15:14:24 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$dbw->insert( 'echo_notification', $row, __METHOD__ );
|
|
|
|
}
|
2012-08-30 16:04:39 +00:00
|
|
|
}
|