Skip to content

Commit 4d37941

Browse files
authored
Merge pull request #25 from topcoder-platform/issues-149
Issues-70:
2 parents a21c5f7 + 9fde58d commit 4d37941

File tree

1 file changed

+39
-6
lines changed

1 file changed

+39
-6
lines changed

class.groups.plugin.php

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,7 @@ public function discussionsController_beforeDiscussionMetaData_handler($sender,
183183
public function base_render_before($sender) {
184184
$sender->addJsFile('vendors/prettify/prettify.js', 'plugins/Groups');
185185
$sender->addJsFile('dashboard.js', 'plugins/Groups');
186-
187-
$categoryModel = new CategoryModel();
188-
189-
self::log('a list of IDs of categories visible to the current user', ['visibleCategories' => $categoryModel->getVisibleCategories([])]);
190-
191-
}
186+
}
192187

193188
public function base_groupOptionsDropdown_handler($sender, $args){
194189
$group = $args['Group'];
@@ -534,6 +529,44 @@ public function categoryModel_hasWatched_create(CategoryModel $sender) {
534529
}
535530
return false;
536531
}
532+
533+
/**
534+
* New discussion has been posted
535+
* @param $sender
536+
* @param $args
537+
*/
538+
public function discussionModel_beforeNotification_handler($sender, $args) {
539+
$data = &$args['Activity'];
540+
if(($data['ActivityType'] == 'Discussion' && $data['RecordType'] == 'Discussion')) {
541+
$discussion = $args['Discussion'];
542+
self::log(' discussionModel_beforeNotification_handler', ['data' => $args['Activity'],
543+
'category' => array_values(CategoryModel::getAncestors($discussion['CategoryID']))]);
544+
$userModel = new UserModel();
545+
$author = $userModel->getID($discussion['InsertUserID']);
546+
$category = CategoryModel::categories($discussion['CategoryID']);
547+
$categoryName = $category['Name'];
548+
$categoryBreadcrumbs = array_column(array_values(CategoryModel::getAncestors($discussion['CategoryID'])), 'Name');
549+
$dateInserted = Gdn_Format::dateFull($discussion['DateInserted']);
550+
$data["HeadlineFormat"] = 'The new discussion has been posted in the category ' . $categoryName . '.';
551+
// Format to Html
552+
$story = condense(Gdn_Format::to($discussion['Body'], $discussion['Format']));
553+
$message = $story; // htmlspecialchars(Gdn_Format::plainText($story, 'Html'));
554+
// We just converted it to HTML. Make sure everything downstream knows it.
555+
// Taking this HTML and feeding it into the Rich Format for example, would be invalid.
556+
$data['Format'] = 'Html';
557+
$data["Story"] =
558+
'You are watching the category ' . $categoryName . ', ' .
559+
'which was updated ' . $dateInserted . ' by ' . $author->Name . ':<br/>' .
560+
'<span>----------------------------------------------------------------------------</span>' .
561+
'<p>' .
562+
'Discussion: ' . $discussion['Name'] . ' <br/>' .
563+
'Author: ' . $author->Name . ' <br/>' .
564+
'Category: ' . implode('', $categoryBreadcrumbs) . ' <br/>' .
565+
'Message: <br/> ' . $message .
566+
'</p>' .
567+
'<span>----------------------------------------------------------------------------</span>';
568+
}
569+
}
537570
/**
538571
* Add Topcoder Roles
539572
* @param $sender

0 commit comments

Comments
 (0)