|
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' => UserTransformer::class, |
|
21
|
|
|
'machine' => MachineTransformer::class, |
|
22
|
|
|
]; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Transform the resource into an array. |
|
26
|
|
|
* |
|
27
|
|
|
* @throws Exception |
|
28
|
|
|
* |
|
29
|
|
|
* @return array |
|
30
|
|
|
*/ |
|
31
|
|
|
public function transformResource(Account $app) |
|
32
|
|
|
{ |
|
33
|
|
|
$game = $this->game ?? null; |
|
|
|
|
|
|
34
|
|
|
switch ($game) { |
|
35
|
|
|
case 'OSRS': |
|
36
|
|
|
return $this->OSRSAccountToArray($app); |
|
37
|
|
|
case null: |
|
38
|
|
|
return; |
|
39
|
|
|
default: |
|
40
|
|
|
throw new Exception('Could not identity account game type'); |
|
41
|
|
|
} |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
protected function OSRSAccountToArray(Account $account) |
|
45
|
|
|
{ |
|
46
|
|
|
return [ |
|
47
|
|
|
'id' => $account->id, |
|
48
|
|
|
'username' => $account->username, |
|
|
|
|
|
|
49
|
|
|
'password' => $account->password, |
|
|
|
|
|
|
50
|
|
|
'game' => $account->game, |
|
|
|
|
|
|
51
|
|
|
'bank_pin' => $account->bank_pin, |
|
|
|
|
|
|
52
|
|
|
'location' => $account->location, |
|
|
|
|
|
|
53
|
|
|
'ingame_name' => $account->ingame_name, |
|
|
|
|
|
|
54
|
|
|
'skills' => $account->skills, |
|
|
|
|
|
|
55
|
|
|
'membership_expires_at' => $account->membership_expires_at, |
|
|
|
|
|
|
56
|
|
|
'banned_at' => $account->banned_at, |
|
|
|
|
|
|
57
|
|
|
'created_at' => $account->created_at, |
|
58
|
|
|
'updated_at' => $account->updated_at, |
|
59
|
|
|
]; |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|