Passed
Push — master ( 13d5af...21d735 )
by Adam
11:07
created

CommentedNotification::notificationUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Coyote\Notifications\Post;
4
5
use Coyote\Post\Comment;
6
use Coyote\Services\UrlBuilder;
7
use Coyote\User;
8
use Illuminate\Contracts\Queue\ShouldQueue;
9
use Illuminate\Notifications\Messages\MailMessage;
10
11
class CommentedNotification extends AbstractNotification implements ShouldQueue
12
{
13
    const ID = \Coyote\Notification::POST_COMMENT;
14
15
    /**
16
     * @var Comment
17
     */
18
    protected $comment;
19
20
    /**
21
     * @param Comment $comment
22
     */
23
    public function __construct(Comment $comment)
24
    {
25
        parent::__construct($comment->user, $comment->post);
26
27
        $this->comment = $comment;
28
    }
29
30
    /**
31
     * @param User $user
32
     * @return array
33
     */
34
    public function toDatabase($user)
35
    {
36
        return [
37
            'object_id'     => $this->objectId(),
38
            'user_id'       => $user->id,
39
            'type_id'       => static::ID,
40
            'subject'       => $this->post->topic->title,
41
            'excerpt'       => excerpt($this->comment->html),
42
            'url'           => UrlBuilder::postComment($this->comment),
43
            'id'            => $this->id
44
        ];
45
    }
46
47
    /**
48
     * Get the mail representation of the notification.
49
     *
50
     * @return \Illuminate\Notifications\Messages\MailMessage
51
     */
52
    public function toMail()
53
    {
54
        return (new MailMessage)
55
            ->subject($this->getMailSubject())
56
            ->line(
57
                sprintf(
58
                    '<strong>%s</strong> dodał komentarz do posta w wątku: <strong>%s</strong>',
59
                    $this->notifier->name,
60
                    $this->post->topic->title
61
                )
62
            )
63
            ->line('<hr>')
64
            ->line($this->comment->html)
65
            ->line('<hr>')
66
            ->action('Zobacz komentarz', url($this->notificationUrl()))
67
            ->line('Jeżeli nie chcesz dostawać tego typu powiadomień, kliknij na przycisk <i>Obserwuj</i> pod postem, aby przestać obserwować dany post.');
68
    }
69
70
    /**
71
     * @return string
72
     */
73
    protected function getMailSubject(): string
74
    {
75
        return $this->notifier->name . ' dodał(a) komentarz w wątku: ' . $this->post->topic->title;
76
    }
77
78
    protected function notificationUrl(): string
79
    {
80
        return route('user.notifications.redirect', ['path' => urlencode(UrlBuilder::postComment($this->comment))]);
81
    }
82
}
83