@@ -567,6 +567,10 @@ public function categoryModel_hasWatched_create(CategoryModel $sender) {
567
567
return false ;
568
568
}
569
569
570
+ //
571
+ // EMAIL TEMPLATES
572
+ //
573
+
570
574
/**
571
575
* New discussion has been posted
572
576
* @param $sender
@@ -576,6 +580,8 @@ public function discussionModel_beforeRecordAdvancedNotification_handler($sender
576
580
$ data = &$ args ['Activity ' ];
577
581
if (($ data ['ActivityType ' ] == 'Discussion ' && $ data ['RecordType ' ] == 'Discussion ' )) {
578
582
$ discussion = $ args ['Discussion ' ];
583
+ $ mediaData = $ this ->getMediaData ('discussion ' , $ data ['RecordID ' ]);
584
+ GroupsPlugin::log (' TopcoderEmailTemplate:buildEmail ' , ['mediaData ' => $ mediaData ]);
579
585
$ userModel = new UserModel ();
580
586
$ author = $ userModel ->getID ($ discussion ['InsertUserID ' ]);
581
587
$ category = CategoryModel::categories ($ discussion ['CategoryID ' ]);
@@ -606,22 +612,29 @@ public function discussionModel_beforeRecordAdvancedNotification_handler($sender
606
612
'which was updated ' . $ dateInserted . ' by ' . $ author ->Name . ':<p/> ' .
607
613
'<span>----------------------------------------------------------------------------</span> ' .
608
614
'<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/> ' .
615
622
'<span>----------------------------------------------------------------------------</span> ' ;
616
623
}
617
624
}
618
625
626
+ /**
627
+ * New comment has been posted
628
+ * @param $sender
629
+ * @param $args
630
+ */
619
631
public function commentModel_beforeRecordAdvancedNotification ($ sender , $ args ){
620
632
$ data = &$ args ['Activity ' ];
621
633
if (($ data ['ActivityType ' ] == 'Comment ' && $ data ['RecordType ' ] == 'Comment ' )) {
622
634
$ discussion = $ args ['Discussion ' ];
623
635
$ comment = $ args ["Comment " ];
624
636
$ userModel = new UserModel ();
637
+ $ mediaData = $ this ->getMediaData ('comment ' , $ data ['RecordID ' ]);
625
638
$ discussionAuthor = $ userModel ->getID ($ discussion ['InsertUserID ' ]);
626
639
$ commentAuthor = $ userModel ->getID ($ comment ['InsertUserID ' ]);
627
640
$ category = CategoryModel::categories ($ discussion ['CategoryID ' ]);
@@ -648,19 +661,18 @@ public function commentModel_beforeRecordAdvancedNotification($sender, $args){
648
661
$ discussionStory = condense (Gdn_Format::to ($ discussion ['Body ' ], $ discussion ['Format ' ]));
649
662
$ commentStory = condense (Gdn_Format::to ($ comment ['Body ' ], $ comment ['Format ' ]));
650
663
// 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.
652
665
$ data ['Format ' ] = 'Html ' ;
653
666
$ data ["Story " ] =
654
667
'<p>You are watching the discussion " ' . $ discussionName . '" in the category " ' .$ categoryName .'" ' .
655
668
'which was updated ' . $ commentDateInserted . ' by ' . $ commentAuthor ->Name . ':</p> ' .
656
669
'<span>----------------------------------------------------------------------------</span> ' .
657
670
'<p> ' .$ groupLink .
658
671
'<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> ' ;
664
676
$ parentCommentID = (int )$ comment ['ParentCommentID ' ];
665
677
if ($ parentCommentID > 0 ) {
666
678
$ commentModel = new CommentModel ();
@@ -678,18 +690,50 @@ public function commentModel_beforeRecordAdvancedNotification($sender, $args){
678
690
}
679
691
680
692
// Build a group link for an email template
681
- private function buildEmailGroupLink ($ group ){
682
- if ($ group ) {
693
+ private function buildEmailGroupLink ($ group ) {
694
+ if ($ group ) {
683
695
$ groupName = $ group ->Name ;
684
696
$ groupType = ucfirst (self ::UI [$ group ->Type ]['TypeName ' ]);
685
697
$ 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 ]));
689
700
}
690
701
return '' ;
691
702
}
692
703
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> ' , $ 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
693
737
694
738
/**
695
739
* Add Topcoder Roles
0 commit comments