1
|
|
|
<?php |
2
|
|
|
namespace keeko\core\serializer\base; |
3
|
|
|
|
4
|
|
|
use keeko\framework\utils\HydrateUtils; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
*/ |
8
|
|
|
trait ActivityObjectSerializerTrait { |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @param mixed $model |
12
|
|
|
* @param array $fields |
13
|
|
|
*/ |
14
|
|
|
public function getAttributes($model, array $fields = null) { |
|
|
|
|
15
|
|
|
return [ |
16
|
|
|
'id' => $model->Id(), |
17
|
|
|
'class_name' => $model->ClassName(), |
18
|
|
|
'type' => $model->Type(), |
19
|
|
|
'display_name' => $model->DisplayName(), |
20
|
|
|
'url' => $model->Url(), |
21
|
|
|
'reference_id' => $model->ReferenceId(), |
22
|
|
|
'version' => $model->Version(), |
23
|
|
|
'extra' => $model->Extra(), |
24
|
|
|
]; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
*/ |
29
|
|
|
public function getFields() { |
30
|
|
|
return ['id', 'class_name', 'type', 'display_name', 'url', 'reference_id', 'version', 'extra']; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param mixed $model |
35
|
|
|
*/ |
36
|
|
|
public function getId($model) { |
|
|
|
|
37
|
|
|
return $model->getId(); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
*/ |
42
|
|
|
public function getRelationships() { |
43
|
|
|
return [ |
44
|
|
|
]; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
*/ |
49
|
|
|
public function getSortFields() { |
50
|
|
|
return ['id', 'class_name', 'type', 'display_name', 'url', 'reference_id', 'version', 'extra']; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param mixed $model |
55
|
|
|
*/ |
56
|
|
|
public function getType($model) { |
|
|
|
|
57
|
|
|
return 'core/activity-object'; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @param mixed $model |
62
|
|
|
* @param mixed $data |
63
|
|
|
*/ |
64
|
|
|
public function hydrate($model, $data) { |
|
|
|
|
65
|
|
|
// attributes |
66
|
|
|
$attribs = isset($data['attributes']) ? $data['attributes'] : []; |
67
|
|
|
|
68
|
|
|
$model = HydrateUtils::hydrate($attribs, $model, ['id', 'class_name', 'type', 'display_name', 'url', 'reference_id', 'version', 'extra']); |
69
|
|
|
|
70
|
|
|
// relationships |
71
|
|
|
$this->hydrateRelationships($model, $data); |
|
|
|
|
72
|
|
|
|
73
|
|
|
return $model; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.