/** * Notify just one user - the author of comment * that a reply has been posted to his comment * * Should NOT send out this notification * if author of parent comment * is also the author of the Answer AND optin to receive * comments on answer in case this in an answer * * In case of question IF parent comment author * is also following QUESTION OR QUESTION AUTHOR * then also exclude that user. * * OR MAYBE _ DON TREAT REPLY AS COMMENT _ SO DON'T * SEND OUT THE REGULAR onNewComment emails in case * of a reply and ONLY send out a onCommentReply email! * * This actually makes sense because reply to comment * often very specific to that parent comment and NOT * interesting to Question followers... * * @param \Lampcms\Interfaces\Post|object $Resource Answer OR Question object * * @return \Lampcms\Modules\Observers\EmailNotifier */ protected function notifyCommentAuthor(\Lampcms\Interfaces\Post $Resource) { $routerCallback = $this->Registry->Router->getCallback(); /** * CommentorID is always the ViewerID */ $commentorID = (int) $this->aInfo['i_uid']; $parentCommentOwner = (int) $this->aInfo['inreply_uid']; $siteUrl = $this->Registry->Ini->SITE_URL; $home = $this->Registry->Router->getHomePageUrl(); $locale = LAMPCMS_DEFAULT_LOCALE; $url = $siteUrl . '{_WEB_ROOT_}/{_viewquestion_}/{_QID_PREFIX_}' . $Resource->getQuestionId() . '/#c' . $this->aInfo['_id']; $commUrl = $routerCallback($url); d('commUrl: ' . $commUrl); /** * If replied to own comment don't notify self * This will also take care of not notifying * Viewer because if Viewer replied to own comment * this condition check will be true */ if ($parentCommentOwner == $commentorID) { return $this; } $coll = $this->collUsers; $subj = new TranslatableSubject('email.subject.comment_reply', array('{username}' => $this->aInfo['username'])); $body = new TranslatableBody('email.body.comment_reply', array('{username}' => $this->aInfo['username'], '{parent_body}' => \strip_tags($this->aInfo['parent_body']), '{body}' => \strip_tags($this->aInfo['b']), '{link}' => $commUrl, '{home}' => $home)); d('subj: ' . $subj . ' body: ' . $body); $Mailer = $this->Registry->Mailer; $Mailer->setCache($this->Registry->Cache); $callable = function () use($parentCommentOwner, $coll, $subj, $body, $Mailer, $locale) { $aUser = $coll->findOne(array('_id' => $parentCommentOwner, 'ne_fc' => array('$ne' => true)), array('email' => true, 'locale' => true)); if (!empty($aUser) && !empty($aUser['email'])) { if (!empty($aUser['locale'])) { $locale = $aUser['locale']; } $subj = $Mailer->translate($locale, $subj); $body = $Mailer->translate($locale, $body); $Mailer->mail($aUser['email'], $subj, $body, null, false); } }; \Lampcms\runLater($callable); }
/** * Notify just one user - the author of comment * that a reply has been posted to his comment * * Should NOT send out this notification * if author of parent comment * is also the author of the Answer AND optin to receive * comments on answer in case this in an answer * * In case of question IF parent comment author * is also following QUESTION OR QUESTION AUTHOR * then also exclde that user. * * OR MAYBE _ DON TREAT REPLY AS COMMENT _ SO DON'T * SEND OUT THE REGULAR onNewComment emails in case * of a reply and ONLY send out a onCommentReply email! * * This actually makes sense because reply to comment * often very specific to that parent comment and NOT * interesting to Question followers... * * @param object $Resource Answer OR Question object * */ protected function notifyCommentAuthor(\Lampcms\Interfaces\Post $Resource) { $commentorID = (int) $this->aInfo['i_uid']; $parentCommentOwner = (int) $this->aInfo['inreply_uid']; $siteUrl = $this->Registry->Ini->SITE_URL; d('$siteUrl: ' . $siteUrl); $commUrl = $siteUrl . '/q' . $Resource->getQuestionId() . '/#c' . $this->aInfo['_id']; d('commUrl: ' . $commUrl); /** * If replied to own comment don't notify self */ if ($parentCommentOwner == $commentorID) { return $this; } $coll = $this->collUsers; $subj = sprintf(static::$COMMENT_REPLY_SUBJ, $this->aInfo['username']); $body = vsprintf(static::$COMMENT_REPLY_BODY, array($this->aInfo['username'], \strip_tags($this->aInfo['parent_body']), \strip_tags($this->aInfo['b']), $commUrl, $siteUrl)); d('subj: ' . $subj . ' body: ' . $body); $oMailer = $this->Registry->Mailer; $callable = function () use($parentCommentOwner, $coll, $subj, $body, $oMailer) { $aUser = $coll->findOne(array('_id' => $parentCommentOwner, 'ne_fc' => array('$ne' => true)), array('email')); if (!empty($aUser) && !empty($aUser['email'])) { $oMailer->mail($aUser['email'], $subj, $body, null, false); } }; \Lampcms\runLater($callable); }