2013-01-15 23:21:39 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Base backend class for accessing and saving echo notification data,
|
|
|
|
* this class should only provide all the necessary interfaces and
|
|
|
|
* implementation should be provided in each child class
|
|
|
|
*/
|
|
|
|
abstract class MWEchoBackend {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Factory to initialize a backend class
|
|
|
|
* @param $backend string
|
|
|
|
* @return MWEchoBackend
|
|
|
|
* @throws MWException
|
|
|
|
*/
|
|
|
|
public static function factory( $backend ) {
|
|
|
|
$backend = strval( $backend );
|
|
|
|
|
|
|
|
$className = 'MW' . $backend . 'EchoBackend';
|
|
|
|
|
|
|
|
if ( !class_exists( $className ) ) {
|
|
|
|
throw new MWException( "$backend backend is not supported" );
|
|
|
|
}
|
|
|
|
|
2013-04-19 03:12:29 +00:00
|
|
|
return new $className();
|
2013-01-15 23:21:39 +00:00
|
|
|
}
|
|
|
|
|
2013-05-03 23:58:56 +00:00
|
|
|
/**
|
|
|
|
* Extract the offset used for notification list
|
|
|
|
* @param $continue String Used for offset
|
|
|
|
* @param @return array
|
|
|
|
*/
|
|
|
|
protected function extractQueryOffset( $continue ) {
|
|
|
|
$offset = array (
|
|
|
|
'timestamp' => 0,
|
|
|
|
'offset' => 0,
|
|
|
|
);
|
|
|
|
if ( $continue ) {
|
|
|
|
$values = explode( '|', $continue, 3 );
|
|
|
|
if ( count( $values ) !== 2 ) {
|
|
|
|
throw new MWException( 'Invalid continue param: ' . $continue );
|
|
|
|
}
|
|
|
|
$offset['timestamp'] = (int)$values[0];
|
|
|
|
$offset['offset'] = (int)$values[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $offset;
|
|
|
|
}
|
|
|
|
|
2013-01-15 23:21:39 +00:00
|
|
|
/**
|
|
|
|
* Create a new notification
|
2013-05-26 02:44:09 +00:00
|
|
|
* @param $user User
|
2013-01-15 23:21:39 +00:00
|
|
|
* @param $row array
|
|
|
|
*/
|
2013-05-26 02:44:09 +00:00
|
|
|
abstract public function createNotification( $user, $row );
|
2013-01-15 23:21:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Load notifications based on the parameters
|
|
|
|
* @param $user User the user to get notifications for
|
|
|
|
* @param $limit int The maximum number of notifications to return
|
2013-05-03 23:58:56 +00:00
|
|
|
* @param $continue string Used for offset
|
|
|
|
* @param $outputFormat string The output format of the notifications (web, email, etc.)
|
2013-01-15 23:21:39 +00:00
|
|
|
* @return array
|
|
|
|
*/
|
2013-05-03 23:58:56 +00:00
|
|
|
abstract public function loadNotifications( $user, $limit, $continue, $outputFormat = 'web' );
|
2013-01-15 23:21:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the bundle data for user/hash
|
|
|
|
* @param $user User
|
|
|
|
* @param $bundleHash string The hash used to identify a set of bundle-able events
|
2013-03-06 00:04:48 +00:00
|
|
|
* @param $type string 'web'/'email'
|
2013-01-15 23:21:39 +00:00
|
|
|
* @return ResultWrapper|bool
|
|
|
|
*/
|
2013-03-06 00:04:48 +00:00
|
|
|
abstract public function getRawBundleData( $user, $bundleHash, $type = 'web' );
|
2013-01-15 23:21:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the last bundle stat - read_timestamp & bundle_display_hash
|
|
|
|
* @param $user User
|
|
|
|
* @param $bundleHash string The hash used to identify a set of bundle-able events
|
|
|
|
* @return ResultWrapper|bool
|
|
|
|
*/
|
|
|
|
abstract public function getLastBundleStat( $user, $bundleHash );
|
2013-01-15 23:21:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create an Echo event
|
|
|
|
* @param $row array
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
abstract public function createEvent( $row );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load an Echo event
|
|
|
|
* @param $id int
|
|
|
|
* @param $fromMaster bool
|
|
|
|
*/
|
|
|
|
abstract public function loadEvent( $id, $fromMaster );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the extra data for an Echo event
|
|
|
|
* @param $event EchoEvent
|
|
|
|
*/
|
|
|
|
abstract public function updateEventExtra( $event );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mark notifications as read for a user
|
|
|
|
* @param $user User
|
|
|
|
* @param $eventIDs array
|
|
|
|
*/
|
|
|
|
abstract public function markRead( $user, $eventIDs );
|
|
|
|
|
2013-04-17 01:00:21 +00:00
|
|
|
/**
|
|
|
|
* Mark all unread notifications as read for a user
|
|
|
|
* @param $user User
|
|
|
|
*/
|
|
|
|
abstract public function markAllRead( $user );
|
|
|
|
|
2013-01-15 23:21:39 +00:00
|
|
|
/**
|
|
|
|
* Retrieves number of unread notifications that a user has.
|
|
|
|
* @param $user User object to check notifications for
|
|
|
|
* @param $dbSource string use master or slave storage to pull count
|
2013-05-24 22:51:47 +00:00
|
|
|
* @return int
|
2013-01-15 23:21:39 +00:00
|
|
|
*/
|
|
|
|
abstract public function getNotificationCount( $user, $dbSource );
|
|
|
|
|
2013-05-24 22:51:47 +00:00
|
|
|
/**
|
|
|
|
* Get the event ids for corresponding unread notifications for an
|
|
|
|
* event type
|
|
|
|
* @param $user User object to check notification for
|
|
|
|
* @param $type string event type
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
abstract public function getUnreadNotifications( $user, $type );
|
2013-01-15 23:21:39 +00:00
|
|
|
}
|