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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-11-26 22:57:28 +00:00
|
|
|
* Adds this new notification object to the database.
|
2012-04-27 15:14:24 +00:00
|
|
|
*/
|
|
|
|
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
|
|
|
}
|