Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
76.92% |
40 / 52 |
|
35.71% |
5 / 14 |
CRAP | |
0.00% |
0 / 1 |
FileAccess | |
76.92% |
40 / 52 |
|
35.71% |
5 / 14 |
24.92 | |
0.00% |
0 / 1 |
__construct | |
80.00% |
8 / 10 |
|
0.00% |
0 / 1 |
6.29 | |||
loadFromPath | |
91.67% |
11 / 12 |
|
0.00% |
0 / 1 |
2.00 | |||
loadLocationsFromPathByLocale | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
loadServicesFromPathByLocale | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
loadTopicsFromPathByLocale | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
loadAuthoritiesFromPathByLocale | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
loadSettingsFromPath | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
loadLocations | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
loadServices | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
loadTopics | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
loadSettings | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
loadAuthorities | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
fetchTopicServicesList | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
fetchLocationListByOffice | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | /** |
4 | * @package 115Mandant |
5 | * @copyright BerlinOnline Stadtportal GmbH & Co. KG |
6 | **/ |
7 | |
8 | namespace BO\Zmsdldb; |
9 | |
10 | /** |
11 | * @SuppressWarnings(PHPMD.TooManyPublicMethods) |
12 | */ |
13 | class FileAccess extends AbstractAccess |
14 | { |
15 | /** |
16 | * Parameters for json files are deprecated, try using loadFromPath() instead |
17 | * |
18 | * @return self |
19 | */ |
20 | public function __construct( |
21 | $locationJson = null, |
22 | $serviceJson = null, |
23 | $topicsJson = null, |
24 | $authoritiesJson = null, |
25 | $settingsJson = null |
26 | ) { |
27 | if (null !== $locationJson) { |
28 | $this->loadLocations($locationJson); |
29 | } |
30 | if (null !== $serviceJson) { |
31 | $this->loadServices($serviceJson); |
32 | } |
33 | if (null !== $topicsJson) { |
34 | $this->loadTopics($topicsJson); |
35 | } |
36 | if (null !== $authoritiesJson) { |
37 | $this->loadAuthorities($authoritiesJson); |
38 | } |
39 | if (null !== $settingsJson) { |
40 | $this->loadSettings($settingsJson); |
41 | } |
42 | } |
43 | |
44 | /** |
45 | * Parameters for json files are deprecated, try using loadFromPath() instead |
46 | * |
47 | * @return self |
48 | */ |
49 | public function loadFromPath($path) |
50 | { |
51 | if (!is_dir($path)) { |
52 | throw new Exception("Could not read directory $path"); |
53 | } |
54 | $this->loadAuthorities($path . DIRECTORY_SEPARATOR . 'authority_de.json', 'de'); |
55 | $this->loadAuthorities($path . DIRECTORY_SEPARATOR . 'authority_de.json', 'en'); |
56 | $this->loadLocations($path . DIRECTORY_SEPARATOR . 'locations_de.json', 'de'); |
57 | $this->loadLocations($path . DIRECTORY_SEPARATOR . 'locations_en.json', 'en'); |
58 | $this->loadServices($path . DIRECTORY_SEPARATOR . 'services_de.json', 'de'); |
59 | $this->loadServices($path . DIRECTORY_SEPARATOR . 'services_en.json', 'en'); |
60 | $this->loadSettings($path . DIRECTORY_SEPARATOR . 'settings.json'); |
61 | $this->loadTopics($path . DIRECTORY_SEPARATOR . 'topic_de.json', 'de'); |
62 | $this->loadTopics($path . DIRECTORY_SEPARATOR . 'topic_de.json', 'en'); |
63 | return $this; |
64 | } |
65 | |
66 | public function loadLocationsFromPathByLocale($path, $locale) |
67 | { |
68 | $this->loadLocations($path . DIRECTORY_SEPARATOR . 'locations_' . $locale . '.json', $locale); |
69 | } |
70 | |
71 | public function loadServicesFromPathByLocale($path, $locale) |
72 | { |
73 | $this->loadServices($path . DIRECTORY_SEPARATOR . 'services_' . $locale . '.json', $locale); |
74 | } |
75 | |
76 | public function loadTopicsFromPathByLocale($path, $locale) |
77 | { |
78 | $this->loadTopics($path . DIRECTORY_SEPARATOR . 'topic_' . $locale . '.json', $locale); |
79 | } |
80 | |
81 | public function loadAuthoritiesFromPathByLocale($path, $locale) |
82 | { |
83 | $this->loadAuthorities($path . DIRECTORY_SEPARATOR . 'authority_' . $locale . '.json', $locale); |
84 | } |
85 | |
86 | public function loadSettingsFromPath($path) |
87 | { |
88 | $this->loadSettings($path . DIRECTORY_SEPARATOR . 'settings.json'); |
89 | } |
90 | |
91 | /** |
92 | * |
93 | * @return self |
94 | */ |
95 | public function loadLocations($locationJson, $locale = 'de') |
96 | { |
97 | $this->accessInstance[$locale]['Location'] = new File\Location($locationJson, $locale); |
98 | $this->accessInstance[$locale]['Location']->setAccessInstance($this); |
99 | return $this; |
100 | } |
101 | |
102 | /** |
103 | * |
104 | * @return self |
105 | */ |
106 | public function loadServices($serviceJson, $locale = 'de') |
107 | { |
108 | $this->accessInstance[$locale]['Service'] = new File\Service($serviceJson, $locale); |
109 | $this->accessInstance[$locale]['Service']->setAccessInstance($this); |
110 | return $this; |
111 | } |
112 | |
113 | /** |
114 | * |
115 | * @return self |
116 | */ |
117 | public function loadTopics($topicJson, $locale = 'de') |
118 | { |
119 | $this->accessInstance[$locale]['Topic'] = new File\Topic($topicJson, $locale); |
120 | $this->accessInstance[$locale]['Topic']->setAccessInstance($this); |
121 | $this->accessInstance[$locale]['Link'] = new File\Link($topicJson, $locale); |
122 | $this->accessInstance[$locale]['Link']->setAccessInstance($this); |
123 | return $this; |
124 | } |
125 | |
126 | /** |
127 | * |
128 | * @return self |
129 | */ |
130 | public function loadSettings($settingsJson) |
131 | { |
132 | $this->accessInstance['de']['Setting'] = new File\Setting($settingsJson); |
133 | $this->accessInstance['de']['Setting']->setAccessInstance($this); |
134 | $this->accessInstance['de']['Office'] = new File\Office($settingsJson); |
135 | $this->accessInstance['de']['Office']->setAccessInstance($this); |
136 | $this->accessInstance['de']['Borough'] = new File\Borough($settingsJson); |
137 | $this->accessInstance['de']['Borough']->setAccessInstance($this); |
138 | return $this; |
139 | } |
140 | |
141 | /** |
142 | * |
143 | * @return self |
144 | */ |
145 | public function loadAuthorities($authorityJson, $locale = 'de') |
146 | { |
147 | $this->accessInstance[$locale]['Authority'] = new File\Authority($authorityJson, $locale); |
148 | $this->accessInstance[$locale]['Authority']->setAccessInstance($this); |
149 | return $this; |
150 | } |
151 | |
152 | /** |
153 | * |
154 | * @todo refactor: returns services, not topics. |
155 | */ |
156 | public function fetchTopicServicesList($topic_path) |
157 | { |
158 | trigger_error("Deprecated function fetchTopicServicesList, use fromService()->fetchTopic()"); |
159 | return $this->fromService()->fetchTopicPath($topic_path); |
160 | } |
161 | |
162 | /** |
163 | * |
164 | * @todo will not work in every edge case, cause authority export does not contain officeinformations |
165 | * @todo returns Collection\Authorities and not locations |
166 | * @return Collection\Locations |
167 | */ |
168 | public function fetchLocationListByOffice($officepath = false) |
169 | { |
170 | trigger_error("Deprecated function fetchLocationListByOffice, use fromAuthority()->fetchOffice()"); |
171 | return $this->fromAuthority()->fetchOffice($officepath); |
172 | } |
173 | } |