2016-05-16 20:35:15 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This pager is used by Special:Notifications (NO-JS).
|
|
|
|
* The heavy-lifting is done by IndexPager (grand-parent to this class).
|
2016-07-25 16:20:38 +00:00
|
|
|
* It paginates on notification_event for a specific user, only for the enabled event types.
|
2016-05-16 20:35:15 +00:00
|
|
|
*/
|
|
|
|
class NotificationPager extends ReverseChronologicalPager {
|
2016-06-01 22:03:58 +00:00
|
|
|
public function __construct() {
|
|
|
|
$dbFactory = MWEchoDbFactory::newFromDefault();
|
2017-09-24 05:23:47 +00:00
|
|
|
$this->mDb = $dbFactory->getEchoDb( DB_REPLICA );
|
2016-06-01 22:03:58 +00:00
|
|
|
|
|
|
|
parent::__construct();
|
|
|
|
}
|
2016-05-16 20:35:15 +00:00
|
|
|
|
2018-11-02 17:47:39 +00:00
|
|
|
public function formatRow( $row ) {
|
2016-05-16 20:35:15 +00:00
|
|
|
$msg = "This pager does not support row formatting. Use 'getNotifications()' to get a list of EchoNotification objects.";
|
|
|
|
throw new Exception( $msg );
|
|
|
|
}
|
|
|
|
|
2018-11-02 17:47:39 +00:00
|
|
|
public function getQueryInfo() {
|
2016-05-16 20:35:15 +00:00
|
|
|
$attributeManager = EchoAttributeManager::newFromGlobalVars();
|
|
|
|
$eventTypes = $attributeManager->getUserEnabledEvents( $this->getUser(), 'web' );
|
|
|
|
|
2016-12-05 18:51:07 +00:00
|
|
|
return [
|
|
|
|
'tables' => [ 'echo_notification', 'echo_event' ],
|
2016-05-16 20:35:15 +00:00
|
|
|
'fields' => '*',
|
2016-12-05 18:51:07 +00:00
|
|
|
'conds' => [
|
2016-05-16 20:35:15 +00:00
|
|
|
'notification_user' => $this->getUser()->getId(),
|
|
|
|
'event_type' => $eventTypes,
|
2016-07-25 16:20:38 +00:00
|
|
|
'event_deleted' => 0,
|
2016-12-05 18:51:07 +00:00
|
|
|
],
|
|
|
|
'options' => [],
|
2016-05-16 20:35:15 +00:00
|
|
|
'join_conds' =>
|
2016-12-05 18:51:07 +00:00
|
|
|
[ 'echo_event' =>
|
|
|
|
[
|
2016-05-16 20:35:15 +00:00
|
|
|
'JOIN',
|
|
|
|
'notification_event=event_id',
|
2016-12-05 18:51:07 +00:00
|
|
|
],
|
|
|
|
],
|
|
|
|
];
|
2016-05-16 20:35:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getNotifications() {
|
|
|
|
if ( !$this->mQueryDone ) {
|
|
|
|
$this->doQuery();
|
|
|
|
}
|
|
|
|
|
2016-12-05 18:51:07 +00:00
|
|
|
$notifications = [];
|
2016-05-16 20:35:15 +00:00
|
|
|
foreach ( $this->mResult as $row ) {
|
|
|
|
$notifications[] = EchoNotification::newFromRow( $row );
|
|
|
|
}
|
|
|
|
|
|
|
|
// get rid of the overfetched
|
|
|
|
if ( count( $notifications ) > $this->getLimit() ) {
|
|
|
|
array_pop( $notifications );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $this->mIsBackwards ) {
|
|
|
|
$notifications = array_reverse( $notifications );
|
|
|
|
}
|
|
|
|
|
|
|
|
return $notifications;
|
|
|
|
}
|
|
|
|
|
2018-11-02 17:47:39 +00:00
|
|
|
public function getIndexField() {
|
2016-05-16 20:35:15 +00:00
|
|
|
return 'notification_event';
|
|
|
|
}
|
|
|
|
}
|