|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by PhpStorm. |
|
4
|
|
|
* User: arthur |
|
5
|
|
|
* Date: 29.10.18 |
|
6
|
|
|
* Time: 09:38. |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Modules\Account\Transformers; |
|
10
|
|
|
|
|
11
|
|
|
use Foundation\Abstracts\Transformers\Transformer; |
|
12
|
|
|
use Foundation\Exceptions\Exception; |
|
13
|
|
|
use Modules\Account\Entities\Account; |
|
14
|
|
|
use Modules\Machine\Transformers\MachineTransformer; |
|
15
|
|
|
use Modules\User\Transformers\UserTransformer; |
|
16
|
|
|
|
|
17
|
|
|
class AccountTransformer extends Transformer |
|
18
|
|
|
{ |
|
19
|
|
|
public $available = [ |
|
20
|
|
|
'user', |
|
21
|
|
|
'machine' |
|
22
|
|
|
]; |
|
23
|
|
|
|
|
24
|
|
|
public $include = [ |
|
25
|
|
|
'machine', |
|
26
|
|
|
'user' |
|
27
|
|
|
]; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Transform the resource into an array. |
|
31
|
|
|
* |
|
32
|
|
|
* @param \Illuminate\Http\Request $request |
|
33
|
|
|
* |
|
34
|
|
|
* @return array |
|
35
|
|
|
* @throws Exception |
|
36
|
|
|
*/ |
|
37
|
|
|
public function toArray($request) |
|
38
|
|
|
{ |
|
39
|
|
|
$game = $this->game ?? null; |
|
|
|
|
|
|
40
|
|
|
switch ($game) { |
|
41
|
|
|
case "OSRS": |
|
42
|
|
|
return $this->OSRSAccountToArray(); |
|
43
|
|
|
default: |
|
44
|
|
|
throw new Exception("Could not identity account game type"); |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
protected function OSRSAccountToArray() |
|
49
|
|
|
{ |
|
50
|
|
|
return [ |
|
51
|
|
|
'id' => $this->id, |
|
|
|
|
|
|
52
|
|
|
'username' => $this->username, |
|
|
|
|
|
|
53
|
|
|
'password' => $this->password, |
|
|
|
|
|
|
54
|
|
|
'game' => $this->game, |
|
|
|
|
|
|
55
|
|
|
"bank_pin" => $this->bank_pin, |
|
|
|
|
|
|
56
|
|
|
"location" => $this->location, |
|
|
|
|
|
|
57
|
|
|
"ingame_name" => $this->ingame_name, |
|
|
|
|
|
|
58
|
|
|
"skills" => $this->skills, |
|
|
|
|
|
|
59
|
|
|
"membership_expires_at" => $this->membership_expires_at, |
|
|
|
|
|
|
60
|
|
|
'banned_at' => $this->banned_at, |
|
|
|
|
|
|
61
|
|
|
'created_at' => $this->created_at, |
|
|
|
|
|
|
62
|
|
|
'updated_at' => $this->updated_at, |
|
|
|
|
|
|
63
|
|
|
]; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function transformUser(Account $account) |
|
67
|
|
|
{ |
|
68
|
|
|
return UserTransformer::resource($account->user); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function transformMachine(Account $account) |
|
72
|
|
|
{ |
|
73
|
|
|
return MachineTransformer::resource($account->machine); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|