1 | <?php |
||
36 | abstract class AbstractProductImportObserver extends AbstractObserver implements ProductImportObserverInterface |
||
37 | { |
||
38 | |||
39 | /** |
||
40 | * The actual row, that has to be processed. |
||
41 | * |
||
42 | * @var array |
||
43 | */ |
||
44 | protected $row = array(); |
||
45 | |||
46 | /** |
||
47 | * Set's the actual row, that has to be processed. |
||
48 | * |
||
49 | * @param array $row The row |
||
50 | * |
||
51 | * @return void |
||
52 | */ |
||
53 | 8 | protected function setRow(array $row) |
|
57 | |||
58 | /** |
||
59 | * Return's the actual row, that has to be processed. |
||
60 | * |
||
61 | * @return array The row |
||
62 | */ |
||
63 | 8 | protected function getRow() |
|
67 | |||
68 | /** |
||
69 | * Will be invoked by the action on the events the listener has been registered for. |
||
70 | * |
||
71 | * @param array $row The row to handle |
||
72 | * |
||
73 | * @return array The modified row |
||
74 | * @see \TechDivision\Import\Product\Observers\ImportObserverInterface::handle() |
||
75 | */ |
||
76 | 8 | public function handle(array $row) |
|
88 | |||
89 | /** |
||
90 | * Process the observer's business logic. |
||
91 | * |
||
92 | * @return array The processed row |
||
93 | */ |
||
94 | protected function process() |
||
97 | |||
98 | /** |
||
99 | * Return's the multiple field delimiter character to use, default value is comma (,). |
||
100 | * |
||
101 | * @return string The multiple field delimiter character |
||
102 | */ |
||
103 | protected function getMultipleFieldDelimiter() |
||
107 | |||
108 | /** |
||
109 | * Set's the array containing header row. |
||
110 | * |
||
111 | * @param array $headers The array with the header row |
||
112 | * |
||
113 | * @return void |
||
114 | */ |
||
115 | public function setHeaders(array $headers) |
||
119 | |||
120 | /** |
||
121 | * Return's the array containing header row. |
||
122 | * |
||
123 | * @return array The array with the header row |
||
124 | */ |
||
125 | protected function getHeaders() |
||
129 | |||
130 | /** |
||
131 | * Queries whether or not the header with the passed name is available. |
||
132 | * |
||
133 | * @param string $name The header name to query |
||
134 | * |
||
135 | * @return boolean TRUE if the header is available, else FALSE |
||
136 | */ |
||
137 | 8 | protected function hasHeader($name) |
|
141 | |||
142 | /** |
||
143 | * Return's the header value for the passed name. |
||
144 | * |
||
145 | * @param string $name The name of the header to return the value for |
||
146 | * |
||
147 | * @return mixed The header value |
||
148 | * \InvalidArgumentException Is thrown, if the header with the passed name is NOT available |
||
149 | */ |
||
150 | 8 | protected function getHeader($name) |
|
154 | |||
155 | /** |
||
156 | * Add's the header with the passed name and position, if not NULL. |
||
157 | * |
||
158 | * @param string $name The header name to add |
||
159 | * |
||
160 | * @return integer The new headers position |
||
161 | */ |
||
162 | protected function addHeader($name) |
||
166 | |||
167 | /** |
||
168 | * Return's TRUE if the passed SKU is the actual one. |
||
169 | * |
||
170 | * @param string $sku The SKU to check |
||
171 | * |
||
172 | * @return boolean TRUE if the passed SKU is the actual one |
||
173 | */ |
||
174 | 8 | protected function isLastSku($sku) |
|
178 | |||
179 | /** |
||
180 | * Return's the ID of the product that has been created recently. |
||
181 | * |
||
182 | * @return string The entity Id |
||
183 | */ |
||
184 | 4 | protected function getLastEntityId() |
|
188 | |||
189 | /** |
||
190 | * Return's the source date format to use. |
||
191 | * |
||
192 | * @return string The source date format |
||
193 | */ |
||
194 | 1 | protected function getSourceDateFormat() |
|
198 | |||
199 | /** |
||
200 | * Cast's the passed value based on the backend type information. |
||
201 | * |
||
202 | * @param string $backendType The backend type to cast to |
||
203 | * @param mixed $value The value to be casted |
||
204 | * |
||
205 | * @return mixed The casted value |
||
206 | */ |
||
207 | 1 | protected function castValueByBackendType($backendType, $value) |
|
211 | |||
212 | /** |
||
213 | * Set's the store view code the create the product/attributes for. |
||
214 | * |
||
215 | * @param string $storeViewCode The store view code |
||
216 | * |
||
217 | * @return void |
||
218 | */ |
||
219 | 3 | protected function setStoreViewCode($storeViewCode) |
|
223 | |||
224 | /** |
||
225 | * Return's the store view code the create the product/attributes for. |
||
226 | * |
||
227 | * @param string|null $default The default value to return, if the store view code has not been set |
||
228 | * |
||
229 | * @return string The store view code |
||
230 | */ |
||
231 | protected function getStoreViewCode($default = null) |
||
235 | |||
236 | /** |
||
237 | * Prepare's the store view code in the subject. |
||
238 | * |
||
239 | * @return void |
||
240 | */ |
||
241 | 3 | protected function prepareStoreViewCode() |
|
252 | |||
253 | /** |
||
254 | * Tries to format the passed value to a valid date with format 'Y-m-d H:i:s'. |
||
255 | * If the passed value is NOT a valid date, NULL will be returned. |
||
256 | * |
||
257 | * @param string|null $value The value to format |
||
258 | * |
||
259 | * @return string The formatted date |
||
260 | */ |
||
261 | 1 | protected function formatDate($value) |
|
272 | |||
273 | /** |
||
274 | * Extracts the elements of the passed value by exploding them |
||
275 | * with the also passed delimiter. |
||
276 | * |
||
277 | * @param string $value The value to extract |
||
278 | * @param string|null $delimiter The delimiter used to extrace the elements |
||
279 | * |
||
280 | * @return array The exploded values |
||
281 | */ |
||
282 | protected function explode($value, $delimiter = null) |
||
293 | |||
294 | /** |
||
295 | * Query whether or not a value for the column with the passed name exists. |
||
296 | * |
||
297 | * @param string $name The column name to query for a valid value |
||
298 | * |
||
299 | * @return boolean TRUE if the value is set, else FALSE |
||
300 | */ |
||
301 | 2 | protected function hasValue($name) |
|
316 | |||
317 | /** |
||
318 | * Set the value in the passed column name. |
||
319 | * |
||
320 | * @param string $name The column name to set the value for |
||
321 | * @param mixed $value The value to set |
||
322 | * |
||
323 | * @return void |
||
324 | */ |
||
325 | protected function setValue($name, $value) |
||
329 | |||
330 | /** |
||
331 | * Resolve's the value with the passed colum name from the actual row. If a callback will |
||
332 | * be passed, the callback will be invoked with the found value as parameter. If |
||
333 | * the value is NULL or empty, the default value will be returned. |
||
334 | * |
||
335 | * @param string $name The name of the column to return the value for |
||
336 | * @param mixed|null $default The default value, that has to be returned, if the row's value is empty |
||
337 | * @param callable|null $callback The callback that has to be invoked on the value, e. g. to format it |
||
338 | * |
||
339 | * @return mixed|null The, almost formatted, value |
||
340 | */ |
||
341 | 8 | protected function getValue($name, $default = null, callable $callback = null) |
|
370 | |||
371 | /** |
||
372 | * Initialize's and return's a new entity with the status 'create'. |
||
373 | * |
||
374 | * @param array $attr The attributes to merge into the new entity |
||
375 | * |
||
376 | * @return array The initialized entity |
||
377 | */ |
||
378 | 5 | protected function initializeEntity(array $attr = array()) |
|
382 | |||
383 | /** |
||
384 | * Merge's and return's the entity with the passed attributes and set's the |
||
385 | * status to 'update'. |
||
386 | * |
||
387 | * @param array $entity The entity to merge the attributes into |
||
388 | * @param array $attr The attributes to be merged |
||
389 | * |
||
390 | * @return array The merged entity |
||
391 | */ |
||
392 | 2 | protected function mergeEntity(array $entity, array $attr) |
|
396 | } |
||
397 |