2012-04-27 15:14:24 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class EchoNotification {
|
2013-03-05 01:31:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var User
|
|
|
|
*/
|
|
|
|
protected $user;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var EchoEvent
|
|
|
|
*/
|
|
|
|
protected $event;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $timestamp;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $readTimestamp;
|
2012-04-27 15:14:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Do not use this constructor.
|
|
|
|
*/
|
2013-03-05 01:31:41 +00:00
|
|
|
protected function __construct() {}
|
2012-04-27 15:14:24 +00:00
|
|
|
|
|
|
|
/**
|
2013-03-05 01:31:41 +00:00
|
|
|
* Creates an EchoNotification object based on event and user
|
|
|
|
* @param $info array The following keys are required:
|
|
|
|
* - 'event' The EchoEvent being notified about.
|
|
|
|
* - 'user' The User being notified.
|
2012-09-02 09:30:38 +00:00
|
|
|
* @throws MWException
|
|
|
|
* @return EchoNotification
|
2012-04-27 15:14:24 +00:00
|
|
|
*/
|
2013-03-05 01:31:41 +00:00
|
|
|
public static function create( array $info ) {
|
|
|
|
$obj = new EchoNotification();
|
2012-04-27 15:14:24 +00:00
|
|
|
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" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-05 01:31:41 +00:00
|
|
|
if ( !$obj->user instanceof User && !$obj->user instanceof StubObject ) {
|
|
|
|
throw new MWException( 'Invalid user parameter, expected: User/StubObject object' );
|
2012-04-27 15:14:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( !$obj->event instanceof EchoEvent ) {
|
2013-03-05 01:31:41 +00:00
|
|
|
throw new MWException( 'Invalid event parameter, expected: EchoEvent object' );
|
2012-04-27 15:14:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$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;
|
|
|
|
}
|
2013-03-05 01:31:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Getter method
|
|
|
|
* @return string Notification creation timestamp
|
|
|
|
*/
|
|
|
|
public function getTimestamp() {
|
|
|
|
return $this->timestamp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Getter method
|
|
|
|
* @return string|null Notification read timestamp
|
|
|
|
*/
|
|
|
|
public function getReadTimestamp() {
|
|
|
|
return $this->readTimestamp;
|
|
|
|
}
|
2012-08-30 16:04:39 +00:00
|
|
|
}
|