Completed
Push — master ( 9b3686...89ef78 )
by Bernhard
07:29
created

getProductMagic360ColumnsRepository()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/**
4
 * TechDivision\Import\Product\Magic360\Services\ProductMagic360Processor
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
 * @author    Bernhard Wick <[email protected]>
16
 * @copyright 2017 TechDivision GmbH <[email protected]>
17
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
 * @link      https://github.com/techdivision/import-product-magic360
19
 * @link      http://www.techdivision.com
20
 */
21
22
namespace TechDivision\Import\Product\Magic360\Services;
23
24
/**
25
 * A SLSB providing methods to load product data using a PDO connection.
26
 *
27
 * @author    Tim Wagner <[email protected]>
28
 * @author    Bernhard Wick <[email protected]>
29
 * @copyright 2017 TechDivision GmbH <[email protected]>
30
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
31
 * @link      https://github.com/techdivision/import-product-magic360
32
 * @link      http://www.techdivision.com
33
 */
34
class ProductMagic360Processor implements ProductMagic360ProcessorInterface
35
{
36
37
    /**
38
     * A PDO connection initialized with the values from the Doctrine EntityManager.
39
     *
40
     * @var \PDO
41
     */
42
    protected $connection;
43
44
    /**
45
     * The repository to load magic360 galleries.
46
     *
47
     * @var \TechDivision\Import\Product\Magic360\Repositories\ProductMagic360GalleryRepository
48
     */
49
    protected $productMagic360GalleryRepository;
50
51
    /**
52
     * The repository to load magic360 gallery to entities.
53
     *
54
     * @var \TechDivision\Import\Product\Magic360\Repositories\ProductMagic360ColumnsRepository
55
     */
56
    protected $productMagic360ColumnsRepository;
57
58
    /**
59
     * The action with the magic360 gallery CRUD methods.
60
     *
61
     * @var \TechDivision\Import\Product\Magic360\Actions\Magic360GalleryAction
62
     */
63
    protected $magic360GalleryAction;
64
65
    /**
66
     * The action with the magic360 gallery value CRUD methods.
67
     *
68
     * @var \TechDivision\Import\Product\Magic360\Actions\Magic360ColumnsAction
69
     */
70
    protected $magic360ColumnsAction;
71
72
    /**
73
     * Sets the passed connection.
74
     *
75
     * @param \PDO $connection The connection to set
76
     *
77
     * @return void
78
     */
79
    public function setConnection(\PDO $connection)
80
    {
81
        $this->connection = $connection;
82
    }
83
84
    /**
85
     * Returns the connection.
86
     *
87
     * @return \PDO The connection instance
88
     */
89
    public function getConnection()
90
    {
91
        return $this->connection;
92
    }
93
94
    /**
95
     * Turns off autocommit mode. While autocommit mode is turned off, changes made to the database via the PDO
96
     * object instance are not committed until you end the transaction by calling ProductProcessor::commit().
97
     * Calling ProductProcessor::rollBack() will roll back all changes to the database and return the connection
98
     * to autocommit mode.
99
     *
100
     * @return boolean Returns TRUE on success or FALSE on failure
101
     * @link http://php.net/manual/en/pdo.begintransaction.php
102
     */
103
    public function beginTransaction()
104
    {
105
        return $this->connection->beginTransaction();
106
    }
107
108
    /**
109
     * Commits a transaction, returning the database connection to autocommit mode until the next call to
110
     * ProductProcessor::beginTransaction() starts a new transaction.
111
     *
112
     * @return boolean Returns TRUE on success or FALSE on failure
113
     * @link http://php.net/manual/en/pdo.commit.php
114
     */
115
    public function commit()
116
    {
117
        return $this->connection->commit();
118
    }
119
120
    /**
121
     * Rolls back the current transaction, as initiated by ProductProcessor::beginTransaction().
122
     *
123
     * If the database was set to autocommit mode, this function will restore autocommit mode after it has
124
     * rolled back the transaction.
125
     *
126
     * Some databases, including MySQL, automatically issue an implicit COMMIT when a database definition
127
     * language (DDL) statement such as DROP TABLE or CREATE TABLE is issued within a transaction. The implicit
128
     * COMMIT will prevent you from rolling back any other changes within the transaction boundary.
129
     *
130
     * @return boolean Returns TRUE on success or FALSE on failure
131
     * @link http://php.net/manual/en/pdo.rollback.php
132
     */
133
    public function rollBack()
134
    {
135
        return $this->connection->rollBack();
136
    }
137
138
    /**
139
     * Sets the repository to load magic360 gallery data.
140
     *
141
     * @param \TechDivision\Import\Product\Magic360\Repositories\ProductMagic360GalleryRepository $productMagic360GalleryRepository The repository instance
142
     *
143
     * @return void
144
     */
145
    public function setProductMagic360GalleryRepository($productMagic360GalleryRepository)
146
    {
147
        $this->productMagic360GalleryRepository = $productMagic360GalleryRepository;
148
    }
149
150
    /**
151
     * Returns the repository to load magic360 gallery data.
152
     *
153
     * @return \TechDivision\Import\Product\Magic360\Repositories\ProductMagic360GalleryRepository The repository instance
154
     */
155
    public function getProductMagic360GalleryRepository()
156
    {
157
        return $this->productMagic360GalleryRepository;
158
    }
159
160
    /**
161
     * Sets the repository to load magic360 column data.
162
     *
163
     * @param \TechDivision\Import\Product\Magic360\Repositories\ProductMagic360ColumnsRepository $productMagic360ColumnsRepository The repository instance
164
     *
165
     * @return void
166
     */
167
    public function setProductMagic360ColumnsRepository($productMagic360ColumnsRepository)
168
    {
169
        $this->productMagic360ColumnsRepository = $productMagic360ColumnsRepository;
170
    }
171
172
    /**
173
     * Returns the repository to load magic360 column data.
174
     *
175
     * @return \TechDivision\Import\Product\Magic360\Repositories\ProductMagic360ColumnsRepository The repository instance
176
     */
177
    public function getProductMagic360ColumnsRepository()
178
    {
179
        return $this->productMagic360ColumnsRepository;
180
    }
181
182
    /**
183
     * Sets the action with the magic360 gallery CRUD methods.
184
     *
185
     * @param \TechDivision\Import\Product\Magic360\Actions\Magic360GalleryAction $magic360GalleryAction The action with the magic360 gallery CRUD methods
186
     *
187
     * @return void
188
     */
189
    public function setMagic360GalleryAction($magic360GalleryAction)
190
    {
191
        $this->magic360GalleryAction = $magic360GalleryAction;
192
    }
193
194
    /**
195
     * Returns the action with the magic360 gallery CRUD methods.
196
     *
197
     * @return \TechDivision\Import\Product\Magic360\Actions\Magic360GalleryAction $magic360GalleryAction The action with the magic360 gallery CRUD methods
198
     */
199
    public function getMagic360GalleryAction()
200
    {
201
        return $this->magic360GalleryAction;
202
    }
203
204
    /**
205
     * Sets the action with the magic360 column CRUD methods.
206
     *
207
     * @param \TechDivision\Import\Product\Magic360\Actions\Magic360ColumnsAction $magic360ColumnsAction The action with the magic360 column CRUD methods
208
     *
209
     * @return void
210
     */
211
    public function setMagic360ColumnsAction($magic360ColumnsAction)
212
    {
213
        $this->magic360ColumnsAction = $magic360ColumnsAction;
214
    }
215
216
    /**
217
     * Returns the action with the magic360 column CRUD methods.
218
     *
219
     * @return \TechDivision\Import\Product\Magic360\Actions\Magic360ColumnsAction The action with the magic360 column CRUD methods
220
     */
221
    public function getMagic360ColumnsAction()
222
    {
223
        return $this->magic360ColumnsAction;
224
    }
225
226
    /**
227
     * Persists the passed magic360 gallery data and returns the ID.
228
     *
229
     * @param array       $galleryEntry The magic360 gallery data to persist
230
     * @param string|null $name         The name of the prepared statement that has to be executed
231
     *
232
     * @return string The ID of the persisted entity
233
     */
234
    public function persistMagic360Gallery($galleryEntry, $name = null)
235
    {
236
        return $this->getMagic360GalleryAction()->persist($galleryEntry, $name);
0 ignored issues
show
Unused Code introduced by
The call to Magic360GalleryAction::persist() has too many arguments starting with $name.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
237
    }
238
239
    /**
240
     * Persists the passed magic360 column data.
241
     *
242
     * @param array       $magic360Columns The magic360 gallery value data to persist
243
     * @param string|null $name            The name of the prepared statement that has to be executed
244
     *
245
     * @return void
246
     */
247
    public function persistMagic360Columns($magic360Columns, $name = null)
248
    {
249
        $this->getMagic360ColumnsAction()->persist($magic360Columns, $name);
0 ignored issues
show
Unused Code introduced by
The call to Magic360ColumnsAction::persist() has too many arguments starting with $name.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
250
    }
251
252
    /**
253
     * Persists the passed magic360 gallery data and returns the ID.
254
     *
255
     * @param array       $row  The magic360 gallery data to persist
256
     * @param string|null $name The name of the prepared statement that has to be executed
257
     *
258
     * @return void
259
     */
260
    public function deleteMagic360Gallery($row, $name = null)
261
    {
262
        $this->getMagic360GalleryAction()->delete($row, $name);
263
    }
264
265
    /**
266
     * Persists the passed magic360 column data.
267
     *
268
     * @param array       $row  The magic360 column data to persist
269
     * @param string|null $name The name of the prepared statement that has to be executed
270
     *
271
     * @return void
272
     */
273
    public function deleteMagic360Columns($row, $name = null)
274
    {
275
        $this->getMagic360ColumnsAction()->delete($row, $name);
276
    }
277
278
    /**
279
     * Loads the magic360 gallery with the passed product ID and position
280
     *
281
     * @param integer $productId The product ID of the magic360 gallery to load
282
     * @param string  $position  The position of the magic360 gallery entry to load
283
     *
284
     * @return array The magic360 gallery
285
     */
286
    public function loadMagic360Gallery($productId, $position)
287
    {
288
        return $this->getProductMagic360GalleryRepository()->findOneByProductIdAndPosition($productId, $position);
289
    }
290
291
    /**
292
     * Loads the magic360 gallery with the passed product ID.
293
     *
294
     * @param integer $productId The product ID of the magic360 column to load
295
     *
296
     * @return array The magic360 gallery
297
     */
298
    public function loadMagic360Columns($productId)
299
    {
300
        return $this->getProductMagic360ColumnsRepository()->findOneByProductId($productId);
301
    }
302
}
303