]> BookStack Code Mirror - bookstack/blob - app/Activity/Notifications/Messages/PageCreationNotification.php
e98f0c20c320bead0237d5f414253c6274a7c377
[bookstack] / app / Activity / Notifications / Messages / PageCreationNotification.php
1 <?php
2
3 namespace BookStack\Activity\Notifications\Messages;
4
5 use BookStack\Activity\Notifications\MessageParts\ListMessageLine;
6 use BookStack\Entities\Models\Page;
7 use BookStack\Entities\Models\Chapter;
8 use BookStack\Users\Models\User;
9 use Illuminate\Notifications\Messages\MailMessage;
10
11 class PageCreationNotification extends BaseActivityNotification
12 {
13     public function toMail(User $notifiable): MailMessage
14     {
15         /** @var Page $page */
16         $page = $this->detail;
17         $book = $page->book;
18         $chapterId = $page->chapter_id;
19         $chapter = $chapterId ? Chapter::find($chapterId) : null;
20
21         $locale = $notifiable->getLocale();
22
23         $listMessageData = [
24             $locale->trans('notifications.detail_page_name') => $page->name,
25             '' => '',
26         ];
27
28         if ($chapter) {
29             $listMessageData += [
30                 $locale->trans('notifications.detail_chapter_name') => $chapter->name,
31             ];
32         }
33     
34         $listMessageData += [
35             $locale->trans('notifications.detail_book_name') => $book->name,
36             $locale->trans('notifications.detail_created_by') => $this->user->name,
37         ];
38
39         return $this->newMailMessage($locale)
40             ->subject($locale->trans('notifications.new_page_subject', ['pageName' => $page->getShortName()]))
41             ->line($locale->trans('notifications.new_page_intro', ['appName' => setting('app-name')], $locale))
42             ->line(new ListMessageLine($listMessageData))
43             ->action($locale->trans('notifications.action_view_page'), $page->getUrl())
44             ->line($this->buildReasonFooterLine($locale));
45     }
46 }