|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by jensk on 17-3-2017. |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace library\storage\storage; |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
use library\storage\factories\ApplicationComponentFactory; |
|
10
|
|
|
|
|
11
|
|
|
class ApplicationComponentsStorage extends AbstractStorage |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @return array |
|
15
|
|
|
*/ |
|
16
|
|
|
public function getApplicationComponents() |
|
17
|
|
|
{ |
|
18
|
|
|
return $this->repository->applicationComponents; |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @param $postValues |
|
23
|
|
|
*/ |
|
24
|
|
|
public function addApplicationComponent($postValues) |
|
25
|
|
|
{ |
|
26
|
|
|
$applicationComponent = ApplicationComponentFactory::createApplicationComponentFromPostValues($postValues); |
|
27
|
|
|
$applicationComponents = $this->repository->applicationComponents; |
|
28
|
|
|
$applicationComponents[] = $applicationComponent; |
|
29
|
|
|
$this->repository->applicationComponents = $applicationComponents; |
|
30
|
|
|
|
|
31
|
|
|
$this->save(); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @param $slug |
|
36
|
|
|
* |
|
37
|
|
|
* @return mixed|null |
|
38
|
|
|
*/ |
|
39
|
|
|
public function getApplicationComponentBySlug($slug) |
|
40
|
|
|
{ |
|
41
|
|
|
$applicationComponents = $this->getApplicationComponents(); |
|
42
|
|
|
foreach ($applicationComponents as $applicationComponent) { |
|
43
|
|
|
if ($applicationComponent->slug == $slug) { |
|
44
|
|
|
return $applicationComponent; |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
return null; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @param $slug |
|
53
|
|
|
* @param $postValues |
|
54
|
|
|
*/ |
|
55
|
|
|
public function saveApplicationComponent($slug, $postValues) |
|
56
|
|
|
{ |
|
57
|
|
|
$newApplicationComponent = ApplicationComponentFactory::createApplicationComponentFromPostValues($postValues); |
|
58
|
|
|
|
|
59
|
|
|
$applicationComponents = $this->getApplicationComponents(); |
|
60
|
|
|
foreach ($applicationComponents as $key => $applicationComponent) { |
|
61
|
|
|
if ($applicationComponent->slug == $slug) { |
|
62
|
|
|
$applicationComponents[$key] = $newApplicationComponent; |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
$this->repository->applicationComponents = $applicationComponents; |
|
66
|
|
|
$this->save(); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @param $slug |
|
71
|
|
|
*/ |
|
72
|
|
|
public function deleteApplicationComponentBySlug($slug) |
|
73
|
|
|
{ |
|
74
|
|
|
$applicationComponents = $this->getApplicationComponents(); |
|
75
|
|
|
foreach ($applicationComponents as $key => $applicationComponent) { |
|
76
|
|
|
if ($applicationComponent->slug == $slug) { |
|
77
|
|
|
unset($applicationComponents[$key]); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
$applicationComponents = array_values($applicationComponents); |
|
81
|
|
|
$this->repository->applicationComponents = $applicationComponents; |
|
82
|
|
|
$this->save(); |
|
83
|
|
|
} |
|
84
|
|
|
} |