<?php if (!defined('VB_ENTRY')) die('Access denied.'); class vB_Notification_Content_GroupByParentid_Comment extends vB_Notification_Content_GroupByParentid { protected static $triggers = array( 'new-content' => 5, ); const TYPENAME = 'Comment'; const FCM_SUPPORTED = true; protected function addAdditionalRecipients() { $nodeid = $this->notificationData['sentbynodeid']; $node = vB_Library::instance('node')->getNodeBare($nodeid); if (($node['nodeid'] != $node['starter']) AND ($node['parentid'] != $node['starter'])) { $parent = vB_Library::instance('node')->getNodeBare($node['parentid']); if (!empty($parent['userid']) AND $parent['userid'] != $this->notificationData['sender']) { return array($parent['userid']); } } return array(); } protected function typeEnabledForUser($user) { static $bf_masks; if (empty($bf_masks)) { $bf_masks = vB::getDatastore()->getValue('bf_misc_usernotificationoptions'); } return ((bool) ($user['notification_options'] & $bf_masks['discussion_comment'])); } public static function fetchPhraseArray($notificationData) { $nodelink = vB5_Route::buildUrl('node|fullurl', ['nodeid' => $notificationData['sentbynodeid']]); $phraseTitle = "missing phrase for " . __CLASS__; $phraseData = []; if (empty($notificationData['sender']) OR is_null($notificationData['sender_username'])) { switch ($notificationData['otherParticipantsCount']) { case 0: $phraseTitle = 'guest_commented_on_your_reply_at_y'; $phraseData = [ $nodelink, $notificationData['aboutstartertitle'] ]; break; case 1: $phraseTitle = 'guest_and_one_other_commented_y'; $phraseData = [ $notificationData['sentbynodeid'], $nodelink, $notificationData['aboutstartertitle'] ]; break; default: $phraseTitle = 'guest_and_y_others_commented_z'; $phraseData = [ $notificationData['sentbynodeid'], $notificationData['otherParticipantsCount'], $nodelink, $notificationData['aboutstartertitle'] ]; break; } } else { $userid = $notificationData['sender']; $username = $notificationData['sender_username']; $userInfo = ['userid' => $userid, 'username' => $username]; try { $userProfileUrl = vB5_Route::buildUrl('profile|fullurl', $userInfo); } catch (Exception $e) { $userProfileUrl = "#"; } switch ($notificationData['otherParticipantsCount']) { case 0: $phraseTitle = 'x_commented_on_your_reply_at_y'; $phraseData = [ $userProfileUrl, $userid, $notificationData['sender_musername'], $nodelink, $notificationData['aboutstartertitle'] ]; break; case 1: $phraseTitle = 'x_and_one_other_commented_y'; $phraseData = [ $userProfileUrl, $userid, $notificationData['sender_musername'], $notificationData['sentbynodeid'], $nodelink, $notificationData['aboutstartertitle'] ]; break; default: $phraseTitle = 'x_and_y_others_commented_z'; $phraseData = [ $userProfileUrl, $userid, $notificationData['sender_musername'], $notificationData['sentbynodeid'], $notificationData['otherParticipantsCount'], $nodelink, $notificationData['aboutstartertitle'] ]; break; } } return [$phraseTitle, $phraseData]; } public static function getFCMExtraData($data, $languageids) { if (empty($data['sentbynodeid'])) { return array(); } $nodeLib = vB_Library::instance('node'); $node = $nodeLib->getNode($data['sentbynodeid']); if (empty($node['starter'])) { return array(); } if ($node['parentid'] == $node['starter']) { return array(); } if ($node['starter'] == $node['nodeid']) { $starter = $node; } else { $starter = $nodeLib->getNode($node['starter']); } if (empty($starter['title'])) { return array(); } $phraseApi = vB_Api::instanceInternal('phrase'); $phraseid = 'fcm_commented_on_reply'; $phraseArgs = array($starter['title']); $return = array(); $data = array( 'INTENT_EXTRA_THREAD_ID' => $node['starter'], 'INTENT_EXTRA_POST_ID' => $node['parentid'], 'INTENT_EXTRA_COMMENT_ID' => $node['nodeid'], ); $clickAction = vB_Library_FCMessaging::CLICK_ACTION_COMMENT; foreach ($languageids AS $__langid) { $__phrase = $phraseApi->fetch($phraseid, $__langid); $__phrase = $__phrase[$phraseid]; $__renderedPhrase = vsprintf($__phrase, $phraseArgs); $return[$__langid] = array( 'title' => $node['authorname'], 'body' => $__renderedPhrase, 'click_action' => $clickAction, 'data' => $data, ); } return $return; } } 