Completed
Pull Request — master (#8)
by Tim
06:21
created

ImportProcessor::getStoreRepository()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

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
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
/**
4
 * TechDivision\Import\Services\ImportProcessor
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
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Services;
22
23
/**
24
 * Processor implementation to load global data.
25
 *
26
 * @author    Tim Wagner <[email protected]>
27
 * @copyright 2016 TechDivision GmbH <[email protected]>
28
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
 * @link      https://github.com/techdivision/import
30
 * @link      http://www.techdivision.com
31
 */
32
class ImportProcessor implements ImportProcessorInterface
33
{
34
35
    /**
36
     * A PDO connection initialized with the values from the Doctrine EntityManager.
37
     *
38
     * @var \PDO
39
     */
40
    protected $connection;
41
42
    /**
43
     * The repository to access categories.
44
     *
45
     * @var \TechDivision\Import\Repositories\CategoryRepository
46
     */
47
    protected $categoryRepository;
48
49
    /**
50
     * The repository to access category varchar values.
51
     *
52
     * @var \TechDivision\Import\Repositories\CategoryVarcharRepository
53
     */
54
    protected $categoryVarcharRepository;
55
56
    /**
57
     * The repository to access EAV attributes.
58
     *
59
     * @var \TechDivision\Import\Repositories\EavAttributeRepository
60
     */
61
    protected $eavAttributeRepository;
62
63
    /**
64
     * The repository to access EAV attribute set.
65
     *
66
     * @var \TechDivision\Import\Repositories\EavAttributeSetRepository
67
     */
68
    protected $eavAttributeSetRepository;
69
70
    /**
71
     * The repository to access stores.
72
     *
73
     * @var \TechDivision\Import\Repositories\StoreRepository
74
     */
75
    protected $storeRepository;
76
77
    /**
78
     * The repository to access store websites.
79
     *
80
     * @var \TechDivision\Import\Repositories\StoreWebsiteRepository
81
     */
82
    protected $storeWebsiteRepository;
83
84
    /**
85
     * The repository to access tax classes.
86
     *
87
     * @var \TechDivision\Import\Repositories\TaxClassRepository
88
     */
89
    protected $taxClassRepository;
90
91
    /**
92
     * The repository to access link types.
93
     *
94
     * @var \TechDivision\Import\Repositories\LinkTypeRepository
95
     */
96
    protected $linkTypeRepository;
97
98
    /**
99
     * Set's the passed connection.
100
     *
101
     * @param \PDO $connection The connection to set
102
     *
103
     * @return void
104
     */
105
    public function setConnection(\PDO $connection)
106
    {
107
        $this->connection = $connection;
108
    }
109
110
    /**
111
     * Return's the connection.
112
     *
113
     * @return \PDO The connection instance
114
     */
115
    public function getConnection()
116
    {
117
        return $this->connection;
118
    }
119
120
    /**
121
     * Turns off autocommit mode. While autocommit mode is turned off, changes made to the database via the PDO
122
     * object instance are not committed until you end the transaction by calling ProductProcessor::commit().
123
     * Calling ProductProcessor::rollBack() will roll back all changes to the database and return the connection
124
     * to autocommit mode.
125
     *
126
     * @return boolean Returns TRUE on success or FALSE on failure
127
     * @link http://php.net/manual/en/pdo.begintransaction.php
128
     */
129
    public function beginTransaction()
130
    {
131
        return $this->connection->beginTransaction();
132
    }
133
134
    /**
135
     * Commits a transaction, returning the database connection to autocommit mode until the next call to
136
     * ProductProcessor::beginTransaction() starts a new transaction.
137
     *
138
     * @return boolean Returns TRUE on success or FALSE on failure
139
     * @link http://php.net/manual/en/pdo.commit.php
140
     */
141
    public function commit()
142
    {
143
        return $this->connection->commit();
144
    }
145
146
    /**
147
     * Rolls back the current transaction, as initiated by ProductProcessor::beginTransaction().
148
     *
149
     * If the database was set to autocommit mode, this function will restore autocommit mode after it has
150
     * rolled back the transaction.
151
     *
152
     * Some databases, including MySQL, automatically issue an implicit COMMIT when a database definition
153
     * language (DDL) statement such as DROP TABLE or CREATE TABLE is issued within a transaction. The implicit
154
     * COMMIT will prevent you from rolling back any other changes within the transaction boundary.
155
     *
156
     * @return boolean Returns TRUE on success or FALSE on failure
157
     * @link http://php.net/manual/en/pdo.rollback.php
158
     */
159
    public function rollBack()
160
    {
161
        return $this->connection->rollBack();
162
    }
163
164
    /**
165
     * Set's the repository to access categories.
166
     *
167
     * @param \TechDivision\Import\Repositories\CategoryRepository $categoryRepository The repository to access categories
168
     *
169
     * @return void
170
     */
171
    public function setCategoryRepository($categoryRepository)
172
    {
173
        $this->categoryRepository = $categoryRepository;
174
    }
175
176
    /**
177
     * Return's the repository to access categories.
178
     *
179
     * @return \TechDivision\Import\Repositories\CategoryRepository The repository instance
180
     */
181
    public function getCategoryRepository()
182
    {
183
        return $this->categoryRepository;
184
    }
185
186
    /**
187
     * Return's the repository to access category varchar values.
188
     *
189
     * @param \TechDivision\Import\Repositories\CategoryVarcharRepository $categoryVarcharRepository The repository instance
190
     *
191
     * @return void
192
     */
193
    public function setCategoryVarcharRepository($categoryVarcharRepository)
194
    {
195
        $this->categoryVarcharRepository = $categoryVarcharRepository;
196
    }
197
198
    /**
199
     * Return's the repository to access category varchar values.
200
     *
201
     * @return \TechDivision\Import\Repositories\CategoryVarcharRepository The repository instance
202
     */
203
    public function getCategoryVarcharRepository()
204
    {
205
        return $this->categoryVarcharRepository;
206
    }
207
208
    /**
209
     * Set's the repository to access EAV attributes.
210
     *
211
     * @param \TechDivision\Import\Repositories\EavAttributeRepository $eavAttributeRepository The repository to access EAV attributes
212
     *
213
     * @return void
214
     */
215
    public function setEavAttributeRepository($eavAttributeRepository)
216
    {
217
        $this->eavAttributeRepository = $eavAttributeRepository;
218
    }
219
220
    /**
221
     * Return's the repository to access EAV attributes.
222
     *
223
     * @return \TechDivision\Import\Repositories\EavAttributeRepository The repository instance
224
     */
225
    public function getEavAttributeRepository()
226
    {
227
        return $this->eavAttributeRepository;
228
    }
229
230
    /**
231
     * Set's the repository to access EAV attribute sets.
232
     *
233
     * @param \TechDivision\Import\Repositories\EavAttributeSetRepository $eavAttributeSetRepository The repository the access EAV attribute sets
234
     *
235
     * @return void
236
     */
237
    public function setEavAttributeSetRepository($eavAttributeSetRepository)
238
    {
239
        $this->eavAttributeSetRepository = $eavAttributeSetRepository;
240
    }
241
242
    /**
243
     * Return's the repository to access EAV attribute sets.
244
     *
245
     * @return \TechDivision\Import\Repositories\EavAttributeSetRepository The repository instance
246
     */
247
    public function getEavAttributeSetRepository()
248
    {
249
        return $this->eavAttributeSetRepository;
250
    }
251
252
    /**
253
     * Set's the repository to access stores.
254
     *
255
     * @param \TechDivision\Import\Repositories\StoreRepository $storeRepository The repository the access stores
256
     *
257
     * @return void
258
     */
259
    public function setStoreRepository($storeRepository)
260
    {
261
        $this->storeRepository = $storeRepository;
262
    }
263
264
    /**
265
     * Return's the repository to access stores.
266
     *
267
     * @return \TechDivision\Import\Repositories\StoreRepository The repository instance
268
     */
269
    public function getStoreRepository()
270
    {
271
        return $this->storeRepository;
272
    }
273
274
    /**
275
     * Set's the repository to access store websites.
276
     *
277
     * @param \TechDivision\Import\Repositories\StoreWebsiteRepository $storeWebsiteRepository The repository the access store websites
278
     *
279
     * @return void
280
     */
281
    public function setStoreWebsiteRepository($storeWebsiteRepository)
282
    {
283
        $this->storeWebsiteRepository = $storeWebsiteRepository;
284
    }
285
286
    /**
287
     * Return's the repository to access store websites.
288
     *
289
     * @return \TechDivision\Import\Repositories\StoreWebsiteRepository The repository instance
290
     */
291
    public function getStoreWebsiteRepository()
292
    {
293
        return $this->storeWebsiteRepository;
294
    }
295
296
    /**
297
     * Set's the repository to access tax classes.
298
     *
299
     * @param \TechDivision\Import\Repositories\TaxClassRepository $taxClassRepository The repository the access stores
300
     *
301
     * @return void
302
     */
303
    public function setTaxClassRepository($taxClassRepository)
304
    {
305
        $this->taxClassRepository = $taxClassRepository;
306
    }
307
308
    /**
309
     * Return's the repository to access tax classes.
310
     *
311
     * @return \TechDivision\Import\Repositories\TaxClassRepository The repository instance
312
     */
313
    public function getTaxClassRepository()
314
    {
315
        return $this->taxClassRepository;
316
    }
317
318
    /**
319
     * Set's the repository to access link types.
320
     *
321
     * @param \TechDivision\Import\Repositories\LinkTypeRepository $linkTypeRepository The repository to access link types
322
     *
323
     * @return void
324
     */
325
    public function setLinkTypeRepository($linkTypeRepository)
326
    {
327
        $this->linkTypeRepository = $linkTypeRepository;
328
    }
329
330
    /**
331
     * Return's the repository to access categories.
332
     *
333
     * @return \TechDivision\Import\Repositories\CategoryRepository The repository instance
334
     */
335
    public function getLinkTypeRepository()
336
    {
337
        return $this->linkTypeRepository;
338
    }
339
340
    /**
341
     * Return's the EAV attribute set with the passed ID.
342
     *
343
     * @param integer $id The ID of the EAV attribute set to load
344
     *
345
     * @return array The EAV attribute set
346
     */
347
    public function getEavAttributeSet($id)
348
    {
349
        return $this->getEavAttributeSetRepository()->load($id);
350
    }
351
352
    /**
353
     * Return's the attribute sets for the passed entity type ID.
354
     *
355
     * @param mixed $entityTypeId The entity type ID to return the attribute sets for
356
     *
357
     * @return array|boolean The attribute sets for the passed entity type ID
358
     */
359
    public function getEavAttributeSetsByEntityTypeId($entityTypeId)
360
    {
361
        return $this->getEavAttributeSetRepository()->findAllByEntityTypeId($entityTypeId);
362
    }
363
364
    /**
365
     * Return's an array with the EAV attributes for the passed entity type ID and attribute set name.
366
     *
367
     * @param integer $entityTypeId     The entity type ID of the EAV attributes to return
368
     * @param string  $attributeSetName The attribute set name of the EAV attributes to return
369
     *
370
     * @return array The
371
     */
372
    public function getEavAttributesByEntityTypeIdAndAttributeSetName($entityTypeId, $attributeSetName)
373
    {
374
        return $this->getEavAttributeRepository()->findAllByEntityTypeIdAndAttributeSetName($entityTypeId, $attributeSetName);
375
    }
376
377
    /**
378
     * Return's an array with the available EAV attributes for the passed option value and store ID.
379
     *
380
     * @param string $optionValue The option value of the EAV attributes
381
     * @param string $storeId     The store ID of the EAV attribues
382
     *
383
     * @return array The array with all available EAV attributes
384
     */
385
    public function getEavAttributesByOptionValueAndStoreId($optionValue, $storeId)
386
    {
387
        return $this->getEavAttributeRepository()->findAllByOptionValueAndStoreId($optionValue, $storeId);
388
    }
389
390
    /**
391
     * Return's the first EAV attribute for the passed option value and store ID.
392
     *
393
     * @param string $optionValue The option value of the EAV attributes
394
     * @param string $storeId     The store ID of the EAV attribues
395
     *
396
     * @return array The array with the EAV attribute
397
     */
398
    public function getEavAttributeByOptionValueAndStoreId($optionValue, $storeId)
399
    {
400
        return $this->getEavAttributeRepository()->findOneByOptionValueAndStoreId($optionValue, $storeId);
401
    }
402
403
    /**
404
     * Return's an array with the available stores.
405
     *
406
     * @return array The array with the available stores
407
     */
408
    public function getStores()
409
    {
410
        return $this->getStoreRepository()->findAll();
411
    }
412
413
    /**
414
     * Return's the default store.
415
     *
416
     * @return array The default store
417
     */
418
    public function getDefaultStore()
419
    {
420
        return $this->getStoreRepository()->findOneByDefault();
421
    }
422
423
    /**
424
     * Return's an array with the available store websites.
425
     *
426
     * @return array The array with the available store websites
427
     */
428
    public function getStoreWebsites()
429
    {
430
        return $this->getStoreWebsiteRepository()->findAll();
431
    }
432
433
    /**
434
     * Return's an array with the available tax classes.
435
     *
436
     * @return array The array with the available tax classes
437
     */
438
    public function getTaxClasses()
439
    {
440
        return $this->getTaxClassRepository()->findAll();
441
    }
442
443
    /**
444
     * Return's an array with all available categories.
445
     *
446
     * @return array The available categories
447
     */
448
    public function getCategories()
449
    {
450
        return $this->getCategoryRepository()->findAll();
451
    }
452
453
    /**
454
     * Return's an array with the root categories with the store code as key.
455
     *
456
     * @return array The root categories
457
     */
458
    public function getRootCategories()
459
    {
460
        return $this->getCategoryRepository()->findAllRootCategories();
461
    }
462
463
    /**
464
     * Returns the category varchar values for the categories with
465
     * the passed with the passed entity IDs.
466
     *
467
     * @param array $entityIds The array with the category IDs
468
     *
469
     * @return mixed The category varchar values
470
     */
471
    public function getCategoryVarcharsByEntityIds(array $entityIds)
472
    {
473
        return $this->getCategoryVarcharRepository()->findAllByEntityIds($entityIds);
474
    }
475
476
    /**
477
     * Return's an array with all available link types.
478
     *
479
     * @return array The available link types
480
     */
481
    public function getLinkTypes()
482
    {
483
        return $this->getLinkTypeRepository()->findAll();
484
    }
485
}
486