/** * Get a list of notifications based on the passed parameters * * @param $user User the user to get notifications for * @param $format string/bool false to not format any notifications, string to a specific output format * @param $limit int The maximum number of notifications to return * @param $continue string Used for offset * @return array */ public static function getNotifications($user, $format = false, $limit = 20, $continue = null) { global $wgEchoBackend; $output = array(); // TODO: Make 'web' based on a new API param? $res = $wgEchoBackend->loadNotifications($user, $limit, $continue, 'web'); foreach ($res as $row) { $event = EchoEvent::newFromRow($row); if ($row->notification_bundle_base && $row->notification_bundle_display_hash) { $event->setBundleHash($row->notification_bundle_display_hash); } $timestampMw = self::getUserLocalTime($user, $row->notification_timestamp); // Start creating date section header $now = wfTimestamp(); $dateFormat = substr($timestampMw, 0, 8); if (substr(self::getUserLocalTime($user, $now), 0, 8) === $dateFormat) { // 'Today' $date = wfMessage('echo-date-today')->escaped(); } elseif (substr(self::getUserLocalTime($user, $now - 86400), 0, 8) === $dateFormat) { // 'Yesterday' $date = wfMessage('echo-date-yesterday')->escaped(); } else { // 'May 10' or '10 May' (depending on user's date format preference) $lang = RequestContext::getMain()->getLanguage(); $dateFormat = $lang->getDateFormatString('pretty', $user->getDatePreference() ?: 'default'); $date = $lang->sprintfDate($dateFormat, $timestampMw); } // End creating date section header $thisEvent = array('id' => $event->getId(), 'type' => $event->getType(), 'category' => $event->getCategory(), 'timestamp' => array('utcunix' => wfTimestamp(TS_UNIX, $row->notification_timestamp), 'unix' => self::getUserLocalTime($user, $row->notification_timestamp, TS_UNIX), 'mw' => $timestampMw, 'date' => $date)); if ($event->getVariant()) { $thisEvent['variant'] = $event->getVariant(); } if ($event->getTitle()) { $thisEvent['title'] = array('full' => $event->getTitle()->getPrefixedText(), 'namespace' => $event->getTitle()->getNSText(), 'namespace-key' => $event->getTitle()->getNamespace(), 'text' => $event->getTitle()->getText()); } if ($event->getAgent()) { if ($event->userCan(Revision::DELETED_USER, $user)) { $thisEvent['agent'] = array('id' => $event->getAgent()->getId(), 'name' => $event->getAgent()->getName()); } else { $thisEvent['agent'] = array('userhidden' => ''); } } //if ( $row->notification_read_timestamp ) { $thisEvent['read'] = $row->notification_read_timestamp; //} if ($format) { $thisEvent['*'] = EchoNotificationController::formatNotification($event, $user, $format); } $output[$event->getID()] = $thisEvent; } return $output; }
/** * Wrapper function that calls other functions required to process email batch */ public function process() { wfProfileIn(__METHOD__); // if there is no event for this user, exist the process if (!$this->setLastEvent()) { return; } // get valid events $events = $this->getEvents(); if ($events) { foreach ($events as $row) { $this->count++; if ($this->count > self::$displaySize) { break; } $event = EchoEvent::newFromRow($row); $this->appendContent($event, $row->eeb_event_hash); } $this->sendEmail(); } $this->clearProcessedEvent(); $this->updateUserLastBatchTimestamp(); wfProfileOut(__METHOD__); }