@@ -12,28 +12,28 @@ |
||
| 12 | 12 | |
| 13 | 13 | class ImageSetFactory |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * Ceate image set from post values |
|
| 17 | - * |
|
| 18 | - * @param $postValues |
|
| 19 | - * |
|
| 20 | - * @return \stdClass |
|
| 21 | - * @throws \Exception |
|
| 22 | - */ |
|
| 23 | - public static function createImageSetFromPostValues($postValues) |
|
| 24 | - { |
|
| 25 | - if (isset($postValues['title'], $postValues['width'], $postValues['height'], $postValues['method'])) { |
|
| 26 | - $imageSetObject = new \stdClass(); |
|
| 15 | + /** |
|
| 16 | + * Ceate image set from post values |
|
| 17 | + * |
|
| 18 | + * @param $postValues |
|
| 19 | + * |
|
| 20 | + * @return \stdClass |
|
| 21 | + * @throws \Exception |
|
| 22 | + */ |
|
| 23 | + public static function createImageSetFromPostValues($postValues) |
|
| 24 | + { |
|
| 25 | + if (isset($postValues['title'], $postValues['width'], $postValues['height'], $postValues['method'])) { |
|
| 26 | + $imageSetObject = new \stdClass(); |
|
| 27 | 27 | |
| 28 | - $imageSetObject->title = $postValues['title']; |
|
| 29 | - $imageSetObject->slug = StringUtil::slugify($postValues['title']); |
|
| 30 | - $imageSetObject->width = $postValues['width']; |
|
| 31 | - $imageSetObject->height = $postValues['height']; |
|
| 32 | - $imageSetObject->method = $postValues['method']; |
|
| 28 | + $imageSetObject->title = $postValues['title']; |
|
| 29 | + $imageSetObject->slug = StringUtil::slugify($postValues['title']); |
|
| 30 | + $imageSetObject->width = $postValues['width']; |
|
| 31 | + $imageSetObject->height = $postValues['height']; |
|
| 32 | + $imageSetObject->method = $postValues['method']; |
|
| 33 | 33 | |
| 34 | - return $imageSetObject; |
|
| 35 | - } else { |
|
| 36 | - throw new \Exception('Trying to create image set with invalid data.'); |
|
| 37 | - } |
|
| 38 | - } |
|
| 34 | + return $imageSetObject; |
|
| 35 | + } else { |
|
| 36 | + throw new \Exception('Trying to create image set with invalid data.'); |
|
| 37 | + } |
|
| 38 | + } |
|
| 39 | 39 | } |
| 40 | 40 | \ No newline at end of file |
@@ -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 |
@@ -75,13 +75,13 @@ discard block |
||
| 75 | 75 | $this->$name = $value; |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * @param string $orderBy |
|
| 80 | - * @param string $order |
|
| 81 | - * |
|
| 82 | - * @return array |
|
| 83 | - * @throws \Exception |
|
| 84 | - */ |
|
| 78 | + /** |
|
| 79 | + * @param string $orderBy |
|
| 80 | + * @param string $order |
|
| 81 | + * |
|
| 82 | + * @return array |
|
| 83 | + * @throws \Exception |
|
| 84 | + */ |
|
| 85 | 85 | public function getContent($orderBy = 'title', $order = 'ASC') |
| 86 | 86 | { |
| 87 | 87 | if (empty($this->content)) { |
@@ -89,16 +89,16 @@ discard block |
||
| 89 | 89 | $this->content = $docs; |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - return $this->content; |
|
| 92 | + return $this->content; |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | - /** |
|
| 96 | - * @return string |
|
| 97 | - */ |
|
| 98 | - public function __toString() |
|
| 99 | - { |
|
| 100 | - return 'Document:' . $this->title; |
|
| 101 | - } |
|
| 95 | + /** |
|
| 96 | + * @return string |
|
| 97 | + */ |
|
| 98 | + public function __toString() |
|
| 99 | + { |
|
| 100 | + return 'Document:' . $this->title; |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | 103 | |
| 104 | 104 | } |
| 105 | 105 | \ No newline at end of file |