3 namespace BookStack\Activity\Notifications\Messages;
5 use BookStack\Activity\Models\Loggable;
6 use BookStack\Activity\Notifications\MessageParts\EntityPathMessageLine;
7 use BookStack\Activity\Notifications\MessageParts\LinkedMailMessageLine;
8 use BookStack\App\MailNotification;
9 use BookStack\Entities\Models\Entity;
10 use BookStack\Entities\Models\Page;
11 use BookStack\Permissions\PermissionApplicator;
12 use BookStack\Translation\LocaleDefinition;
13 use BookStack\Users\Models\User;
14 use Illuminate\Bus\Queueable;
16 abstract class BaseActivityNotification extends MailNotification
20 public function __construct(
21 protected Loggable|string $detail,
27 * Get the array representation of the notification.
29 * @param mixed $notifiable
32 public function toArray($notifiable)
35 'activity_detail' => $this->detail,
36 'activity_creator' => $this->user,
41 * Build the common reason footer line used in mail messages.
43 protected function buildReasonFooterLine(LocaleDefinition $locale): LinkedMailMessageLine
45 return new LinkedMailMessageLine(
46 url('/my-account/notifications'),
47 $locale->trans('notifications.footer_reason'),
48 $locale->trans('notifications.footer_reason_link'),
53 * Build a line which provides the book > chapter path to a page.
54 * Takes into account visibility of these parent items.
55 * Returns null if no path items can be used.
57 protected function buildPagePathLine(Page $page, User $notifiable): ?EntityPathMessageLine
59 $permissions = new PermissionApplicator($notifiable);
61 $path = array_filter([$page->book, $page->chapter], function (?Entity $entity) use ($permissions) {
62 return !is_null($entity) && $permissions->checkOwnableUserAccess($entity, 'view');
65 return empty($path) ? null : new EntityPathMessageLine($path);