updateNotificationRecipients()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 3
nc 2
nop 2
1
<?php
2
3
namespace SilverStripe\Blog\Model;
4
5
use SilverStripe\Comments\Model\Comment;
6
use SilverStripe\Core\Config\Config;
7
use SilverStripe\ORM\DataExtension;
8
use SilverStripe\ORM\SS_List;
9
use SilverStripe\Security\Member;
10
11
/**
12
 * Customise blog post to support comment notifications.
13
 *
14
 * Extends {@see BlogPost} with extensions to {@see CommentNotifiable}.
15
 */
16
class BlogPostNotifications extends DataExtension
17
{
18
    /**
19
     * Configure whether to send notifications even for spam comments
20
     *
21
     * @config
22
     * @var boolean
23
     */
24
    private static $notification_on_spam = true;
25
26
    /**
27
     * Notify all authors of notifications.
28
     *
29
     * @param SS_List $list
30
     * @param mixed $comment
31
     */
32
    public function updateNotificationRecipients(&$list, &$comment)
33
    {
34
        //default is notification is on regardless of spam status
35
        $list = $this->owner->Authors();
36
37
        // If comment is spam and notification are set to not send on spam clear the recipient list
38
        if (Config::inst()->get(__CLASS__, 'notification_on_spam') == false && $comment->IsSpam) {
39
            $list = [];
40
        }
41
    }
42
43
    /**
44
     * Update comment to include the page title.
45
     *
46
     * @param string $subject
47
     * @param Comment $comment
48
     * @param Member|string $recipient
49
     */
50
    public function updateNotificationSubject(&$subject, &$comment, &$recipient)
0 ignored issues
show
Unused Code introduced by
The parameter $comment is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $recipient is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
51
    {
52
        $subject = sprintf('A new comment has been posted on %s', $this->owner->Title);
53
    }
54
}
55