@@ -12,29 +12,29 @@ |
||
12 | 12 | |
13 | 13 | class ApplicationComponentFactory |
14 | 14 | { |
15 | - /** |
|
16 | - * @param $postValues |
|
17 | - * |
|
18 | - * @return \stdClass |
|
19 | - * @throws \Exception |
|
20 | - */ |
|
21 | - public static function createApplicationComponentFromPostValues($postValues) |
|
22 | - { |
|
23 | - if (isset($postValues['title'], $postValues['component'])) { |
|
24 | - $applicationComponent = new \stdClass(); |
|
25 | - $applicationComponent->title = $postValues['title']; |
|
26 | - $applicationComponent->slug = StringUtil::slugify($postValues['title']); |
|
27 | - $applicationComponent->component = $postValues['component']; |
|
28 | - $applicationComponent->parameters = new \stdClass(); |
|
29 | - if (isset($postValues['parameterNames'], $postValues['parameterValues'])) { |
|
30 | - foreach ($postValues['parameterNames'] as $key => $value) { |
|
31 | - $applicationComponent->parameters->$value = $postValues['parameterValues'][$key]; |
|
32 | - } |
|
33 | - } |
|
15 | + /** |
|
16 | + * @param $postValues |
|
17 | + * |
|
18 | + * @return \stdClass |
|
19 | + * @throws \Exception |
|
20 | + */ |
|
21 | + public static function createApplicationComponentFromPostValues($postValues) |
|
22 | + { |
|
23 | + if (isset($postValues['title'], $postValues['component'])) { |
|
24 | + $applicationComponent = new \stdClass(); |
|
25 | + $applicationComponent->title = $postValues['title']; |
|
26 | + $applicationComponent->slug = StringUtil::slugify($postValues['title']); |
|
27 | + $applicationComponent->component = $postValues['component']; |
|
28 | + $applicationComponent->parameters = new \stdClass(); |
|
29 | + if (isset($postValues['parameterNames'], $postValues['parameterValues'])) { |
|
30 | + foreach ($postValues['parameterNames'] as $key => $value) { |
|
31 | + $applicationComponent->parameters->$value = $postValues['parameterValues'][$key]; |
|
32 | + } |
|
33 | + } |
|
34 | 34 | |
35 | - return $applicationComponent; |
|
36 | - } else { |
|
37 | - throw new \Exception('Trying to create application component with invalid data.'); |
|
38 | - } |
|
39 | - } |
|
35 | + return $applicationComponent; |
|
36 | + } else { |
|
37 | + throw new \Exception('Trying to create application component with invalid data.'); |
|
38 | + } |
|
39 | + } |
|
40 | 40 | } |
41 | 41 | \ No newline at end of file |
@@ -12,58 +12,58 @@ |
||
12 | 12 | |
13 | 13 | class DocumentTypeFactory extends AbstractBricksFactory |
14 | 14 | { |
15 | - public static function createDocumentTypeFromPostValues($postValues) |
|
16 | - { |
|
17 | - if (isset($postValues['title'])) { |
|
18 | - $documentTypeObject = self::createInitialDocoumentTypeObject($postValues); |
|
19 | - if (isset($postValues['fieldTitles'], $postValues['fieldTypes'], $postValues['fieldRequired'], $postValues['fieldMultiple'])) { |
|
20 | - foreach ($postValues['fieldTitles'] as $key => $value) { |
|
21 | - $fieldObject = self::createFieldObject($postValues, $value, $key); |
|
15 | + public static function createDocumentTypeFromPostValues($postValues) |
|
16 | + { |
|
17 | + if (isset($postValues['title'])) { |
|
18 | + $documentTypeObject = self::createInitialDocoumentTypeObject($postValues); |
|
19 | + if (isset($postValues['fieldTitles'], $postValues['fieldTypes'], $postValues['fieldRequired'], $postValues['fieldMultiple'])) { |
|
20 | + foreach ($postValues['fieldTitles'] as $key => $value) { |
|
21 | + $fieldObject = self::createFieldObject($postValues, $value, $key); |
|
22 | 22 | |
23 | - $documentTypeObject->fields[] = $fieldObject; |
|
24 | - } |
|
25 | - } |
|
26 | - if (isset($postValues['brickTitles'], $postValues['brickBricks'])) { |
|
27 | - foreach ($postValues['brickTitles'] as $key => $value) { |
|
28 | - $brickObject = self::createBrickObject($postValues, $value, $key); |
|
23 | + $documentTypeObject->fields[] = $fieldObject; |
|
24 | + } |
|
25 | + } |
|
26 | + if (isset($postValues['brickTitles'], $postValues['brickBricks'])) { |
|
27 | + foreach ($postValues['brickTitles'] as $key => $value) { |
|
28 | + $brickObject = self::createBrickObject($postValues, $value, $key); |
|
29 | 29 | |
30 | - $documentTypeObject->bricks[] = $brickObject; |
|
31 | - } |
|
32 | - } |
|
30 | + $documentTypeObject->bricks[] = $brickObject; |
|
31 | + } |
|
32 | + } |
|
33 | 33 | |
34 | - return $documentTypeObject; |
|
35 | - } else { |
|
36 | - throw new \Exception('Trying to create document type with invalid data.'); |
|
37 | - } |
|
38 | - } |
|
34 | + return $documentTypeObject; |
|
35 | + } else { |
|
36 | + throw new \Exception('Trying to create document type with invalid data.'); |
|
37 | + } |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * @param $postValues |
|
42 | - * @param $title |
|
43 | - * @param $slug |
|
44 | - * |
|
45 | - * @return \stdClass |
|
46 | - */ |
|
47 | - private static function createBrickObject($postValues, $title, $slug) |
|
48 | - { |
|
49 | - $brickObject = new \stdClass(); |
|
50 | - $brickObject->title = $title; |
|
51 | - $brickObject->slug = StringUtil::slugify($title); |
|
52 | - $brickObject->brickSlug = $postValues['brickBricks'][$slug]; |
|
53 | - $brickObject->multiple = ($postValues['brickMultiples'][$slug] === 'true'); |
|
40 | + /** |
|
41 | + * @param $postValues |
|
42 | + * @param $title |
|
43 | + * @param $slug |
|
44 | + * |
|
45 | + * @return \stdClass |
|
46 | + */ |
|
47 | + private static function createBrickObject($postValues, $title, $slug) |
|
48 | + { |
|
49 | + $brickObject = new \stdClass(); |
|
50 | + $brickObject->title = $title; |
|
51 | + $brickObject->slug = StringUtil::slugify($title); |
|
52 | + $brickObject->brickSlug = $postValues['brickBricks'][$slug]; |
|
53 | + $brickObject->multiple = ($postValues['brickMultiples'][$slug] === 'true'); |
|
54 | 54 | |
55 | - return $brickObject; |
|
56 | - } |
|
55 | + return $brickObject; |
|
56 | + } |
|
57 | 57 | |
58 | - private static function createInitialDocoumentTypeObject($postValues) |
|
59 | - { |
|
60 | - $documentTypeObject = new \stdClass(); |
|
61 | - $documentTypeObject->title = $postValues['title']; |
|
62 | - $documentTypeObject->slug = StringUtil::slugify($postValues['title']); |
|
63 | - $documentTypeObject->fields = array(); |
|
64 | - $documentTypeObject->bricks = array(); |
|
65 | - $documentTypeObject->dynamicBricks = isset($postValues['dynamicBricks']) ? $postValues['dynamicBricks'] : array(); |
|
58 | + private static function createInitialDocoumentTypeObject($postValues) |
|
59 | + { |
|
60 | + $documentTypeObject = new \stdClass(); |
|
61 | + $documentTypeObject->title = $postValues['title']; |
|
62 | + $documentTypeObject->slug = StringUtil::slugify($postValues['title']); |
|
63 | + $documentTypeObject->fields = array(); |
|
64 | + $documentTypeObject->bricks = array(); |
|
65 | + $documentTypeObject->dynamicBricks = isset($postValues['dynamicBricks']) ? $postValues['dynamicBricks'] : array(); |
|
66 | 66 | |
67 | - return $documentTypeObject; |
|
68 | - } |
|
67 | + return $documentTypeObject; |
|
68 | + } |
|
69 | 69 | } |
70 | 70 | \ No newline at end of file |
@@ -13,174 +13,174 @@ |
||
13 | 13 | |
14 | 14 | class DocumentFactory |
15 | 15 | { |
16 | - /** |
|
17 | - * @param array $postValues |
|
18 | - * @param DocumentTypesStorage $documentTypesStorage |
|
19 | - * |
|
20 | - * @return \CloudControl\Cms\storage\Document |
|
21 | - */ |
|
22 | - public static function createDocumentFromPostValues($postValues, DocumentTypesStorage $documentTypesStorage) |
|
23 | - { |
|
24 | - $postValues = utf8Convert($postValues); |
|
25 | - $documentType = $documentTypesStorage->getDocumentTypeBySlug($postValues['documentType']); |
|
26 | - |
|
27 | - $staticBricks = $documentType->bricks; |
|
28 | - |
|
29 | - $documentObj = self::createInitialDocumentObject($postValues, $documentType); |
|
30 | - |
|
31 | - $documentObj->fields = isset($postValues['fields']) ? $postValues['fields'] : array(); |
|
32 | - $documentObj->bricks = array(); |
|
33 | - |
|
34 | - $documentObj = self::createBrickArrayForDocument($postValues, $documentObj, $staticBricks); |
|
35 | - $documentObj = self::createDynamicBrickArrayForDocument($postValues, $documentObj); |
|
36 | - |
|
37 | - return $documentObj; |
|
38 | - } |
|
39 | - |
|
40 | - /** |
|
41 | - * @param array $postValues |
|
42 | - * @param \stdClass $documentType |
|
43 | - * |
|
44 | - * @return Document |
|
45 | - */ |
|
46 | - private static function createInitialDocumentObject($postValues, $documentType) |
|
47 | - { |
|
48 | - $documentObj = new Document(); |
|
49 | - $documentObj->title = $postValues['title']; |
|
50 | - $documentObj->slug = StringUtil::slugify($postValues['title']); |
|
51 | - $documentObj->type = 'document'; |
|
52 | - $documentObj->documentType = $documentType->title; |
|
53 | - $documentObj->documentTypeSlug = $documentType->slug; |
|
54 | - $documentObj->state = isset($postValues['state']) ? 'published' : 'unpublished'; |
|
55 | - $documentObj->lastModificationDate = time(); |
|
56 | - $documentObj->creationDate = isset($postValues['creationDate']) ? intval($postValues['creationDate']) : time(); |
|
57 | - $documentObj->lastModifiedBy = $_SESSION['cloudcontrol']->username; |
|
58 | - |
|
59 | - return $documentObj; |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * @param array $postValues |
|
64 | - * @param Document $documentObj |
|
65 | - * @param array $staticBricks |
|
66 | - * |
|
67 | - * @return Document |
|
68 | - */ |
|
69 | - private static function createBrickArrayForDocument($postValues, $documentObj, $staticBricks) |
|
70 | - { |
|
71 | - if (isset($postValues['bricks'])) { |
|
72 | - foreach ($postValues['bricks'] as $brickSlug => $brick) { |
|
73 | - // Find the current bricktype and check if its multiple |
|
74 | - list($staticBrick, $multiple) = self::getStaticBrickAndSetMultiple($staticBricks, $brickSlug); |
|
75 | - |
|
76 | - if ($multiple) { |
|
77 | - $documentObj = self::addMultipleBricks($documentObj, $brick, $staticBrick, $brickSlug); |
|
78 | - } else { |
|
79 | - $documentObj = self::addSingleBrick($documentObj, $brick, $brickSlug); |
|
80 | - } |
|
81 | - } |
|
82 | - } |
|
83 | - return $documentObj; |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * @param array $postValues |
|
88 | - * @param Document $documentObj |
|
89 | - * |
|
90 | - * @return Document |
|
91 | - */ |
|
92 | - private static function createDynamicBrickArrayForDocument($postValues, $documentObj) |
|
93 | - { |
|
94 | - $documentObj->dynamicBricks = array(); |
|
95 | - if (isset($postValues['dynamicBricks'])) { |
|
96 | - foreach ($postValues['dynamicBricks'] as $brickTypeSlug => $brick) { |
|
97 | - foreach ($brick as $brickContent) { |
|
98 | - $brickObj = new \stdClass(); |
|
99 | - $brickObj->type = $brickTypeSlug; |
|
100 | - $brickObj->fields = $brickContent; |
|
101 | - $dynamicBricks = $documentObj->dynamicBricks; |
|
102 | - $dynamicBricks[] = $brickObj; |
|
103 | - $documentObj->dynamicBricks = $dynamicBricks; |
|
104 | - } |
|
105 | - } |
|
106 | - } |
|
107 | - return $documentObj; |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * @param $staticBricks |
|
112 | - * @param $brickSlug |
|
113 | - * |
|
114 | - * @return array |
|
115 | - */ |
|
116 | - private static function getStaticBrickAndSetMultiple($staticBricks, $brickSlug) |
|
117 | - { |
|
118 | - $staticBrick = null; |
|
119 | - $multiple = false; |
|
120 | - foreach ($staticBricks as $staticBrick) { |
|
121 | - if ($staticBrick->slug === $brickSlug) { |
|
122 | - $multiple = $staticBrick->multiple; |
|
123 | - break; |
|
124 | - } |
|
125 | - } |
|
126 | - |
|
127 | - return array($staticBrick, $multiple); |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * @param $staticBrick |
|
132 | - * @param $brickInstance |
|
133 | - * |
|
134 | - * @return \stdClass |
|
135 | - */ |
|
136 | - private static function createBrick($staticBrick, $brickInstance) |
|
137 | - { |
|
138 | - $brickObj = new \stdClass(); |
|
139 | - $brickObj->fields = new \stdClass(); |
|
140 | - $brickObj->type = $staticBrick->brickSlug; |
|
141 | - |
|
142 | - foreach ($brickInstance['fields'] as $fieldName => $fieldValues) { |
|
143 | - $brickObj->fields->$fieldName = $fieldValues; |
|
144 | - } |
|
145 | - |
|
146 | - return $brickObj; |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * @param $documentObj |
|
151 | - * @param $brick |
|
152 | - * @param $staticBrick |
|
153 | - * @param $brickSlug |
|
154 | - * |
|
155 | - * @return mixed |
|
156 | - */ |
|
157 | - private static function addMultipleBricks($documentObj, $brick, $staticBrick, $brickSlug) |
|
158 | - { |
|
159 | - $brickArray = array(); |
|
160 | - foreach ($brick as $brickInstance) { |
|
161 | - $brickObj = self::createBrick($staticBrick, $brickInstance); |
|
162 | - $brickArray[] = $brickObj; |
|
163 | - } |
|
164 | - |
|
165 | - $bricks = $documentObj->bricks; |
|
166 | - $bricks[$brickSlug] = $brickArray; |
|
167 | - $documentObj->bricks = $bricks; |
|
168 | - |
|
169 | - return $documentObj; |
|
170 | - } |
|
171 | - |
|
172 | - /** |
|
173 | - * @param $documentObj |
|
174 | - * @param $brick |
|
175 | - * @param $brickSlug |
|
176 | - * |
|
177 | - * @return mixed |
|
178 | - */ |
|
179 | - private static function addSingleBrick($documentObj, $brick, $brickSlug) |
|
180 | - { |
|
181 | - $bricks = $documentObj->bricks; |
|
182 | - $bricks[$brickSlug] = $brick; |
|
183 | - $documentObj->bricks = $bricks; |
|
184 | - return $documentObj; |
|
185 | - } |
|
16 | + /** |
|
17 | + * @param array $postValues |
|
18 | + * @param DocumentTypesStorage $documentTypesStorage |
|
19 | + * |
|
20 | + * @return \CloudControl\Cms\storage\Document |
|
21 | + */ |
|
22 | + public static function createDocumentFromPostValues($postValues, DocumentTypesStorage $documentTypesStorage) |
|
23 | + { |
|
24 | + $postValues = utf8Convert($postValues); |
|
25 | + $documentType = $documentTypesStorage->getDocumentTypeBySlug($postValues['documentType']); |
|
26 | + |
|
27 | + $staticBricks = $documentType->bricks; |
|
28 | + |
|
29 | + $documentObj = self::createInitialDocumentObject($postValues, $documentType); |
|
30 | + |
|
31 | + $documentObj->fields = isset($postValues['fields']) ? $postValues['fields'] : array(); |
|
32 | + $documentObj->bricks = array(); |
|
33 | + |
|
34 | + $documentObj = self::createBrickArrayForDocument($postValues, $documentObj, $staticBricks); |
|
35 | + $documentObj = self::createDynamicBrickArrayForDocument($postValues, $documentObj); |
|
36 | + |
|
37 | + return $documentObj; |
|
38 | + } |
|
39 | + |
|
40 | + /** |
|
41 | + * @param array $postValues |
|
42 | + * @param \stdClass $documentType |
|
43 | + * |
|
44 | + * @return Document |
|
45 | + */ |
|
46 | + private static function createInitialDocumentObject($postValues, $documentType) |
|
47 | + { |
|
48 | + $documentObj = new Document(); |
|
49 | + $documentObj->title = $postValues['title']; |
|
50 | + $documentObj->slug = StringUtil::slugify($postValues['title']); |
|
51 | + $documentObj->type = 'document'; |
|
52 | + $documentObj->documentType = $documentType->title; |
|
53 | + $documentObj->documentTypeSlug = $documentType->slug; |
|
54 | + $documentObj->state = isset($postValues['state']) ? 'published' : 'unpublished'; |
|
55 | + $documentObj->lastModificationDate = time(); |
|
56 | + $documentObj->creationDate = isset($postValues['creationDate']) ? intval($postValues['creationDate']) : time(); |
|
57 | + $documentObj->lastModifiedBy = $_SESSION['cloudcontrol']->username; |
|
58 | + |
|
59 | + return $documentObj; |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * @param array $postValues |
|
64 | + * @param Document $documentObj |
|
65 | + * @param array $staticBricks |
|
66 | + * |
|
67 | + * @return Document |
|
68 | + */ |
|
69 | + private static function createBrickArrayForDocument($postValues, $documentObj, $staticBricks) |
|
70 | + { |
|
71 | + if (isset($postValues['bricks'])) { |
|
72 | + foreach ($postValues['bricks'] as $brickSlug => $brick) { |
|
73 | + // Find the current bricktype and check if its multiple |
|
74 | + list($staticBrick, $multiple) = self::getStaticBrickAndSetMultiple($staticBricks, $brickSlug); |
|
75 | + |
|
76 | + if ($multiple) { |
|
77 | + $documentObj = self::addMultipleBricks($documentObj, $brick, $staticBrick, $brickSlug); |
|
78 | + } else { |
|
79 | + $documentObj = self::addSingleBrick($documentObj, $brick, $brickSlug); |
|
80 | + } |
|
81 | + } |
|
82 | + } |
|
83 | + return $documentObj; |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * @param array $postValues |
|
88 | + * @param Document $documentObj |
|
89 | + * |
|
90 | + * @return Document |
|
91 | + */ |
|
92 | + private static function createDynamicBrickArrayForDocument($postValues, $documentObj) |
|
93 | + { |
|
94 | + $documentObj->dynamicBricks = array(); |
|
95 | + if (isset($postValues['dynamicBricks'])) { |
|
96 | + foreach ($postValues['dynamicBricks'] as $brickTypeSlug => $brick) { |
|
97 | + foreach ($brick as $brickContent) { |
|
98 | + $brickObj = new \stdClass(); |
|
99 | + $brickObj->type = $brickTypeSlug; |
|
100 | + $brickObj->fields = $brickContent; |
|
101 | + $dynamicBricks = $documentObj->dynamicBricks; |
|
102 | + $dynamicBricks[] = $brickObj; |
|
103 | + $documentObj->dynamicBricks = $dynamicBricks; |
|
104 | + } |
|
105 | + } |
|
106 | + } |
|
107 | + return $documentObj; |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * @param $staticBricks |
|
112 | + * @param $brickSlug |
|
113 | + * |
|
114 | + * @return array |
|
115 | + */ |
|
116 | + private static function getStaticBrickAndSetMultiple($staticBricks, $brickSlug) |
|
117 | + { |
|
118 | + $staticBrick = null; |
|
119 | + $multiple = false; |
|
120 | + foreach ($staticBricks as $staticBrick) { |
|
121 | + if ($staticBrick->slug === $brickSlug) { |
|
122 | + $multiple = $staticBrick->multiple; |
|
123 | + break; |
|
124 | + } |
|
125 | + } |
|
126 | + |
|
127 | + return array($staticBrick, $multiple); |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * @param $staticBrick |
|
132 | + * @param $brickInstance |
|
133 | + * |
|
134 | + * @return \stdClass |
|
135 | + */ |
|
136 | + private static function createBrick($staticBrick, $brickInstance) |
|
137 | + { |
|
138 | + $brickObj = new \stdClass(); |
|
139 | + $brickObj->fields = new \stdClass(); |
|
140 | + $brickObj->type = $staticBrick->brickSlug; |
|
141 | + |
|
142 | + foreach ($brickInstance['fields'] as $fieldName => $fieldValues) { |
|
143 | + $brickObj->fields->$fieldName = $fieldValues; |
|
144 | + } |
|
145 | + |
|
146 | + return $brickObj; |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * @param $documentObj |
|
151 | + * @param $brick |
|
152 | + * @param $staticBrick |
|
153 | + * @param $brickSlug |
|
154 | + * |
|
155 | + * @return mixed |
|
156 | + */ |
|
157 | + private static function addMultipleBricks($documentObj, $brick, $staticBrick, $brickSlug) |
|
158 | + { |
|
159 | + $brickArray = array(); |
|
160 | + foreach ($brick as $brickInstance) { |
|
161 | + $brickObj = self::createBrick($staticBrick, $brickInstance); |
|
162 | + $brickArray[] = $brickObj; |
|
163 | + } |
|
164 | + |
|
165 | + $bricks = $documentObj->bricks; |
|
166 | + $bricks[$brickSlug] = $brickArray; |
|
167 | + $documentObj->bricks = $bricks; |
|
168 | + |
|
169 | + return $documentObj; |
|
170 | + } |
|
171 | + |
|
172 | + /** |
|
173 | + * @param $documentObj |
|
174 | + * @param $brick |
|
175 | + * @param $brickSlug |
|
176 | + * |
|
177 | + * @return mixed |
|
178 | + */ |
|
179 | + private static function addSingleBrick($documentObj, $brick, $brickSlug) |
|
180 | + { |
|
181 | + $bricks = $documentObj->bricks; |
|
182 | + $bricks[$brickSlug] = $brick; |
|
183 | + $documentObj->bricks = $bricks; |
|
184 | + return $documentObj; |
|
185 | + } |
|
186 | 186 | } |
187 | 187 | \ No newline at end of file |
@@ -12,34 +12,34 @@ |
||
12 | 12 | |
13 | 13 | class SitemapItemFactory |
14 | 14 | { |
15 | - /** |
|
16 | - * Create a sitemap item from post values |
|
17 | - * |
|
18 | - * @param $postValues |
|
19 | - * |
|
20 | - * @return \stdClass |
|
21 | - * @throws \Exception |
|
22 | - */ |
|
23 | - public static function createSitemapItemFromPostValues($postValues) |
|
24 | - { |
|
25 | - if (isset($postValues['title'], $postValues['url'], $postValues['component'], $postValues['template'])) { |
|
26 | - $sitemapObject = new \stdClass(); |
|
27 | - $sitemapObject->title = $postValues['title']; |
|
28 | - $sitemapObject->slug = StringUtil::slugify($postValues['title']); |
|
29 | - $sitemapObject->url = $postValues['url']; |
|
30 | - $sitemapObject->component = $postValues['component']; |
|
31 | - $sitemapObject->template = $postValues['template']; |
|
32 | - $sitemapObject->regex = isset($postValues['regex']); |
|
33 | - $sitemapObject->parameters = new \stdClass(); |
|
34 | - if (isset($postValues['parameterNames'], $postValues['parameterValues'])) { |
|
35 | - foreach ($postValues['parameterNames'] as $key => $value) { |
|
36 | - $sitemapObject->parameters->$value = $postValues['parameterValues'][$key]; |
|
37 | - } |
|
38 | - } |
|
15 | + /** |
|
16 | + * Create a sitemap item from post values |
|
17 | + * |
|
18 | + * @param $postValues |
|
19 | + * |
|
20 | + * @return \stdClass |
|
21 | + * @throws \Exception |
|
22 | + */ |
|
23 | + public static function createSitemapItemFromPostValues($postValues) |
|
24 | + { |
|
25 | + if (isset($postValues['title'], $postValues['url'], $postValues['component'], $postValues['template'])) { |
|
26 | + $sitemapObject = new \stdClass(); |
|
27 | + $sitemapObject->title = $postValues['title']; |
|
28 | + $sitemapObject->slug = StringUtil::slugify($postValues['title']); |
|
29 | + $sitemapObject->url = $postValues['url']; |
|
30 | + $sitemapObject->component = $postValues['component']; |
|
31 | + $sitemapObject->template = $postValues['template']; |
|
32 | + $sitemapObject->regex = isset($postValues['regex']); |
|
33 | + $sitemapObject->parameters = new \stdClass(); |
|
34 | + if (isset($postValues['parameterNames'], $postValues['parameterValues'])) { |
|
35 | + foreach ($postValues['parameterNames'] as $key => $value) { |
|
36 | + $sitemapObject->parameters->$value = $postValues['parameterValues'][$key]; |
|
37 | + } |
|
38 | + } |
|
39 | 39 | |
40 | - return $sitemapObject; |
|
41 | - } else { |
|
42 | - throw new \Exception('Trying to create sitemap item with invalid data.'); |
|
43 | - } |
|
44 | - } |
|
40 | + return $sitemapObject; |
|
41 | + } else { |
|
42 | + throw new \Exception('Trying to create sitemap item with invalid data.'); |
|
43 | + } |
|
44 | + } |
|
45 | 45 | } |
46 | 46 | \ No newline at end of file |
@@ -12,32 +12,32 @@ |
||
12 | 12 | |
13 | 13 | class BrickFactory extends AbstractBricksFactory |
14 | 14 | { |
15 | - /** |
|
16 | - * Create a brick from post values |
|
17 | - * |
|
18 | - * @param $postValues |
|
19 | - * |
|
20 | - * @return \stdClass |
|
21 | - * @throws \Exception |
|
22 | - */ |
|
23 | - public static function createBrickFromPostValues($postValues) |
|
24 | - { |
|
25 | - if (isset($postValues['title'])) { |
|
26 | - $brickObject = new \stdClass(); |
|
27 | - $brickObject->title = $postValues['title']; |
|
28 | - $brickObject->slug = StringUtil::slugify($postValues['title']); |
|
29 | - $brickObject->fields = array(); |
|
30 | - if (isset($postValues['fieldTitles'], $postValues['fieldTypes'], $postValues['fieldRequired'], $postValues['fieldMultiple'])) { |
|
31 | - foreach ($postValues['fieldTitles'] as $key => $value) { |
|
32 | - $fieldObject = self::createFieldObject($postValues, $value, $key); |
|
15 | + /** |
|
16 | + * Create a brick from post values |
|
17 | + * |
|
18 | + * @param $postValues |
|
19 | + * |
|
20 | + * @return \stdClass |
|
21 | + * @throws \Exception |
|
22 | + */ |
|
23 | + public static function createBrickFromPostValues($postValues) |
|
24 | + { |
|
25 | + if (isset($postValues['title'])) { |
|
26 | + $brickObject = new \stdClass(); |
|
27 | + $brickObject->title = $postValues['title']; |
|
28 | + $brickObject->slug = StringUtil::slugify($postValues['title']); |
|
29 | + $brickObject->fields = array(); |
|
30 | + if (isset($postValues['fieldTitles'], $postValues['fieldTypes'], $postValues['fieldRequired'], $postValues['fieldMultiple'])) { |
|
31 | + foreach ($postValues['fieldTitles'] as $key => $value) { |
|
32 | + $fieldObject = self::createFieldObject($postValues, $value, $key); |
|
33 | 33 | |
34 | - $brickObject->fields[] = $fieldObject; |
|
35 | - } |
|
36 | - } |
|
34 | + $brickObject->fields[] = $fieldObject; |
|
35 | + } |
|
36 | + } |
|
37 | 37 | |
38 | - return $brickObject; |
|
39 | - } else { |
|
40 | - throw new \Exception('Trying to create document type with invalid data.'); |
|
41 | - } |
|
42 | - } |
|
38 | + return $brickObject; |
|
39 | + } else { |
|
40 | + throw new \Exception('Trying to create document type with invalid data.'); |
|
41 | + } |
|
42 | + } |
|
43 | 43 | } |
44 | 44 | \ No newline at end of file |
@@ -12,22 +12,22 @@ |
||
12 | 12 | |
13 | 13 | abstract class AbstractBricksFactory |
14 | 14 | { |
15 | - /** |
|
16 | - * @param $postValues |
|
17 | - * @param $title |
|
18 | - * @param $fieldType |
|
19 | - * |
|
20 | - * @return \stdClass |
|
21 | - */ |
|
22 | - protected static function createFieldObject($postValues, $title, $fieldType) |
|
23 | - { |
|
24 | - $fieldObject = new \stdClass(); |
|
25 | - $fieldObject->title = $title; |
|
26 | - $fieldObject->slug = StringUtil::slugify($title); |
|
27 | - $fieldObject->type = $postValues['fieldTypes'][$fieldType]; |
|
28 | - $fieldObject->required = ($postValues['fieldRequired'][$fieldType] === 'true'); |
|
29 | - $fieldObject->multiple = ($postValues['fieldMultiple'][$fieldType] === 'true'); |
|
15 | + /** |
|
16 | + * @param $postValues |
|
17 | + * @param $title |
|
18 | + * @param $fieldType |
|
19 | + * |
|
20 | + * @return \stdClass |
|
21 | + */ |
|
22 | + protected static function createFieldObject($postValues, $title, $fieldType) |
|
23 | + { |
|
24 | + $fieldObject = new \stdClass(); |
|
25 | + $fieldObject->title = $title; |
|
26 | + $fieldObject->slug = StringUtil::slugify($title); |
|
27 | + $fieldObject->type = $postValues['fieldTypes'][$fieldType]; |
|
28 | + $fieldObject->required = ($postValues['fieldRequired'][$fieldType] === 'true'); |
|
29 | + $fieldObject->multiple = ($postValues['fieldMultiple'][$fieldType] === 'true'); |
|
30 | 30 | |
31 | - return $fieldObject; |
|
32 | - } |
|
31 | + return $fieldObject; |
|
32 | + } |
|
33 | 33 | } |
34 | 34 | \ No newline at end of file |
@@ -13,26 +13,26 @@ |
||
13 | 13 | |
14 | 14 | class DocumentFolderFactory |
15 | 15 | { |
16 | - /** |
|
17 | - * Create folder from post values |
|
18 | - * |
|
19 | - * @param $postValues |
|
20 | - * |
|
21 | - * @return Document |
|
22 | - * @throws \Exception |
|
23 | - */ |
|
24 | - public static function createDocumentFolderFromPostValues($postValues) |
|
25 | - { |
|
26 | - if (isset($postValues['title'], $postValues['path'], $postValues['content'])) { |
|
27 | - $documentFolderObject = new Document(); |
|
28 | - $documentFolderObject->title = $postValues['title']; |
|
29 | - $documentFolderObject->slug = StringUtil::slugify($postValues['title']); |
|
30 | - $documentFolderObject->type = 'folder'; |
|
31 | - $documentFolderObject->content = json_decode($postValues['content']); |
|
16 | + /** |
|
17 | + * Create folder from post values |
|
18 | + * |
|
19 | + * @param $postValues |
|
20 | + * |
|
21 | + * @return Document |
|
22 | + * @throws \Exception |
|
23 | + */ |
|
24 | + public static function createDocumentFolderFromPostValues($postValues) |
|
25 | + { |
|
26 | + if (isset($postValues['title'], $postValues['path'], $postValues['content'])) { |
|
27 | + $documentFolderObject = new Document(); |
|
28 | + $documentFolderObject->title = $postValues['title']; |
|
29 | + $documentFolderObject->slug = StringUtil::slugify($postValues['title']); |
|
30 | + $documentFolderObject->type = 'folder'; |
|
31 | + $documentFolderObject->content = json_decode($postValues['content']); |
|
32 | 32 | |
33 | - return $documentFolderObject; |
|
34 | - } else { |
|
35 | - throw new \Exception('Trying to create document folder with invalid data.'); |
|
36 | - } |
|
37 | - } |
|
33 | + return $documentFolderObject; |
|
34 | + } else { |
|
35 | + throw new \Exception('Trying to create document folder with invalid data.'); |
|
36 | + } |
|
37 | + } |
|
38 | 38 | } |
39 | 39 | \ No newline at end of file |
@@ -10,115 +10,115 @@ |
||
10 | 10 | |
11 | 11 | class DocumentTypesStorage extends AbstractStorage |
12 | 12 | { |
13 | - /** |
|
14 | - * @var BricksStorage |
|
15 | - */ |
|
16 | - protected $bricks; |
|
13 | + /** |
|
14 | + * @var BricksStorage |
|
15 | + */ |
|
16 | + protected $bricks; |
|
17 | 17 | |
18 | - /** |
|
19 | - * @return array |
|
20 | - */ |
|
21 | - public function getDocumentTypes() |
|
22 | - { |
|
23 | - return $this->repository->documentTypes; |
|
24 | - } |
|
18 | + /** |
|
19 | + * @return array |
|
20 | + */ |
|
21 | + public function getDocumentTypes() |
|
22 | + { |
|
23 | + return $this->repository->documentTypes; |
|
24 | + } |
|
25 | 25 | |
26 | - /** |
|
27 | - * Add a document type from post values |
|
28 | - * |
|
29 | - * @param $postValues |
|
30 | - * |
|
31 | - * @throws \Exception |
|
32 | - */ |
|
33 | - public function addDocumentType($postValues) |
|
34 | - { |
|
35 | - $documentTypeObject = DocumentTypeFactory::createDocumentTypeFromPostValues($postValues); |
|
26 | + /** |
|
27 | + * Add a document type from post values |
|
28 | + * |
|
29 | + * @param $postValues |
|
30 | + * |
|
31 | + * @throws \Exception |
|
32 | + */ |
|
33 | + public function addDocumentType($postValues) |
|
34 | + { |
|
35 | + $documentTypeObject = DocumentTypeFactory::createDocumentTypeFromPostValues($postValues); |
|
36 | 36 | |
37 | - $documentTypes = $this->repository->documentTypes; |
|
38 | - $documentTypes[] = $documentTypeObject; |
|
39 | - $this->repository->documentTypes = $documentTypes; |
|
37 | + $documentTypes = $this->repository->documentTypes; |
|
38 | + $documentTypes[] = $documentTypeObject; |
|
39 | + $this->repository->documentTypes = $documentTypes; |
|
40 | 40 | |
41 | - $this->save(); |
|
42 | - } |
|
41 | + $this->save(); |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * Delete document type |
|
46 | - * |
|
47 | - * @param $slug |
|
48 | - * |
|
49 | - * @throws \Exception |
|
50 | - */ |
|
51 | - public function deleteDocumentTypeBySlug($slug) |
|
52 | - { |
|
53 | - $documentTypes = $this->repository->documentTypes; |
|
54 | - foreach ($documentTypes as $key => $documentTypeObject) { |
|
55 | - if ($documentTypeObject->slug == $slug) { |
|
56 | - unset($documentTypes[$key]); |
|
57 | - } |
|
58 | - } |
|
59 | - $documentTypes = array_values($documentTypes); |
|
60 | - $this->repository->documentTypes = $documentTypes; |
|
61 | - $this->save(); |
|
62 | - } |
|
44 | + /** |
|
45 | + * Delete document type |
|
46 | + * |
|
47 | + * @param $slug |
|
48 | + * |
|
49 | + * @throws \Exception |
|
50 | + */ |
|
51 | + public function deleteDocumentTypeBySlug($slug) |
|
52 | + { |
|
53 | + $documentTypes = $this->repository->documentTypes; |
|
54 | + foreach ($documentTypes as $key => $documentTypeObject) { |
|
55 | + if ($documentTypeObject->slug == $slug) { |
|
56 | + unset($documentTypes[$key]); |
|
57 | + } |
|
58 | + } |
|
59 | + $documentTypes = array_values($documentTypes); |
|
60 | + $this->repository->documentTypes = $documentTypes; |
|
61 | + $this->save(); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * Get document type by its slug |
|
66 | - * |
|
67 | - * @param $slug |
|
68 | - * @param bool $getBricks |
|
69 | - * |
|
70 | - * @return mixed |
|
71 | - */ |
|
72 | - public function getDocumentTypeBySlug($slug, $getBricks = false) |
|
73 | - { |
|
74 | - $documentTypes = $this->repository->documentTypes; |
|
75 | - foreach ($documentTypes as $documentType) { |
|
76 | - if ($documentType->slug == $slug) { |
|
77 | - if ($getBricks === true) { |
|
78 | - foreach ($documentType->bricks as $key => $brick) { |
|
79 | - $brickStructure = $this->getBricks()->getBrickBySlug($brick->brickSlug); |
|
80 | - $documentType->bricks[$key]->structure = $brickStructure; |
|
81 | - } |
|
82 | - foreach ($documentType->dynamicBricks as $key => $brickSlug) { |
|
83 | - $brickStructure = $this->getBricks()->getBrickBySlug($brickSlug); |
|
84 | - $documentType->dynamicBricks[$key] = $brickStructure; |
|
85 | - } |
|
86 | - } |
|
64 | + /** |
|
65 | + * Get document type by its slug |
|
66 | + * |
|
67 | + * @param $slug |
|
68 | + * @param bool $getBricks |
|
69 | + * |
|
70 | + * @return mixed |
|
71 | + */ |
|
72 | + public function getDocumentTypeBySlug($slug, $getBricks = false) |
|
73 | + { |
|
74 | + $documentTypes = $this->repository->documentTypes; |
|
75 | + foreach ($documentTypes as $documentType) { |
|
76 | + if ($documentType->slug == $slug) { |
|
77 | + if ($getBricks === true) { |
|
78 | + foreach ($documentType->bricks as $key => $brick) { |
|
79 | + $brickStructure = $this->getBricks()->getBrickBySlug($brick->brickSlug); |
|
80 | + $documentType->bricks[$key]->structure = $brickStructure; |
|
81 | + } |
|
82 | + foreach ($documentType->dynamicBricks as $key => $brickSlug) { |
|
83 | + $brickStructure = $this->getBricks()->getBrickBySlug($brickSlug); |
|
84 | + $documentType->dynamicBricks[$key] = $brickStructure; |
|
85 | + } |
|
86 | + } |
|
87 | 87 | |
88 | - return $documentType; |
|
89 | - } |
|
90 | - } |
|
88 | + return $documentType; |
|
89 | + } |
|
90 | + } |
|
91 | 91 | |
92 | - return null; |
|
93 | - } |
|
92 | + return null; |
|
93 | + } |
|
94 | 94 | |
95 | - /** |
|
96 | - * Save changes to a document type |
|
97 | - * |
|
98 | - * @param $slug |
|
99 | - * @param $postValues |
|
100 | - * |
|
101 | - * @throws \Exception |
|
102 | - */ |
|
103 | - public function saveDocumentType($slug, $postValues) |
|
104 | - { |
|
105 | - $documentTypeObject = DocumentTypeFactory::createDocumentTypeFromPostValues($postValues); |
|
95 | + /** |
|
96 | + * Save changes to a document type |
|
97 | + * |
|
98 | + * @param $slug |
|
99 | + * @param $postValues |
|
100 | + * |
|
101 | + * @throws \Exception |
|
102 | + */ |
|
103 | + public function saveDocumentType($slug, $postValues) |
|
104 | + { |
|
105 | + $documentTypeObject = DocumentTypeFactory::createDocumentTypeFromPostValues($postValues); |
|
106 | 106 | |
107 | - $documentTypes = $this->repository->documentTypes; |
|
108 | - foreach ($documentTypes as $key => $documentType) { |
|
109 | - if ($documentType->slug == $slug) { |
|
110 | - $documentTypes[$key] = $documentTypeObject; |
|
111 | - } |
|
112 | - } |
|
113 | - $this->repository->documentTypes = $documentTypes; |
|
114 | - $this->save(); |
|
115 | - } |
|
107 | + $documentTypes = $this->repository->documentTypes; |
|
108 | + foreach ($documentTypes as $key => $documentType) { |
|
109 | + if ($documentType->slug == $slug) { |
|
110 | + $documentTypes[$key] = $documentTypeObject; |
|
111 | + } |
|
112 | + } |
|
113 | + $this->repository->documentTypes = $documentTypes; |
|
114 | + $this->save(); |
|
115 | + } |
|
116 | 116 | |
117 | - private function getBricks() |
|
118 | - { |
|
119 | - if (!$this->bricks instanceof BricksStorage) { |
|
120 | - $this->bricks = new BricksStorage($this->repository); |
|
121 | - } |
|
122 | - return $this->bricks; |
|
123 | - } |
|
117 | + private function getBricks() |
|
118 | + { |
|
119 | + if (!$this->bricks instanceof BricksStorage) { |
|
120 | + $this->bricks = new BricksStorage($this->repository); |
|
121 | + } |
|
122 | + return $this->bricks; |
|
123 | + } |
|
124 | 124 | } |
125 | 125 | \ No newline at end of file |
@@ -10,91 +10,91 @@ |
||
10 | 10 | |
11 | 11 | class BricksStorage extends AbstractStorage |
12 | 12 | { |
13 | - /** |
|
14 | - * @return array |
|
15 | - */ |
|
16 | - public function getBricks() |
|
17 | - { |
|
18 | - return $this->repository->bricks; |
|
19 | - } |
|
13 | + /** |
|
14 | + * @return array |
|
15 | + */ |
|
16 | + public function getBricks() |
|
17 | + { |
|
18 | + return $this->repository->bricks; |
|
19 | + } |
|
20 | 20 | |
21 | - /** |
|
22 | - * Add a brick |
|
23 | - * |
|
24 | - * @param $postValues |
|
25 | - * |
|
26 | - * @throws \Exception |
|
27 | - */ |
|
28 | - public function addBrick($postValues) |
|
29 | - { |
|
30 | - $brickObject = BrickFactory::createBrickFromPostValues($postValues); |
|
21 | + /** |
|
22 | + * Add a brick |
|
23 | + * |
|
24 | + * @param $postValues |
|
25 | + * |
|
26 | + * @throws \Exception |
|
27 | + */ |
|
28 | + public function addBrick($postValues) |
|
29 | + { |
|
30 | + $brickObject = BrickFactory::createBrickFromPostValues($postValues); |
|
31 | 31 | |
32 | - $bricks = $this->repository->bricks; |
|
33 | - $bricks[] = $brickObject; |
|
34 | - $this->repository->bricks = $bricks; |
|
32 | + $bricks = $this->repository->bricks; |
|
33 | + $bricks[] = $brickObject; |
|
34 | + $this->repository->bricks = $bricks; |
|
35 | 35 | |
36 | - $this->save(); |
|
37 | - } |
|
36 | + $this->save(); |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * Get a brick by its slug |
|
41 | - * |
|
42 | - * @param $slug |
|
43 | - * |
|
44 | - * @return \stdClass |
|
45 | - */ |
|
46 | - public function getBrickBySlug($slug) |
|
47 | - { |
|
48 | - $bricks = $this->repository->bricks; |
|
49 | - foreach ($bricks as $brick) { |
|
50 | - if ($brick->slug == $slug) { |
|
51 | - return $brick; |
|
52 | - } |
|
53 | - } |
|
39 | + /** |
|
40 | + * Get a brick by its slug |
|
41 | + * |
|
42 | + * @param $slug |
|
43 | + * |
|
44 | + * @return \stdClass |
|
45 | + */ |
|
46 | + public function getBrickBySlug($slug) |
|
47 | + { |
|
48 | + $bricks = $this->repository->bricks; |
|
49 | + foreach ($bricks as $brick) { |
|
50 | + if ($brick->slug == $slug) { |
|
51 | + return $brick; |
|
52 | + } |
|
53 | + } |
|
54 | 54 | |
55 | - return null; |
|
56 | - } |
|
55 | + return null; |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * Save changes to a brick |
|
60 | - * |
|
61 | - * @param $slug |
|
62 | - * @param $postValues |
|
63 | - * |
|
64 | - * @throws \Exception |
|
65 | - */ |
|
66 | - public function saveBrick($slug, $postValues) |
|
67 | - { |
|
68 | - $brickObject = BrickFactory::createBrickFromPostValues($postValues); |
|
58 | + /** |
|
59 | + * Save changes to a brick |
|
60 | + * |
|
61 | + * @param $slug |
|
62 | + * @param $postValues |
|
63 | + * |
|
64 | + * @throws \Exception |
|
65 | + */ |
|
66 | + public function saveBrick($slug, $postValues) |
|
67 | + { |
|
68 | + $brickObject = BrickFactory::createBrickFromPostValues($postValues); |
|
69 | 69 | |
70 | - $bricks = $this->repository->bricks; |
|
71 | - foreach ($bricks as $key => $brick) { |
|
72 | - if ($brick->slug == $slug) { |
|
73 | - $bricks[$key] = $brickObject; |
|
74 | - } |
|
75 | - } |
|
76 | - $this->repository->bricks = $bricks; |
|
77 | - $this->save(); |
|
78 | - } |
|
70 | + $bricks = $this->repository->bricks; |
|
71 | + foreach ($bricks as $key => $brick) { |
|
72 | + if ($brick->slug == $slug) { |
|
73 | + $bricks[$key] = $brickObject; |
|
74 | + } |
|
75 | + } |
|
76 | + $this->repository->bricks = $bricks; |
|
77 | + $this->save(); |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * Delete a brick by its slug |
|
82 | - * |
|
83 | - * @param $slug |
|
84 | - * |
|
85 | - * @throws \Exception |
|
86 | - */ |
|
87 | - public function deleteBrickBySlug($slug) |
|
88 | - { |
|
89 | - $bricks = $this->repository->bricks; |
|
90 | - foreach ($bricks as $key => $brickObject) { |
|
91 | - if ($brickObject->slug == $slug) { |
|
92 | - unset($bricks[$key]); |
|
93 | - } |
|
94 | - } |
|
80 | + /** |
|
81 | + * Delete a brick by its slug |
|
82 | + * |
|
83 | + * @param $slug |
|
84 | + * |
|
85 | + * @throws \Exception |
|
86 | + */ |
|
87 | + public function deleteBrickBySlug($slug) |
|
88 | + { |
|
89 | + $bricks = $this->repository->bricks; |
|
90 | + foreach ($bricks as $key => $brickObject) { |
|
91 | + if ($brickObject->slug == $slug) { |
|
92 | + unset($bricks[$key]); |
|
93 | + } |
|
94 | + } |
|
95 | 95 | |
96 | - $bricks = array_values($bricks); |
|
97 | - $this->repository->bricks = $bricks; |
|
98 | - $this->save(); |
|
99 | - } |
|
96 | + $bricks = array_values($bricks); |
|
97 | + $this->repository->bricks = $bricks; |
|
98 | + $this->save(); |
|
99 | + } |
|
100 | 100 | } |
101 | 101 | \ No newline at end of file |