|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of Transfer. |
|
5
|
|
|
* |
|
6
|
|
|
* For the full copyright and license information, please view the LICENSE file located |
|
7
|
|
|
* in the root directory. |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Transfer\EzPlatform\Repository\Values\Mapper; |
|
11
|
|
|
|
|
12
|
|
|
use eZ\Publish\API\Repository\Values\Content\Location; |
|
13
|
|
|
use eZ\Publish\API\Repository\Values\Content\LocationCreateStruct; |
|
14
|
|
|
use eZ\Publish\API\Repository\Values\Content\LocationUpdateStruct; |
|
15
|
|
|
use Transfer\EzPlatform\Repository\Values\LocationObject; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* User mapper. |
|
19
|
|
|
* |
|
20
|
|
|
* @author Harald Tollefsen <[email protected]> |
|
21
|
|
|
*/ |
|
22
|
|
|
class LocationMapper |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @var LocationObject |
|
26
|
|
|
*/ |
|
27
|
|
|
public $locationObject; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @param LocationObject $locationObject |
|
31
|
19 |
|
*/ |
|
32
|
|
|
public function __construct(LocationObject $locationObject) |
|
33
|
19 |
|
{ |
|
34
|
19 |
|
$this->locationObject = $locationObject; |
|
35
|
|
|
} |
|
36
|
17 |
|
|
|
37
|
|
|
public function locationToObject(Location $location) |
|
38
|
17 |
|
{ |
|
39
|
17 |
|
$this->locationObject->data['content_id'] = $location->contentId; |
|
40
|
17 |
|
$this->locationObject->data['remote_id'] = $location->remoteId; |
|
41
|
17 |
|
$this->locationObject->data['parent_location_id'] = $location->parentLocationId; |
|
42
|
17 |
|
$this->locationObject->data['hidden'] = $location->hidden; |
|
43
|
17 |
|
$this->locationObject->data['priority'] = $location->priority; |
|
44
|
17 |
|
$this->locationObject->data['sort_field'] = $location->sortField; |
|
45
|
|
|
$this->locationObject->data['sort_order'] = $location->sortOrder; |
|
46
|
17 |
|
|
|
47
|
17 |
|
$this->locationObject->setProperty('id', $location->id); |
|
48
|
17 |
|
$this->locationObject->setProperty('depth', $location->depth); |
|
49
|
17 |
|
$this->locationObject->setProperty('content_info', $location->contentInfo); |
|
50
|
17 |
|
$this->locationObject->setProperty('invisible', $location->invisible); |
|
51
|
17 |
|
$this->locationObject->setProperty('path', $location->path); |
|
52
|
17 |
|
$this->locationObject->setProperty('path_string', $location->pathString); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @param LocationCreateStruct $createStruct |
|
57
|
11 |
|
*/ |
|
58
|
|
|
public function mapObjectToCreateStruct(LocationCreateStruct $createStruct) |
|
59
|
|
|
{ |
|
60
|
|
|
// Name collection (ez => transfer) |
|
61
|
11 |
|
$keys = array( |
|
62
|
11 |
|
'remoteId' => 'remote_id', |
|
63
|
11 |
|
'hidden' => 'hidden', |
|
64
|
11 |
|
'priority' => 'priority', |
|
65
|
11 |
|
'sortField' => 'sort_field', |
|
66
|
11 |
|
'sortOrder' => 'sort_order', |
|
67
|
|
|
); |
|
68
|
11 |
|
|
|
69
|
|
|
$this->arrayToStruct($createStruct, $keys); |
|
70
|
11 |
|
|
|
71
|
11 |
|
$this->callStruct($createStruct); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @param LocationUpdateStruct $updateStruct |
|
76
|
16 |
|
*/ |
|
77
|
|
|
public function mapObjectToUpdateStruct(LocationUpdateStruct $updateStruct) |
|
78
|
|
|
{ |
|
79
|
|
|
// Name collection (ez => transfer) |
|
80
|
16 |
|
$keys = array( |
|
81
|
16 |
|
'remoteId' => 'remote_id', |
|
82
|
16 |
|
'priority' => 'priority', |
|
83
|
16 |
|
'sortField' => 'sort_field', |
|
84
|
16 |
|
'sortOrder' => 'sort_order', |
|
85
|
|
|
); |
|
86
|
16 |
|
|
|
87
|
|
|
$this->arrayToStruct($updateStruct, $keys); |
|
88
|
16 |
|
|
|
89
|
16 |
|
$this->callStruct($updateStruct); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @param LocationCreateStruct|LocationUpdateStruct $struct |
|
94
|
|
|
* @param array $keys |
|
95
|
19 |
|
*/ |
|
96
|
|
|
private function arrayToStruct($struct, $keys) |
|
97
|
19 |
|
{ |
|
98
|
19 |
|
foreach ($keys as $ezKey => $transferKey) { |
|
99
|
12 |
|
if (isset($this->locationObject->data[$transferKey])) { |
|
100
|
12 |
|
$struct->$ezKey = $this->locationObject->data[$transferKey]; |
|
101
|
19 |
|
} |
|
102
|
19 |
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @param LocationCreateStruct|LocationUpdateStruct $struct |
|
107
|
19 |
|
*/ |
|
108
|
|
|
private function callStruct($struct) |
|
109
|
19 |
|
{ |
|
110
|
1 |
|
if ($this->locationObject->getProperty('struct_callback')) { |
|
111
|
1 |
|
$callback = $this->locationObject->getProperty('struct_callback'); |
|
112
|
1 |
|
$callback($struct); |
|
113
|
19 |
|
} |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|