/** * Retrieves the latest notifications for the specified user. * * @param WebSoccer $websoccer Application contex * @param DbConnection $db DB connection * @param I18n $i18n I18n context. * @param int $userId ID of user * @param int $teamId ID of user's currently selected team * @param int $limit maximum number of notifications to return. * @return array Array of assoc. arrays which represent a notification. A notification has keys id, eventdate, eventtype, seen, message, link */ public static function getLatestNotifications(WebSoccer $websoccer, DbConnection $db, I18n $i18n, $userId, $teamId, $limit) { $result = $db->querySelect('*', $websoccer->getConfig('db_prefix') . '_notification', 'user_id = %d AND (team_id = %d OR team_id IS NULL) ORDER BY eventdate DESC', array($userId, $teamId), $limit); $notifications = array(); while ($row = $result->fetch_array()) { $notification = array('id' => $row['id'], 'eventdate' => $row['eventdate'], 'eventtype' => $row['eventtype'], 'seen' => $row['seen']); // prepare message if ($i18n->hasMessage($row['message_key'])) { $message = $i18n->getMessage($row['message_key']); } else { $message = $row['message_key']; } // replace place holders if (strlen($row['message_data'])) { $messageData = json_decode($row['message_data'], true); if ($messageData) { foreach ($messageData as $placeholderName => $placeholderValue) { $message = str_replace('{' . $placeholderName . '}', htmlspecialchars($placeholderValue, ENT_COMPAT, 'UTF-8'), $message); } } } $notification['message'] = $message; // add target link $link = ''; if ($row['target_pageid']) { if ($row['target_querystr']) { $link = $websoccer->getInternalUrl($row['target_pageid'], $row['target_querystr']); } else { $link = $websoccer->getInternalUrl($row['target_pageid']); } } $notification['link'] = $link; $notifications[] = $notification; } return $notifications; }