Skip to content

Commit 2707658

Browse files
committed
Added attachments
1 parent c26ecbb commit 2707658

File tree

1 file changed

+61
-17
lines changed

1 file changed

+61
-17
lines changed

class.groups.plugin.php

Lines changed: 61 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,10 @@ public function categoryModel_hasWatched_create(CategoryModel $sender) {
567567
return false;
568568
}
569569

570+
//
571+
// EMAIL TEMPLATES
572+
//
573+
570574
/**
571575
* New discussion has been posted
572576
* @param $sender
@@ -576,6 +580,8 @@ public function discussionModel_beforeRecordAdvancedNotification_handler($sender
576580
$data = &$args['Activity'];
577581
if(($data['ActivityType'] == 'Discussion' && $data['RecordType'] == 'Discussion')) {
578582
$discussion = $args['Discussion'];
583+
$mediaData = $this->getMediaData('discussion', $data['RecordID']);
584+
GroupsPlugin::log(' TopcoderEmailTemplate:buildEmail', ['mediaData' => $mediaData]);
579585
$userModel = new UserModel();
580586
$author = $userModel->getID($discussion['InsertUserID']);
581587
$category = CategoryModel::categories($discussion['CategoryID']);
@@ -606,22 +612,29 @@ public function discussionModel_beforeRecordAdvancedNotification_handler($sender
606612
'which was updated ' . $dateInserted . ' by ' . $author->Name . ':<p/>' .
607613
'<span>----------------------------------------------------------------------------</span>' .
608614
'<p>' .
609-
$groupLink.
610-
'<span>Discussion: ' . $discussion['Name'] . '</span><br/>' .
611-
'<span>Author: ' . $author->Name . '</span><br/>' .
612-
'<span>Category: ' . implode('', $categoryBreadcrumbs) . '</span><br/>' .
613-
'<span>Message:</span><br/> ' . $message .
614-
'</p>' .
615+
$groupLink .
616+
'<span>Discussion: ' . $discussion['Name'] . '</span><br/>' .
617+
'<span>Author: ' . $author->Name . '</span><br/>' .
618+
'<span>Category: ' . implode('', $categoryBreadcrumbs) . '</span><br/>' .
619+
'<span>Message:</span>' . $message .
620+
$this->formatMediaData($mediaData) .
621+
'</p><br/>'.
615622
'<span>----------------------------------------------------------------------------</span>';
616623
}
617624
}
618625

626+
/**
627+
* New comment has been posted
628+
* @param $sender
629+
* @param $args
630+
*/
619631
public function commentModel_beforeRecordAdvancedNotification($sender, $args){
620632
$data = &$args['Activity'];
621633
if(($data['ActivityType'] == 'Comment' && $data['RecordType'] == 'Comment')) {
622634
$discussion = $args['Discussion'];
623635
$comment = $args["Comment"];
624636
$userModel = new UserModel();
637+
$mediaData = $this->getMediaData('comment', $data['RecordID']);
625638
$discussionAuthor = $userModel->getID($discussion['InsertUserID']);
626639
$commentAuthor = $userModel->getID($comment['InsertUserID']);
627640
$category = CategoryModel::categories($discussion['CategoryID']);
@@ -648,19 +661,18 @@ public function commentModel_beforeRecordAdvancedNotification($sender, $args){
648661
$discussionStory = condense(Gdn_Format::to($discussion['Body'], $discussion['Format']));
649662
$commentStory = condense(Gdn_Format::to($comment['Body'], $comment['Format']));
650663
// We just converted it to HTML. Make sure everything downstream knows it.
651-
// Taking this HTML and feeding it into the Rich Format for example, would be invalid.
664+
// Taking this HTML and feeding it into the required format for example, would be invalid.
652665
$data['Format'] = 'Html';
653666
$data["Story"] =
654667
'<p>You are watching the discussion "' . $discussionName . '" in the category "' .$categoryName.'" '.
655668
'which was updated ' . $commentDateInserted . ' by ' . $commentAuthor->Name . ':</p>' .
656669
'<span>----------------------------------------------------------------------------</span>' .
657670
'<p>'.$groupLink.
658671
'<span>Message:</span>'.
659-
'</p>' .
660-
'<p>' .
661-
$commentStory .
662-
'</p>'.
663-
'<span>----------------------------------------------------------------------------</span>';
672+
'</p>' .
673+
$commentStory .
674+
$this->formatMediaData($mediaData).
675+
'<br/><span>----------------------------------------------------------------------------</span>';
664676
$parentCommentID = (int)$comment['ParentCommentID'];
665677
if($parentCommentID > 0) {
666678
$commentModel = new CommentModel();
@@ -678,18 +690,50 @@ public function commentModel_beforeRecordAdvancedNotification($sender, $args){
678690
}
679691

680692
// Build a group link for an email template
681-
private function buildEmailGroupLink($group){
682-
if($group) {
693+
private function buildEmailGroupLink($group) {
694+
if ($group) {
683695
$groupName = $group->Name;
684696
$groupType = ucfirst(self::UI[$group->Type]['TypeName']);
685697
$color = c('Garden.EmailTemplate.ButtonTextColor');
686-
687-
return sprintf('<span>%s: %s </span><br/>', $groupType, anchor($groupName, url(self::GROUP_ROUTE.$group->GroupID, true), '',
688-
['rel'=>'noopener noreferrer', 'target'=>'_blank', 'style'=>'color:'.$color]));
698+
return sprintf('<span>%s: %s </span><br/>', $groupType, anchor($groupName, url(GroupsPlugin::GROUP_ROUTE . $group->GroupID, true), '',
699+
['rel' => 'noopener noreferrer', 'target' => '_blank', 'style' => 'color:' . $color]));
689700
}
690701
return '';
691702
}
692703

704+
// Format attachments
705+
private function formatMediaData($mediaData){
706+
if(count($mediaData) == 0) {
707+
return '';
708+
}
709+
710+
$output = '<span>Attachments:</span>';
711+
foreach ($mediaData as $mediaItem) {
712+
$name = val('Name', $mediaItem);
713+
$path = val('Path', $mediaItem);
714+
$link = anchor($name, $path, ['rel' => 'noopener noreferrer', 'target' => '_blank']);
715+
$output .= sprintf('<span>%s</span>&nbsp;', $link);
716+
}
717+
return $output;
718+
}
719+
720+
// Load data from Media Table
721+
private function getMediaData($type, $id) {
722+
$mediaData = [];
723+
$mediaModel = new MediaModel();
724+
if (in_array($type, ['discussion', 'comment'])) {
725+
if (is_numeric($id)) {
726+
$sqlWhere = [
727+
'ForeignTable' => $type,
728+
'ForeignID' => $id
729+
];
730+
$mediaData = $mediaModel->getWhere($sqlWhere)->resultArray();
731+
}
732+
}
733+
return $mediaData;
734+
}
735+
736+
// END: EMAIL TEMPLATES
693737

694738
/**
695739
* Add Topcoder Roles

0 commit comments

Comments
 (0)