<?php if (!defined('VB_ENTRY')) die('Access denied.'); abstract class vB_Notification_Moderator extends vB_Notification { const TYPENAME = 'Moderator'; protected static $updateEvents = [ 'read_topic', 'read_channel', 'physically_deleted_node', 'deleted_user', ]; protected $usersToNotify = null; protected $notifyBitfieldName = ''; protected $emailBitfieldName = ''; protected $hasEmailNotificationOption = true; protected function validateProvidedRecipients($recipients) { return []; } protected function overwriteRule() { return 'combine'; } protected function populateUsersToNotify() { if ($this->usersToNotify === null) { $this->usersToNotify = [ 'notify' => [], 'email' => [], ]; $bf_misc_moderatornotificationoptions = vB::getDatastore()->getValue('bf_misc_moderatornotificationoptions'); $bf_misc_moderatoremailnotificationoptions = vB::getDatastore()->getValue('bf_misc_moderatoremailnotificationoptions'); foreach ($bf_misc_moderatornotificationoptions AS $bf_name => $bf_value) { $this->usersToNotify['notify'][$bf_name] = []; } foreach ($bf_misc_moderatoremailnotificationoptions AS $bf_name => $bf_value) { $this->usersToNotify['email'][$bf_name] = []; } $moderators = vB::getDbAssertor()->getRows('vBForum:getModeratorNotificationOptions'); foreach ($moderators AS $moderator) { foreach ($bf_misc_moderatornotificationoptions AS $bf_name => $bf_value) { if ($moderator['moderatornotificationoptions'] & $bf_value) { $this->usersToNotify['notify'][$bf_name][$moderator['userid']] = $moderator['userid']; } } foreach ($bf_misc_moderatoremailnotificationoptions AS $bf_name => $bf_value) { if ($moderator['moderatoremailnotificationoptions'] & $bf_value) { $this->usersToNotify['email'][$bf_name][$moderator['userid']] = $moderator['userid']; } } } } } protected function getUserIdsToNotify() { return $this->getUserIdsToNotifyOrEmail('notify'); } protected function getUserIdsToNotifyOrEmail($notificationType) { if (!in_array($notificationType, ['notify', 'email'], true)) { throw new Exception('Invalid notification type.'); } if (empty($this->notifyBitfieldName)) { throw new Exception('Subclasses of vB_Notification_Moderator must define notifyBitfieldName.'); } $this->populateUsersToNotify(); if (!isset($this->usersToNotify[$notificationType][$this->notifyBitfieldName])) { throw new Exception('Invalid or non-existent value used in notifyBitfieldName.'); } return $this->usersToNotify[$notificationType][$this->notifyBitfieldName]; } protected function addAdditionalRecipients() { return $this->getUserIdsToNotify(); } protected function typeEnabledForUser($user) { return in_array($user['userid'], $this->getUserIdsToNotify()); } protected function flagCombinedNotifications(&$addNotificationData, &$targetNotificationData, $addNotificationFromDb) { if ($targetNotificationData) { $targetNotificationData['combined_with_existing_db_notification'] = (bool) $addNotificationFromDb; } } public function shouldSendEmailToUser($userid) { $recipientsCache = $this->getCachedRecipientData(); $recipientCache = $recipientsCache[$userid]; $bf_misc_moderatoremailnotificationoptions = vB::getDatastore()->getValue('bf_misc_moderatoremailnotificationoptions'); $bfOptionMask = $bf_misc_moderatoremailnotificationoptions[$this->emailBitfieldName]; $send = (bool) ($bfOptionMask & $recipientCache['moderatoremailnotificationoptions']); if (!empty($this->notificationData['combined_with_existing_db_notification'])) { $send = false; } return $send; } protected static function normalizeCustomData($customData) { if (is_string($customData)) { $customData = json_decode($customData, true); } return $customData; } } 