mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-28 09:40:41 +00:00
9559105b59
Change-Id: I2c10cb69f1f1726b63d25579c6a35c882cc1fe7e
69 lines
1.5 KiB
PHP
69 lines
1.5 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 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 ) {
|
|
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 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 ),
|
|
'notification_read_timestamp' => $this->readTimestamp,
|
|
);
|
|
|
|
$dbw->insert( 'echo_notification', $row, __METHOD__ );
|
|
}
|
|
}
|