|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright CONTENT CONTROL GmbH, http://www.contentcontrol-berlin.de |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace midcom\datamanager\extension\transformer; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Image transformer |
|
10
|
|
|
* |
|
11
|
|
|
* This handles multiple attachments because of filter chains and such |
|
12
|
|
|
*/ |
|
13
|
|
|
class imageTransformer extends attachmentTransformer |
|
14
|
|
|
{ |
|
15
|
25 |
|
public function transform($input) |
|
16
|
|
|
{ |
|
17
|
25 |
|
if ($input === null) { |
|
18
|
24 |
|
return []; |
|
19
|
|
|
} |
|
20
|
22 |
|
$result = ['objects' => []]; |
|
21
|
|
|
|
|
22
|
22 |
|
foreach ($input as $key => $value) { |
|
23
|
1 |
|
if (in_array($key, ['delete', 'description', 'title', 'score'])) { |
|
24
|
1 |
|
$result[$key] = $value; |
|
25
|
|
|
} else { |
|
26
|
1 |
|
$result['objects'][$key] = parent::transform($value); |
|
27
|
1 |
|
if ($key === 'file') { |
|
28
|
|
|
$result['identifier'] = $result['objects'][$key]['identifier']; |
|
29
|
|
|
} |
|
30
|
1 |
|
if ($key === 'main') { |
|
31
|
1 |
|
if (!empty($this->config['widget_config']['show_title'])) { |
|
32
|
1 |
|
$result['title'] = $result['objects'][$key]['title']; |
|
33
|
|
|
} |
|
34
|
1 |
|
if (!empty($this->config['widget_config']['show_description'])) { |
|
35
|
|
|
$result['description'] = $result['objects'][$key]['description']; |
|
36
|
|
|
} |
|
37
|
|
|
} |
|
38
|
|
|
} |
|
39
|
|
|
} |
|
40
|
22 |
|
return $result; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
4 |
|
public function reverseTransform($array) |
|
44
|
|
|
{ |
|
45
|
4 |
|
if (empty($array)) { |
|
46
|
1 |
|
return null; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
3 |
|
$result = []; |
|
50
|
3 |
|
if ( !empty($array['file']) |
|
51
|
3 |
|
|| !empty($array['identifier']) && substr($array['identifier'], 0, 8) === 'tmpfile-') { |
|
52
|
|
|
$result['file'] = parent::reverseTransform($array); |
|
53
|
3 |
|
} elseif (!empty($array['objects'])) { |
|
54
|
1 |
|
foreach ($array['objects'] as $key => $value) { |
|
55
|
1 |
|
if (array_key_exists('score', $array)) { |
|
56
|
|
|
$value['score'] = $array['score']; |
|
57
|
|
|
} |
|
58
|
1 |
|
$result[$key] = parent::reverseTransform($value); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
3 |
|
if (!empty($array['delete'])) { |
|
62
|
|
|
$result['delete'] = $array['delete']; |
|
63
|
|
|
} |
|
64
|
3 |
|
if (!empty($this->config['widget_config']['show_description'])) { |
|
65
|
|
|
$result['description'] = $array['description']; |
|
66
|
|
|
} |
|
67
|
3 |
|
if (!empty($this->config['widget_config']['show_title'])) { |
|
68
|
1 |
|
$result['title'] = $array['title']; |
|
69
|
|
|
} |
|
70
|
3 |
|
if (!empty($this->config['widget_config']['sortable'])) { |
|
71
|
|
|
$result['score'] = $array['score']; |
|
72
|
|
|
} |
|
73
|
3 |
|
return $result; |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|