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\UserRelation;
9use League\Fractal\ParamBag;
10
11class UserRelationTransformer extends TransformerAbstract
12{
13 protected array $availableIncludes = [
14 'target',
15 ];
16
17 public function transform(UserRelation $userRelation)
18 {
19 return [
20 'target_id' => $userRelation->zebra_id,
21 'relation_type' => $userRelation->friend ? 'friend' : 'block',
22 // mutual is a bit derpy, it only applies to friends
23 'mutual' => (bool) $userRelation->mutual,
24 ];
25 }
26
27 public function includeTarget(UserRelation $userRelation, ?ParamBag $params = null)
28 {
29 $transformer = new UserCompactTransformer();
30
31 $rulesetName = $params?->get('ruleset')[0];
32 if ($rulesetName !== null) {
33 $transformer->setMode($rulesetName);
34 }
35
36 return $this->item($userRelation->target, $transformer);
37 }
38}