1<?php
2
3// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
4// See the LICENCE file in the repository root for full licence text.
5
6namespace App\Transformers;
7
8use App\Models\Notification;
9use App\Models\UserNotification;
10
11class NotificationTransformer extends TransformerAbstract
12{
13 public function transform($object)
14 {
15 if ($object instanceof UserNotification) {
16 $notification = $object->notification;
17 $isRead = $object->is_read;
18 } elseif ($object instanceof Notification) {
19 $notification = $object;
20 $isRead = false;
21 } // otherwise just explode from accessing null
22
23 return [
24 'id' => $notification->getKey(),
25 'name' => $notification->name,
26 'created_at' => json_time($notification->created_at),
27 'object_type' => $notification->notifiable_type,
28 'object_id' => $notification->notifiable_id,
29 'source_user_id' => $notification->source_user_id,
30 'is_read' => $isRead,
31 'details' => $notification->details,
32 ];
33 }
34}