|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright CONTENT CONTROL GmbH, http://www.contentcontrol-berlin.de |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace midcom\datamanager\storage; |
|
7
|
|
|
|
|
8
|
|
|
use midcom\datamanager\helper\imagefilter; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Image storage |
|
12
|
|
|
* |
|
13
|
|
|
* Controls a list of images derived from just one (via filter chains) |
|
14
|
|
|
*/ |
|
15
|
|
|
class image extends blobs implements recreateable |
|
16
|
|
|
{ |
|
17
|
|
|
protected $save_archival = false; |
|
18
|
|
|
|
|
19
|
|
|
public function recreate() : bool |
|
20
|
|
|
{ |
|
21
|
|
|
$existing = $this->load(); |
|
22
|
|
|
if (array_key_exists('archival', $existing)) { |
|
23
|
|
|
$attachment = $existing['archival']; |
|
24
|
|
|
} elseif (array_key_exists('main', $existing)) { |
|
25
|
|
|
$attachment = $existing['main']; |
|
26
|
|
|
} else { |
|
27
|
|
|
return true; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
$filter = new imagefilter($this->config['type_config'], $this->save_archival); |
|
31
|
|
|
$this->map = $filter->process($attachment, $existing); |
|
32
|
|
|
return $this->save_attachment_list(); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* {@inheritdoc} |
|
37
|
|
|
*/ |
|
38
|
4 |
|
public function save() |
|
39
|
|
|
{ |
|
40
|
4 |
|
if ($this->value === null) { |
|
41
|
|
|
//delete? |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
4 |
|
if (!empty($this->value['delete'])) { |
|
45
|
|
|
$this->map = []; |
|
46
|
|
|
$this->save_attachment_list(); |
|
47
|
|
|
return; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
4 |
|
if (!empty($this->value['file'])) { |
|
51
|
|
|
$this->value['file']->parentguid = $this->object->guid; |
|
52
|
|
|
$existing = $this->load(); |
|
53
|
|
|
$filter = new imagefilter($this->config['type_config'], $this->save_archival); |
|
54
|
|
|
$this->map = $filter->process($this->value['file'], $existing); |
|
55
|
|
|
|
|
56
|
|
|
$this->save_attachment_list(); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
4 |
|
if ( array_intersect_key(array_flip(['description', 'title', 'score']), $this->value) |
|
60
|
4 |
|
&& $main = $this->get_main()) { |
|
61
|
|
|
$needs_update = false; |
|
62
|
|
|
if (array_key_exists('description', $this->value)) { |
|
63
|
|
|
$main->set_parameter('midcom.helper.datamanager2.type.blobs', 'description', $this->value['description']); |
|
64
|
|
|
} |
|
65
|
|
|
if (array_key_exists('title', $this->value)) { |
|
66
|
|
|
$needs_update = $main->title != $this->value['title']; |
|
67
|
|
|
$main->title = $this->value['title']; |
|
68
|
|
|
} |
|
69
|
|
|
if (array_key_exists('score', $this->value)) { |
|
70
|
|
|
$needs_update = $needs_update || $main->metadata->score != $this->value['score']; |
|
71
|
|
|
$main->metadata->score = (int) $this->value['score']; |
|
72
|
|
|
} |
|
73
|
|
|
if ($needs_update) { |
|
74
|
|
|
$main->update(); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
4 |
|
} |
|
78
|
|
|
|
|
79
|
1 |
|
private function get_main() : ?\midcom_db_attachment |
|
80
|
|
|
{ |
|
81
|
1 |
|
if (!empty($this->map['main'])) { |
|
82
|
|
|
return $this->map['main']; |
|
83
|
|
|
} |
|
84
|
1 |
|
return $this->load()['main'] ?? null; |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|