@@ -15,79 +15,79 @@ |
||
15 | 15 | class CommentNotifier extends Extension |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * Notify Members of the post there is a new comment. |
|
20 | - * |
|
21 | - * @param Comment $comment |
|
22 | - */ |
|
23 | - public function onAfterPostComment(Comment $comment) |
|
24 | - { |
|
25 | - $parent = $comment->Parent(); |
|
18 | + /** |
|
19 | + * Notify Members of the post there is a new comment. |
|
20 | + * |
|
21 | + * @param Comment $comment |
|
22 | + */ |
|
23 | + public function onAfterPostComment(Comment $comment) |
|
24 | + { |
|
25 | + $parent = $comment->Parent(); |
|
26 | 26 | |
27 | - if (!$parent || !$parent->hasMethod('notificationRecipients')) { |
|
28 | - return; |
|
29 | - } |
|
27 | + if (!$parent || !$parent->hasMethod('notificationRecipients')) { |
|
28 | + return; |
|
29 | + } |
|
30 | 30 | |
31 | - // Ask parent to submit all recipients |
|
32 | - $recipients = $parent->notificationRecipients($comment); |
|
31 | + // Ask parent to submit all recipients |
|
32 | + $recipients = $parent->notificationRecipients($comment); |
|
33 | 33 | |
34 | - foreach ($recipients as $recipient) { |
|
35 | - $this->notifyCommentRecipient($comment, $parent, $recipient); |
|
36 | - } |
|
37 | - } |
|
34 | + foreach ($recipients as $recipient) { |
|
35 | + $this->notifyCommentRecipient($comment, $parent, $recipient); |
|
36 | + } |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * Send comment notification to a given recipient |
|
41 | - * |
|
42 | - * @param Comment $comment |
|
43 | - * @param DataObject $parent Object with the {@see CommentNotifiable} extension applied |
|
44 | - * @param Member|string $recipient Either a member object or an email address to which notifications should be sent |
|
45 | - */ |
|
46 | - public function notifyCommentRecipient($comment, $parent, $recipient) |
|
47 | - { |
|
48 | - $subject = $parent->notificationSubject($comment, $recipient); |
|
49 | - $sender = $parent->notificationSender($comment, $recipient); |
|
50 | - $template = $parent->notificationTemplate($comment, $recipient); |
|
39 | + /** |
|
40 | + * Send comment notification to a given recipient |
|
41 | + * |
|
42 | + * @param Comment $comment |
|
43 | + * @param DataObject $parent Object with the {@see CommentNotifiable} extension applied |
|
44 | + * @param Member|string $recipient Either a member object or an email address to which notifications should be sent |
|
45 | + */ |
|
46 | + public function notifyCommentRecipient($comment, $parent, $recipient) |
|
47 | + { |
|
48 | + $subject = $parent->notificationSubject($comment, $recipient); |
|
49 | + $sender = $parent->notificationSender($comment, $recipient); |
|
50 | + $template = $parent->notificationTemplate($comment, $recipient); |
|
51 | 51 | |
52 | - // Validate email |
|
53 | - // Important in case of the owner being a default-admin or a username with no contact email |
|
54 | - $to = ($recipient instanceof Member) ? $recipient->Email : $recipient; |
|
52 | + // Validate email |
|
53 | + // Important in case of the owner being a default-admin or a username with no contact email |
|
54 | + $to = ($recipient instanceof Member) ? $recipient->Email : $recipient; |
|
55 | 55 | |
56 | - if (!Email::is_valid_address($to)) { |
|
57 | - return; |
|
58 | - } |
|
56 | + if (!Email::is_valid_address($to)) { |
|
57 | + return; |
|
58 | + } |
|
59 | 59 | |
60 | - // Prepare the email |
|
61 | - $email = Email::create(); |
|
62 | - $email->setSubject($subject); |
|
63 | - $email->setFrom($sender); |
|
64 | - $email->setTo($to); |
|
65 | - $email->setHTMLTemplate($template); |
|
60 | + // Prepare the email |
|
61 | + $email = Email::create(); |
|
62 | + $email->setSubject($subject); |
|
63 | + $email->setFrom($sender); |
|
64 | + $email->setTo($to); |
|
65 | + $email->setHTMLTemplate($template); |
|
66 | 66 | |
67 | - if ($recipient instanceof Member) { |
|
68 | - $email->setData([ |
|
69 | - 'Parent' => $parent, |
|
70 | - 'Comment' => $comment, |
|
71 | - 'Recipient' => $recipient, |
|
72 | - 'ApproveLink' => $comment->ApproveLink($recipient), |
|
73 | - 'HamLink' => $comment->HamLink($recipient), |
|
74 | - 'SpamLink' => $comment->SpamLink($recipient), |
|
75 | - 'DeleteLink' => $comment->DeleteLink($recipient), |
|
76 | - ]); |
|
77 | - } else { |
|
78 | - $email->setData([ |
|
79 | - 'Parent' => $parent, |
|
80 | - 'Comment' => $comment, |
|
81 | - 'ApproveLink' => false, |
|
82 | - 'SpamLink' => false, |
|
83 | - 'DeleteLink' => false, |
|
84 | - 'HamLink' => false, |
|
85 | - 'Recipient' => $recipient |
|
86 | - ]); |
|
87 | - } |
|
67 | + if ($recipient instanceof Member) { |
|
68 | + $email->setData([ |
|
69 | + 'Parent' => $parent, |
|
70 | + 'Comment' => $comment, |
|
71 | + 'Recipient' => $recipient, |
|
72 | + 'ApproveLink' => $comment->ApproveLink($recipient), |
|
73 | + 'HamLink' => $comment->HamLink($recipient), |
|
74 | + 'SpamLink' => $comment->SpamLink($recipient), |
|
75 | + 'DeleteLink' => $comment->DeleteLink($recipient), |
|
76 | + ]); |
|
77 | + } else { |
|
78 | + $email->setData([ |
|
79 | + 'Parent' => $parent, |
|
80 | + 'Comment' => $comment, |
|
81 | + 'ApproveLink' => false, |
|
82 | + 'SpamLink' => false, |
|
83 | + 'DeleteLink' => false, |
|
84 | + 'HamLink' => false, |
|
85 | + 'Recipient' => $recipient |
|
86 | + ]); |
|
87 | + } |
|
88 | 88 | |
89 | - $this->owner->invokeWithExtensions('updateCommentNotification', $email, $comment, $recipient); |
|
89 | + $this->owner->invokeWithExtensions('updateCommentNotification', $email, $comment, $recipient); |
|
90 | 90 | |
91 | - return $email->send(); |
|
92 | - } |
|
91 | + return $email->send(); |
|
92 | + } |
|
93 | 93 | } |