|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* TechDivision\Import\Repositories\StoreRepository |
|
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\Repositories; |
|
22
|
|
|
|
|
23
|
|
|
use TechDivision\Import\Utils\MemberNames; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Repository implementation to load store data. |
|
27
|
|
|
* |
|
28
|
|
|
* @author Tim Wagner <[email protected]> |
|
29
|
|
|
* @copyright 2016 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 |
|
32
|
|
|
* @link http://www.techdivision.com |
|
33
|
|
|
*/ |
|
34
|
|
|
class StoreRepository extends AbstractRepository |
|
35
|
|
|
{ |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Initializes the repository's prepared statements. |
|
39
|
|
|
* |
|
40
|
|
|
* @return void |
|
41
|
|
|
*/ |
|
42
|
|
|
public function init() |
|
43
|
|
|
{ |
|
44
|
|
|
|
|
45
|
|
|
// load the utility class name |
|
46
|
|
|
$utilityClassName = $this->getUtilityClassName(); |
|
47
|
|
|
|
|
48
|
|
|
// initialize the prepared statements |
|
49
|
|
|
$this->storesStmt = $this->getConnection()->prepare($utilityClassName::STORES); |
|
|
|
|
|
|
50
|
|
|
$this->storeDefaultStmt = $this->getConnection()->prepare($utilityClassName::STORE_DEFAULT); |
|
|
|
|
|
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Return's an array with the available stores and their |
|
55
|
|
|
* store codes as keys. |
|
56
|
|
|
* |
|
57
|
|
|
* @return array The array with all available stores |
|
58
|
|
|
*/ |
|
59
|
|
|
public function findAll() |
|
60
|
|
|
{ |
|
61
|
|
|
|
|
62
|
|
|
// initialize the array with the available stores |
|
63
|
|
|
$stores = array(); |
|
64
|
|
|
|
|
65
|
|
|
// execute the prepared statement |
|
66
|
|
|
$this->storesStmt->execute(); |
|
67
|
|
|
|
|
68
|
|
|
// fetch the stores and assemble them as array with the store code as key |
|
69
|
|
|
foreach ($this->storesStmt->fetchAll() as $store) { |
|
70
|
|
|
$stores[$store[MemberNames::CODE]] = $store; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
// return the array with the stores |
|
74
|
|
|
return $stores; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Return's the default store. |
|
79
|
|
|
* |
|
80
|
|
|
* @return array The default store |
|
81
|
|
|
*/ |
|
82
|
|
|
public function findOneByDefault() |
|
83
|
|
|
{ |
|
84
|
|
|
|
|
85
|
|
|
// execute the prepared statement and return the default store |
|
86
|
|
|
$this->storeDefaultStmt->execute(); |
|
87
|
|
|
return $this->storeDefaultStmt->fetch(); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: