|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2018 |
|
6
|
|
|
* @package Controller |
|
7
|
|
|
* @subpackage Common |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
namespace Aimeos\Controller\Common\Catalog\Import\Csv\Processor; |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Abstract class with common methods for all CSV import processors |
|
16
|
|
|
* |
|
17
|
|
|
* @package Controller |
|
18
|
|
|
* @subpackage Common |
|
19
|
|
|
*/ |
|
20
|
|
|
class Base |
|
21
|
|
|
extends \Aimeos\Controller\Common\Catalog\Import\Csv\Base |
|
|
|
|
|
|
22
|
|
|
{ |
|
23
|
|
|
private $context; |
|
24
|
|
|
private $mapping; |
|
25
|
|
|
private $object; |
|
26
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Initializes the object |
|
30
|
|
|
* |
|
31
|
|
|
* @param \Aimeos\MShop\Context\Item\Iface $context Context object |
|
32
|
|
|
* @param array $mapping Associative list of field position in CSV as key and domain item key as value |
|
33
|
|
|
* @param \Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Iface $object Decorated processor |
|
34
|
|
|
*/ |
|
35
|
|
|
public function __construct( \Aimeos\MShop\Context\Item\Iface $context, array $mapping, |
|
36
|
|
|
\Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Iface $object = null ) |
|
37
|
|
|
{ |
|
38
|
|
|
$this->context = $context; |
|
39
|
|
|
$this->mapping = $mapping; |
|
40
|
|
|
$this->object = $object; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Adds the list item default values and returns the resulting array |
|
46
|
|
|
* |
|
47
|
|
|
* @param array $list Associative list of domain item keys and their values, e.g. "catalog.lists.status" => 1 |
|
48
|
|
|
* @param integer $pos Computed position of the list item in the associated list of items |
|
49
|
|
|
* @return array Given associative list enriched by default values if they were not already set |
|
50
|
|
|
*/ |
|
51
|
|
|
protected function addListItemDefaults( array $list, $pos ) |
|
52
|
|
|
{ |
|
53
|
|
|
if( !isset( $list['catalog.lists.position'] ) ) { |
|
54
|
|
|
$list['catalog.lists.position'] = $pos; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
if( !isset( $list['catalog.lists.status'] ) ) { |
|
58
|
|
|
$list['catalog.lists.status'] = 1; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
return $list; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Returns the context item |
|
67
|
|
|
* |
|
68
|
|
|
* @return \Aimeos\MShop\Context\Item\Iface Context object |
|
69
|
|
|
*/ |
|
70
|
|
|
protected function getContext() |
|
71
|
|
|
{ |
|
72
|
|
|
return $this->context; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Returns the mapping list |
|
78
|
|
|
* |
|
79
|
|
|
* @return array Associative list of field positions in CSV as keys and domain item keys as values |
|
80
|
|
|
*/ |
|
81
|
|
|
protected function getMapping() |
|
82
|
|
|
{ |
|
83
|
|
|
return $this->mapping; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Returns the decorated processor object |
|
89
|
|
|
* |
|
90
|
|
|
* @return \Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Iface Processor object |
|
91
|
|
|
* @throws \Aimeos\Controller\Jobs\Exception If no processor object is available |
|
92
|
|
|
*/ |
|
93
|
|
|
protected function getObject() |
|
94
|
|
|
{ |
|
95
|
|
|
if( $this->object === null ) { |
|
96
|
|
|
throw new \Aimeos\Controller\Jobs\Exception( 'No processor object available' ); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
return $this->object; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Returns the value from the list or the default value |
|
105
|
|
|
* |
|
106
|
|
|
* @param array $list Associative list of key/value pairs |
|
107
|
|
|
* @param string $key Key for the value to retrieve |
|
108
|
|
|
* @param mixed $default Default value if key isn't found |
|
109
|
|
|
* @param mixed Value for the key in the list of the default value |
|
110
|
|
|
*/ |
|
111
|
|
|
protected function getValue( array $list, $key, $default ) |
|
112
|
|
|
{ |
|
113
|
|
|
return ( isset( $list[$key] ) ? $list[$key] : $default ); |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|