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
|
2012-09-02 09:30:38 +00:00
|
|
|
* @param $info array Named arguments:
|
2012-04-27 15:14:24 +00:00
|
|
|
* event: (required) The EchoEvent being notified about.
|
|
|
|
* user: (required) The User being notified.
|
|
|
|
*
|
2012-09-02 09:30:38 +00:00
|
|
|
* @throws MWException
|
|
|
|
* @return EchoNotification
|
2012-04-27 15:14:24 +00:00
|
|
|
*/
|
|
|
|
public static function create( $info = array() ) {
|
|
|
|
$obj = new EchoNotification;
|
|
|
|
static $validFields = array( 'event', 'user' );
|
|
|
|
|
|
|
|
$obj->timestamp = wfTimestampNow();
|
|
|
|
|
2012-08-31 21:50:46 +00:00
|
|
|
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" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-31 21:50:46 +00:00
|
|
|
if ( !$obj->user instanceof User &&
|
|
|
|
!$obj->user instanceof StubObject
|
2012-04-27 15:14:24 +00:00
|
|
|
) {
|
2012-08-31 21:50:46 +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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-01-15 23:21:39 +00:00
|
|
|
* Adds this new notification object to the backend storage.
|
2012-04-27 15:14:24 +00:00
|
|
|
*/
|
|
|
|
protected function insert() {
|
2013-01-15 23:21:39 +00:00
|
|
|
global $wgEchoBackend;
|
2012-04-27 15:14:24 +00:00
|
|
|
|
|
|
|
$row = array(
|
|
|
|
'notification_event' => $this->event->getId(),
|
|
|
|
'notification_user' => $this->user->getId(),
|
2013-01-15 23:21:39 +00:00
|
|
|
'notification_timestamp' => $this->timestamp,
|
2012-08-01 19:53:05 +00:00
|
|
|
'notification_read_timestamp' => $this->readTimestamp,
|
2012-04-27 15:14:24 +00:00
|
|
|
);
|
|
|
|
|
2013-01-15 23:21:39 +00:00
|
|
|
$wgEchoBackend->createNotification( $row );
|
2012-04-27 15:14:24 +00:00
|
|
|
}
|
2013-03-01 00:26:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
2012-08-30 16:04:39 +00:00
|
|
|
}
|