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
6declare(strict_types=1);
7
8namespace App\Transformers;
9
10use App\Models\UserGroupEvent;
11use League\Fractal\Resource\ResourceInterface;
12
13class UserGroupEventTransformer extends TransformerAbstract
14{
15 protected array $availableIncludes = [
16 'actor',
17 ];
18
19 protected array $defaultIncludes = [
20 'actor',
21 ];
22
23 protected $permissions = [
24 'actor' => 'UserGroupEventShowActor',
25 ];
26
27 public function transform(UserGroupEvent $event): array
28 {
29 $json = [
30 'created_at' => $event->created_at_json,
31 'group_id' => $event->group_id,
32 'hidden' => $event->isHidden(),
33 'id' => $event->id,
34 'type' => $event->type,
35 'user_id' => $event->user_id,
36 ...$event->details,
37 ];
38
39 unset($json['actor_name']);
40
41 return $json;
42 }
43
44 public function includeActor(UserGroupEvent $event): ResourceInterface
45 {
46 return $this->primitive([
47 'id' => $event->actor_id,
48 'username' => $event->details['actor_name'],
49 ]);
50 }
51}