|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by PhpStorm. |
|
4
|
|
|
* User: arthur |
|
5
|
|
|
* Date: 29.10.18 |
|
6
|
|
|
* Time: 09:38. |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Modules\Machine\Transformers; |
|
10
|
|
|
|
|
11
|
|
|
use Foundation\Abstracts\Transformers\Transformer; |
|
12
|
|
|
use Modules\Machine\Entities\Machine; |
|
13
|
|
|
use Modules\User\Entities\User; |
|
14
|
|
|
use Modules\User\Transformers\UserTransformer; |
|
15
|
|
|
|
|
16
|
|
|
class MachineTransformer extends Transformer |
|
17
|
|
|
{ |
|
18
|
|
|
public $available = [ |
|
19
|
|
|
'user', |
|
20
|
|
|
]; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Transform the resource into an array. |
|
24
|
|
|
* |
|
25
|
|
|
* @param \Illuminate\Http\Request $request |
|
26
|
|
|
* |
|
27
|
|
|
* @return array |
|
28
|
|
|
*/ |
|
29
|
6 |
|
public function toArray($request) |
|
30
|
|
|
{ |
|
31
|
|
|
return [ |
|
32
|
6 |
|
'id' => $this->id, |
|
|
|
|
|
|
33
|
6 |
|
'user_id' => $this->user_id, |
|
|
|
|
|
|
34
|
6 |
|
'name' => $this->name, |
|
|
|
|
|
|
35
|
6 |
|
'hostname' => $this->hostname, |
|
|
|
|
|
|
36
|
6 |
|
'username' => $this->username, |
|
|
|
|
|
|
37
|
6 |
|
'os' => $this->os, |
|
|
|
|
|
|
38
|
6 |
|
'hash' => $this->hash, |
|
|
|
|
|
|
39
|
6 |
|
'active' => $this->active, |
|
|
|
|
|
|
40
|
6 |
|
'ip_address' => $this->ip_address, |
|
|
|
|
|
|
41
|
6 |
|
'mac_address' => $this->mac_address, |
|
|
|
|
|
|
42
|
6 |
|
'memory_usage' => $this->memory_usage, |
|
|
|
|
|
|
43
|
6 |
|
'memory_available' => $this->memory_available, |
|
|
|
|
|
|
44
|
6 |
|
'cpu_usage' => $this->cpu_usage, |
|
|
|
|
|
|
45
|
6 |
|
'cpu_clock' => $this->cpu_clock, |
|
|
|
|
|
|
46
|
6 |
|
'online' => $this->online, |
|
|
|
|
|
|
47
|
6 |
|
'last_heartbeat' => $this->last_heartbeat ?? null, |
|
|
|
|
|
|
48
|
6 |
|
'created_at' => $this->created_at, |
|
|
|
|
|
|
49
|
6 |
|
'updated_at' => $this->updated_at, |
|
|
|
|
|
|
50
|
|
|
]; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
1 |
|
public function transformUser(Machine $machine) |
|
54
|
|
|
{ |
|
55
|
1 |
|
return UserTransformer::resource($machine->user); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|