Skip to content

Commit 08a570c

Browse files
authored
Merge pull request #26 from topcoder-platform/issues-149
Issues-70
2 parents 4d37941 + 843dc11 commit 08a570c

File tree

1 file changed

+57
-8
lines changed

1 file changed

+57
-8
lines changed

class.groups.plugin.php

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -535,11 +535,11 @@ public function categoryModel_hasWatched_create(CategoryModel $sender) {
535535
* @param $sender
536536
* @param $args
537537
*/
538-
public function discussionModel_beforeNotification_handler($sender, $args) {
538+
public function discussionModel_beforeRecordAdvancedNotification_handler($sender, $args) {
539539
$data = &$args['Activity'];
540540
if(($data['ActivityType'] == 'Discussion' && $data['RecordType'] == 'Discussion')) {
541541
$discussion = $args['Discussion'];
542-
self::log(' discussionModel_beforeNotification_handler', ['data' => $args['Activity'],
542+
self::log(' discussionModel_BeforeRecordAdvancedNotification_handler', ['data' => $args['Activity'],
543543
'category' => array_values(CategoryModel::getAncestors($discussion['CategoryID']))]);
544544
$userModel = new UserModel();
545545
$author = $userModel->getID($discussion['InsertUserID']);
@@ -555,18 +555,67 @@ public function discussionModel_beforeNotification_handler($sender, $args) {
555555
// Taking this HTML and feeding it into the Rich Format for example, would be invalid.
556556
$data['Format'] = 'Html';
557557
$data["Story"] =
558-
'You are watching the category ' . $categoryName . ', ' .
559-
'which was updated ' . $dateInserted . ' by ' . $author->Name . ':<br/>' .
558+
'<p>You are watching the category "' . $categoryName . '", ' .
559+
'which was updated ' . $dateInserted . ' by ' . $author->Name . ':<p/>' .
560560
'<span>----------------------------------------------------------------------------</span>' .
561561
'<p>' .
562-
'Discussion: ' . $discussion['Name'] . ' <br/>' .
563-
'Author: ' . $author->Name . ' <br/>' .
564-
'Category: ' . implode('', $categoryBreadcrumbs) . ' <br/>' .
565-
'Message: <br/> ' . $message .
562+
'<span>Discussion: ' . $discussion['Name'] . '</span><br/>' .
563+
'<span>Author: ' . $author->Name . '</span><br/>' .
564+
'<span>Category: ' . implode('', $categoryBreadcrumbs) . '</span><br/>' .
565+
'<span>Message:</span><br/> ' . $message .
566566
'</p>' .
567567
'<span>----------------------------------------------------------------------------</span>';
568568
}
569569
}
570+
571+
public function commentModel_beforeRecordAdvancedNotification($sender, $args){
572+
573+
$data = &$args['Activity'];
574+
if(($data['ActivityType'] == 'Comment' && $data['RecordType'] == 'Comment')) {
575+
$discussion = $args['Discussion'];
576+
$comment = $args["Comment"];
577+
self::log(' commentModel_beforeNotification_handler', ['data' => $args['Activity'],
578+
'category' => array_values(CategoryModel::getAncestors($discussion['CategoryID']))]);
579+
$userModel = new UserModel();
580+
$discussionAuthor = $userModel->getID($discussion['InsertUserID']);
581+
$commentAuthor = $userModel->getID($comment['InsertUserID']);
582+
$category = CategoryModel::categories($discussion['CategoryID']);
583+
$discussionName = $discussion['Name'];
584+
$categoryName = $category['Name'];
585+
$categoryBreadcrumbs = array_column(array_values(CategoryModel::getAncestors($discussion['CategoryID'])), 'Name');
586+
$discussionDateInserted = Gdn_Format::dateFull($discussion['DateInserted']);
587+
$commentDateInserted = Gdn_Format::dateFull($comment['DateInserted']);
588+
// $data["HeadlineFormat"] = 'The new discussion has been posted in the category ' . $categoryName . '.';
589+
// Format to Html
590+
$discussionStory = condense(Gdn_Format::to($discussion['Body'], $discussion['Format']));
591+
$commentStory = condense(Gdn_Format::to($comment['Body'], $comment['Format']));
592+
// We just converted it to HTML. Make sure everything downstream knows it.
593+
// Taking this HTML and feeding it into the Rich Format for example, would be invalid.
594+
$data['Format'] = 'Html';
595+
$data["Story"] =
596+
'<p>You are watching the discussion "' . $discussionName . '" in the category "' .$categoryName.'" '.
597+
'which was updated ' . $commentDateInserted . ' by ' . $commentAuthor->Name . ':</p>' .
598+
'<span>----------------------------------------------------------------------------</span>' .
599+
'<p>Message: </p>' .
600+
'<p>' .
601+
$commentStory .
602+
'</p>'.
603+
'<span>----------------------------------------------------------------------------</span>';
604+
$parentCommentID = (int)$comment['ParentCommentID'];
605+
if($parentCommentID > 0) {
606+
$commentModel = new CommentModel();
607+
$parentComment = $commentModel->getID($parentCommentID, DATASET_TYPE_ARRAY);
608+
$parentCommentAuthor = $userModel->getID($comment['InsertUserID']);
609+
$parentCommentStory = condense(Gdn_Format::to($parentComment['Body'], $parentComment['Format']));
610+
$data['Story'] .=
611+
'<p>Original Message (by '.$parentCommentAuthor->Name.' ):</p>'.
612+
'<p>' .
613+
$parentCommentStory.
614+
'</p>' .
615+
'<span>----------------------------------------------------------------------------</span>';
616+
}
617+
}
618+
}
570619
/**
571620
* Add Topcoder Roles
572621
* @param $sender

0 commit comments

Comments
 (0)