Completed
Push — 19.x ( 7e93c9...2d1425 )
by Tim
01:33
created

getProductMediaGalleryValueVideoAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
/**
4
 * TechDivision\Import\Product\Media\Services\ProductMediaProcessor
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * This source file is subject to the Open Software License (OSL 3.0)
9
 * that is available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * PHP version 5
13
 *
14
 * @author    Tim Wagner <[email protected]>
15
 * @copyright 2016 TechDivision GmbH <[email protected]>
16
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
 * @link      https://github.com/techdivision/import-product-media
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Product\Media\Services;
22
23
use TechDivision\Import\Actions\ActionInterface;
24
use TechDivision\Import\Connection\ConnectionInterface;
25
use TechDivision\Import\Product\Media\Repositories\ProductMediaGalleryRepositoryInterface;
26
use TechDivision\Import\Product\Media\Repositories\ProductMediaGalleryValueRepositoryInterface;
27
use TechDivision\Import\Product\Media\Repositories\ProductMediaGalleryValueToEntityRepositoryInterface;
28
29
/**
30
 * The product media processor implementation.
31
 *
32
 * @author    Tim Wagner <[email protected]>
33
 * @copyright 2016 TechDivision GmbH <[email protected]>
34
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
35
 * @link      https://github.com/techdivision/import-product-media
36
 * @link      http://www.techdivision.com
37
 */
38
class ProductMediaProcessor implements ProductMediaProcessorInterface
39
{
40
41
    /**
42
     * A PDO connection initialized with the values from the Doctrine EntityManager.
43
     *
44
     * @var \TechDivision\Import\Connection\ConnectionInterface
45
     */
46
    protected $connection;
47
48
    /**
49
     * The repository to load product media galleries.
50
     *
51
     * @var \TechDivision\Import\Product\Media\Repositories\ProductMediaGalleryRepositoryInterface
52
     */
53
    protected $productMediaGalleryRepository;
54
55
    /**
56
     * The repository to load product media gallery to entities.
57
     *
58
     * @var \TechDivision\Import\Product\Media\Repositories\ProductMediaGalleryValueToEntityRepositoryInterface
59
     */
60
    protected $productMediaGalleryValueToEntityRepository;
61
62
    /**
63
     * The repository to load product media gallery values.
64
     *
65
     * @var \TechDivision\Import\Product\Media\Repositories\ProductMediaGalleryValueRepositoryInterface
66
     */
67
    protected $productMediaGalleryValueRepository;
68
69
    /**
70
     * The action with the product media gallery CRUD methods.
71
     *
72
     * @var \TechDivision\Import\Actions\ActionInterface
73
     */
74
    protected $productMediaGalleryAction;
75
76
    /**
77
     * The action with the product media gallery value CRUD methods.
78
     *
79
     * @var \TechDivision\Import\Actions\ActionInterface
80
     */
81
    protected $productMediaGalleryValueAction;
82
83
    /**
84
     * The action with the product media gallery value to entity CRUD methods.
85
     *
86
     * @var \TechDivision\Import\Actions\ActionInterface
87
     */
88
    protected $productMediaGalleryValueToEntityAction;
89
90
    /**
91
     * Initialize the processor with the necessary assembler and repository instances.
92
     *
93
     * @param \TechDivision\Import\Connection\ConnectionInterface                                                 $connection                                 The connection to use
94
     * @param \TechDivision\Import\Product\Media\Repositories\ProductMediaGalleryRepositoryInterface              $productMediaGalleryRepository              The product media gallery repository to use
95
     * @param \TechDivision\Import\Product\Media\Repositories\ProductMediaGalleryValueRepositoryInterface         $productMediaGalleryValueRepository         The product media gallery value repository to use
96
     * @param \TechDivision\Import\Product\Media\Repositories\ProductMediaGalleryValueToEntityRepositoryInterface $productMediaGalleryValueToEntityRepository The product media gallery value to entity repository to use
97
     * @param \TechDivision\Import\Actions\ActionInterface                                                        $productMediaGalleryAction                  The product media gallery action to use
98
     * @param \TechDivision\Import\Actions\ActionInterface                                                        $productMediaGalleryValueAction             The product media gallery value action to use
99
     * @param \TechDivision\Import\Actions\ActionInterface                                                        $productMediaGalleryValueToEntityAction     The product media gallery value to entity action to use
100
     */
101
    public function __construct(
102
        ConnectionInterface $connection,
103
        ProductMediaGalleryRepositoryInterface $productMediaGalleryRepository,
104
        ProductMediaGalleryValueRepositoryInterface $productMediaGalleryValueRepository,
105
        ProductMediaGalleryValueToEntityRepositoryInterface $productMediaGalleryValueToEntityRepository,
106
        ActionInterface $productMediaGalleryAction,
107
        ActionInterface $productMediaGalleryValueAction,
108
        ActionInterface $productMediaGalleryValueToEntityAction
109
    ) {
110
        $this->setConnection($connection);
111
        $this->setProductMediaGalleryRepository($productMediaGalleryRepository);
112
        $this->setProductMediaGalleryValueRepository($productMediaGalleryValueRepository);
113
        $this->setProductMediaGalleryValueToEntityRepository($productMediaGalleryValueToEntityRepository);
114
        $this->setProductMediaGalleryAction($productMediaGalleryAction);
115
        $this->setProductMediaGalleryValueAction($productMediaGalleryValueAction);
116
        $this->setProductMediaGalleryValueToEntityAction($productMediaGalleryValueToEntityAction);
117
    }
118
119
    /**
120
     * Set's the passed connection.
121
     *
122
     * @param \TechDivision\Import\Connection\ConnectionInterface $connection The connection to set
123
     *
124
     * @return void
125
     */
126
    public function setConnection(ConnectionInterface $connection)
127
    {
128
        $this->connection = $connection;
129
    }
130
131
    /**
132
     * Return's the connection.
133
     *
134
     * @return \TechDivision\Import\Connection\ConnectionInterface The connection instance
135
     */
136
    public function getConnection()
137
    {
138
        return $this->connection;
139
    }
140
141
    /**
142
     * Turns off autocommit mode. While autocommit mode is turned off, changes made to the database via the PDO
143
     * object instance are not committed until you end the transaction by calling ProductProcessor::commit().
144
     * Calling ProductProcessor::rollBack() will roll back all changes to the database and return the connection
145
     * to autocommit mode.
146
     *
147
     * @return boolean Returns TRUE on success or FALSE on failure
148
     * @link http://php.net/manual/en/pdo.begintransaction.php
149
     */
150
    public function beginTransaction()
151
    {
152
        return $this->connection->beginTransaction();
153
    }
154
155
    /**
156
     * Commits a transaction, returning the database connection to autocommit mode until the next call to
157
     * ProductProcessor::beginTransaction() starts a new transaction.
158
     *
159
     * @return boolean Returns TRUE on success or FALSE on failure
160
     * @link http://php.net/manual/en/pdo.commit.php
161
     */
162
    public function commit()
163
    {
164
        return $this->connection->commit();
165
    }
166
167
    /**
168
     * Rolls back the current transaction, as initiated by ProductProcessor::beginTransaction().
169
     *
170
     * If the database was set to autocommit mode, this function will restore autocommit mode after it has
171
     * rolled back the transaction.
172
     *
173
     * Some databases, including MySQL, automatically issue an implicit COMMIT when a database definition
174
     * language (DDL) statement such as DROP TABLE or CREATE TABLE is issued within a transaction. The implicit
175
     * COMMIT will prevent you from rolling back any other changes within the transaction boundary.
176
     *
177
     * @return boolean Returns TRUE on success or FALSE on failure
178
     * @link http://php.net/manual/en/pdo.rollback.php
179
     */
180
    public function rollBack()
181
    {
182
        return $this->connection->rollBack();
183
    }
184
185
    /**
186
     * Set's the repository to load product media gallery data.
187
     *
188
     * @param \TechDivision\Import\Product\Media\Repositories\ProductMediaGalleryRepositoryInterface $productMediaGalleryRepository The repository instance
189
     *
190
     * @return void
191
     */
192
    public function setProductMediaGalleryRepository(ProductMediaGalleryRepositoryInterface $productMediaGalleryRepository)
193
    {
194
        $this->productMediaGalleryRepository = $productMediaGalleryRepository;
195
    }
196
197
    /**
198
     * Return's the repository to load product media gallery data.
199
     *
200
     * @return \TechDivision\Import\Product\Media\Repositories\ProductMediaGalleryRepositoryInterface The repository instance
201
     */
202
    public function getProductMediaGalleryRepository()
203
    {
204
        return $this->productMediaGalleryRepository;
205
    }
206
207
    /**
208
     * Set's the repository to load product media gallery value to entity data.
209
     *
210
     * @param \TechDivision\Import\Product\Media\Repositories\ProductMediaGalleryValueToEntityRepositoryInterface $productMediaGalleryValueToEntityRepository The repository instance
211
     *
212
     * @return void
213
     */
214
    public function setProductMediaGalleryValueToEntityRepository(ProductMediaGalleryValueToEntityRepositoryInterface $productMediaGalleryValueToEntityRepository)
215
    {
216
        $this->productMediaGalleryValueToEntityRepository = $productMediaGalleryValueToEntityRepository;
217
    }
218
219
    /**
220
     * Return's the repository to load product media gallery value to entity data.
221
     *
222
     * @return \TechDivision\Import\Product\Media\Repositories\ProductMediaGalleryValueToEntityRepositoryInterface The repository instance
223
     */
224
    public function getProductMediaGalleryValueToEntityRepository()
225
    {
226
        return $this->productMediaGalleryValueToEntityRepository;
227
    }
228
229
    /**
230
     * Set's the repository to load product media gallery value data.
231
     *
232
     * @param \TechDivision\Import\Product\Media\Repositories\ProductMediaGalleryValueRepositoryInterface $productMediaGalleryValueRepository The repository instance
233
     *
234
     * @return void
235
     */
236
    public function setProductMediaGalleryValueRepository(ProductMediaGalleryValueRepositoryInterface $productMediaGalleryValueRepository)
237
    {
238
        $this->productMediaGalleryValueRepository = $productMediaGalleryValueRepository;
239
    }
240
241
    /**
242
     * Return's the repository to load product media gallery value data.
243
     *
244
     * @return \TechDivision\Import\Product\Media\Repositories\ProductMediaGalleryValueRepositoryInterface The repository instance
245
     */
246
    public function getProductMediaGalleryValueRepository()
247
    {
248
        return $this->productMediaGalleryValueRepository;
249
    }
250
251
    /**
252
     * Set's the action with the product media gallery CRUD methods.
253
     *
254
     * @param \TechDivision\Import\Actions\ActionInterface $productMediaGalleryAction The action with the product media gallery CRUD methods
255
     *
256
     * @return void
257
     */
258
    public function setProductMediaGalleryAction(ActionInterface $productMediaGalleryAction)
259
    {
260
        $this->productMediaGalleryAction = $productMediaGalleryAction;
261
    }
262
263
    /**
264
     * Return's the action with the product media gallery CRUD methods.
265
     *
266
     * @return \TechDivision\Import\Actions\ActionInterface The action with the product media gallery CRUD methods
267
     */
268
    public function getProductMediaGalleryAction()
269
    {
270
        return $this->productMediaGalleryAction;
271
    }
272
273
    /**
274
     * Set's the action with the product media gallery valueCRUD methods.
275
     *
276
     * @param \TechDivision\Import\Actions\ActionInterface $productMediaGalleryValueAction The action with the product media gallery value CRUD methods
277
     *
278
     * @return void
279
     */
280
    public function setProductMediaGalleryValueAction(ActionInterface $productMediaGalleryValueAction)
281
    {
282
        $this->productMediaGalleryValueAction = $productMediaGalleryValueAction;
283
    }
284
285
    /**
286
     * Return's the action with the product media gallery valueCRUD methods.
287
     *
288
     * @return \TechDivision\Import\Actions\ActionInterface The action with the product media gallery value CRUD methods
289
     */
290
    public function getProductMediaGalleryValueAction()
291
    {
292
        return $this->productMediaGalleryValueAction;
293
    }
294
295
    /**
296
     * Set's the action with the product media gallery value to entity CRUD methods.
297
     *
298
     * @param \TechDivision\Import\Actions\ActionInterface $productMediaGalleryValueToEntityAction The action with the product media gallery value to entity CRUD methods
299
     *
300
     * @return void
301
     */
302
    public function setProductMediaGalleryValueToEntityAction(ActionInterface $productMediaGalleryValueToEntityAction)
303
    {
304
        $this->productMediaGalleryValueToEntityAction = $productMediaGalleryValueToEntityAction;
305
    }
306
307
    /**
308
     * Return's the action with the product media gallery value to entity CRUD methods.
309
     *
310
     * @return \TechDivision\Import\Actions\ActionInterface $productMediaGalleryAction The action with the product media gallery value to entity CRUD methods
311
     */
312
    public function getProductMediaGalleryValueToEntityAction()
313
    {
314
        return $this->productMediaGalleryValueToEntityAction;
315
    }
316
317
    /**
318
     * Load's the product media gallery with the passed attribute ID + value.
319
     *
320
     * @param integer $attributeId The attribute ID of the product media gallery to load
321
     * @param string  $value       The value of the product media gallery to load
322
     *
323
     * @return array The product media gallery
324
     */
325
    public function loadProductMediaGallery($attributeId, $value)
326
    {
327
        return $this->getProductMediaGalleryRepository()->findOneByAttributeIdAndValue($attributeId, $value);
328
    }
329
330
    /**
331
     * Load's the product media gallery with the passed value/entity ID.
332
     *
333
     * @param integer $valueId  The value ID of the product media gallery value to entity to load
334
     * @param integer $entityId The entity ID of the product media gallery value to entity to load
335
     *
336
     * @return array The product media gallery
337
     */
338
    public function loadProductMediaGalleryValueToEntity($valueId, $entityId)
339
    {
340
        return $this->getProductMediaGalleryValueToEntityRepository()->findOneByValueIdAndEntityId($valueId, $entityId);
341
    }
342
343
    /**
344
     * Load's the product media gallery value with the passed value/store/parent ID.
345
     *
346
     * @param integer $valueId  The value ID of the product media gallery value to load
347
     * @param string  $storeId  The store ID of the product media gallery value to load
348
     * @param string  $entityId The entity ID of the parent product of the product media gallery value to load
349
     *
350
     * @return array The product media gallery value
351
     */
352
    public function loadProductMediaGalleryValue($valueId, $storeId, $entityId)
353
    {
354
        return $this->getProductMediaGalleryValueRepository()->findOneByValueIdAndStoreIdAndEntityId($valueId, $storeId, $entityId);
355
    }
356
357
    /**
358
     * Load's the product media gallery entities with the passed SKU.
359
     *
360
     * @param string $sku The SKU to load the media gallery entities for
361
     *
362
     * @return array The product media gallery entities
363
     */
364
    public function getProductMediaGalleriesBySku($sku)
365
    {
366
        return $this->getProductMediaGalleryRepository()->findAllBySku($sku);
367
    }
368
369
    /**
370
     * Persist's the passed product media gallery data and return's the ID.
371
     *
372
     * @param array       $productMediaGallery The product media gallery data to persist
373
     * @param string|null $name                The name of the prepared statement that has to be executed
374
     *
375
     * @return string The ID of the persisted entity
376
     */
377
    public function persistProductMediaGallery($productMediaGallery, $name = null)
378
    {
379
        return $this->getProductMediaGalleryAction()->persist($productMediaGallery, $name);
380
    }
381
382
    /**
383
     * Persist's the passed product media gallery value data.
384
     *
385
     * @param array       $productMediaGalleryValue The product media gallery value data to persist
386
     * @param string|null $name                     The name of the prepared statement that has to be executed
387
     *
388
     * @return void
389
     */
390
    public function persistProductMediaGalleryValue($productMediaGalleryValue, $name = null)
391
    {
392
        $this->getProductMediaGalleryValueAction()->persist($productMediaGalleryValue, $name);
393
    }
394
395
    /**
396
     * Persist's the passed product media gallery value to entity data.
397
     *
398
     * @param array       $productMediaGalleryValuetoEntity The product media gallery value to entity data to persist
399
     * @param string|null $name                             The name of the prepared statement that has to be executed
400
     *
401
     * @return void
402
     */
403
    public function persistProductMediaGalleryValueToEntity($productMediaGalleryValuetoEntity, $name = null)
404
    {
405
        $this->getProductMediaGalleryValueToEntityAction()->persist($productMediaGalleryValuetoEntity, $name);
406
    }
407
408
    /**
409
     * Delete's the passed product media gallery data.
410
     *
411
     * @param array       $row  The product media gallery data to be deleted
412
     * @param string|null $name The name of the prepared statement that has to be executed
413
     *
414
     * @return string The ID of the persisted entity
415
     */
416
    public function deleteProductMediaGallery(array $row, $name = null)
417
    {
418
        return $this->getProductMediaGalleryAction()->delete($row, $name);
419
    }
420
}
421