@@ -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 |
@@ -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 |
@@ -10,123 +10,123 @@ |
||
| 10 | 10 | |
| 11 | 11 | class DocumentStorage extends AbstractStorage |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * Get documents |
|
| 15 | - * |
|
| 16 | - * @param string $state |
|
| 17 | - * |
|
| 18 | - * @return array |
|
| 19 | - * @throws \Exception |
|
| 20 | - */ |
|
| 21 | - public function getDocuments($state = 'published') |
|
| 22 | - { |
|
| 23 | - if (!in_array($state, Document::$DOCUMENT_STATES)) { |
|
| 24 | - throw new \Exception('Unsupported document state: ' . $state); |
|
| 25 | - } |
|
| 26 | - return $this->repository->getDocuments($state); |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - public function getDocumentsWithState($folderPath = '/') |
|
| 30 | - { |
|
| 31 | - return $this->repository->getDocumentsWithState($folderPath); |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * @return int |
|
| 36 | - */ |
|
| 37 | - public function getTotalDocumentCount() |
|
| 38 | - { |
|
| 39 | - return $this->repository->getTotalDocumentCount(); |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @param string $slug |
|
| 44 | - * |
|
| 45 | - * @param string $state |
|
| 46 | - * |
|
| 47 | - * @return mixed |
|
| 48 | - * @throws \Exception |
|
| 49 | - */ |
|
| 50 | - public function getDocumentBySlug($slug, $state = 'published') |
|
| 51 | - { |
|
| 52 | - if (!in_array($state, Document::$DOCUMENT_STATES)) { |
|
| 53 | - throw new \Exception('Unsupported document state: ' . $state); |
|
| 54 | - } |
|
| 55 | - $path = '/' . $slug; |
|
| 56 | - |
|
| 57 | - return $this->repository->getDocumentByPath($path, $state); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @param $postValues |
|
| 62 | - * @param $state |
|
| 63 | - * |
|
| 64 | - * @throws \Exception |
|
| 65 | - */ |
|
| 66 | - public function saveDocument($postValues, $state = 'unpublished') |
|
| 67 | - { |
|
| 68 | - if (!in_array($state, Document::$DOCUMENT_STATES)) { |
|
| 69 | - throw new \Exception('Unsupported document state: ' . $state); |
|
| 70 | - } |
|
| 71 | - $oldPath = '/' . $postValues['path']; |
|
| 72 | - |
|
| 73 | - $container = $this->getDocumentContainerByPath($oldPath); |
|
| 74 | - $documentObject = DocumentFactory::createDocumentFromPostValues($postValues, new DocumentTypesStorage($this->repository)); |
|
| 75 | - if ($container->path === '/') { |
|
| 76 | - $newPath = $container->path . $documentObject->slug; |
|
| 77 | - } else { |
|
| 78 | - $newPath = $container->path . '/' . $documentObject->slug; |
|
| 79 | - } |
|
| 80 | - $documentObject->path = $newPath; |
|
| 81 | - $this->repository->saveDocument($documentObject, $state); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * @param $postValues |
|
| 86 | - * @param string $state |
|
| 87 | - */ |
|
| 88 | - public function addDocument($postValues, $state = 'unpublished') |
|
| 89 | - { |
|
| 90 | - $documentObject = DocumentFactory::createDocumentFromPostValues($postValues, new DocumentTypesStorage($this->repository)); |
|
| 91 | - if ($postValues['path'] === '/') { |
|
| 92 | - $documentObject->path = $postValues['path'] . $documentObject->slug; |
|
| 93 | - } else { |
|
| 94 | - $documentObject->path = $postValues['path'] . '/' . $documentObject->slug; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - $this->repository->saveDocument($documentObject, $state); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * @param $slug |
|
| 102 | - */ |
|
| 103 | - public function deleteDocumentBySlug($slug) |
|
| 104 | - { |
|
| 105 | - $path = '/' . $slug; |
|
| 106 | - $this->repository->deleteDocumentByPath($path); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * Returns the folder containing the document |
|
| 111 | - * |
|
| 112 | - * @param $path |
|
| 113 | - * |
|
| 114 | - * @return bool|\CloudControl\Cms\storage\Document |
|
| 115 | - * @throws \Exception |
|
| 116 | - */ |
|
| 117 | - private function getDocumentContainerByPath($path) |
|
| 118 | - { |
|
| 119 | - return $this->repository->getDocumentContainerByPath($path); |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - public function getPublishedDocumentsNoFolders() |
|
| 123 | - { |
|
| 124 | - return $this->repository->getPublishedDocumentsNoFolders(); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - public function cleanPublishedDeletedDocuments() |
|
| 128 | - { |
|
| 129 | - $this->repository->cleanPublishedDeletedDocuments(); |
|
| 130 | - } |
|
| 13 | + /** |
|
| 14 | + * Get documents |
|
| 15 | + * |
|
| 16 | + * @param string $state |
|
| 17 | + * |
|
| 18 | + * @return array |
|
| 19 | + * @throws \Exception |
|
| 20 | + */ |
|
| 21 | + public function getDocuments($state = 'published') |
|
| 22 | + { |
|
| 23 | + if (!in_array($state, Document::$DOCUMENT_STATES)) { |
|
| 24 | + throw new \Exception('Unsupported document state: ' . $state); |
|
| 25 | + } |
|
| 26 | + return $this->repository->getDocuments($state); |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + public function getDocumentsWithState($folderPath = '/') |
|
| 30 | + { |
|
| 31 | + return $this->repository->getDocumentsWithState($folderPath); |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * @return int |
|
| 36 | + */ |
|
| 37 | + public function getTotalDocumentCount() |
|
| 38 | + { |
|
| 39 | + return $this->repository->getTotalDocumentCount(); |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @param string $slug |
|
| 44 | + * |
|
| 45 | + * @param string $state |
|
| 46 | + * |
|
| 47 | + * @return mixed |
|
| 48 | + * @throws \Exception |
|
| 49 | + */ |
|
| 50 | + public function getDocumentBySlug($slug, $state = 'published') |
|
| 51 | + { |
|
| 52 | + if (!in_array($state, Document::$DOCUMENT_STATES)) { |
|
| 53 | + throw new \Exception('Unsupported document state: ' . $state); |
|
| 54 | + } |
|
| 55 | + $path = '/' . $slug; |
|
| 56 | + |
|
| 57 | + return $this->repository->getDocumentByPath($path, $state); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @param $postValues |
|
| 62 | + * @param $state |
|
| 63 | + * |
|
| 64 | + * @throws \Exception |
|
| 65 | + */ |
|
| 66 | + public function saveDocument($postValues, $state = 'unpublished') |
|
| 67 | + { |
|
| 68 | + if (!in_array($state, Document::$DOCUMENT_STATES)) { |
|
| 69 | + throw new \Exception('Unsupported document state: ' . $state); |
|
| 70 | + } |
|
| 71 | + $oldPath = '/' . $postValues['path']; |
|
| 72 | + |
|
| 73 | + $container = $this->getDocumentContainerByPath($oldPath); |
|
| 74 | + $documentObject = DocumentFactory::createDocumentFromPostValues($postValues, new DocumentTypesStorage($this->repository)); |
|
| 75 | + if ($container->path === '/') { |
|
| 76 | + $newPath = $container->path . $documentObject->slug; |
|
| 77 | + } else { |
|
| 78 | + $newPath = $container->path . '/' . $documentObject->slug; |
|
| 79 | + } |
|
| 80 | + $documentObject->path = $newPath; |
|
| 81 | + $this->repository->saveDocument($documentObject, $state); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * @param $postValues |
|
| 86 | + * @param string $state |
|
| 87 | + */ |
|
| 88 | + public function addDocument($postValues, $state = 'unpublished') |
|
| 89 | + { |
|
| 90 | + $documentObject = DocumentFactory::createDocumentFromPostValues($postValues, new DocumentTypesStorage($this->repository)); |
|
| 91 | + if ($postValues['path'] === '/') { |
|
| 92 | + $documentObject->path = $postValues['path'] . $documentObject->slug; |
|
| 93 | + } else { |
|
| 94 | + $documentObject->path = $postValues['path'] . '/' . $documentObject->slug; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + $this->repository->saveDocument($documentObject, $state); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * @param $slug |
|
| 102 | + */ |
|
| 103 | + public function deleteDocumentBySlug($slug) |
|
| 104 | + { |
|
| 105 | + $path = '/' . $slug; |
|
| 106 | + $this->repository->deleteDocumentByPath($path); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * Returns the folder containing the document |
|
| 111 | + * |
|
| 112 | + * @param $path |
|
| 113 | + * |
|
| 114 | + * @return bool|\CloudControl\Cms\storage\Document |
|
| 115 | + * @throws \Exception |
|
| 116 | + */ |
|
| 117 | + private function getDocumentContainerByPath($path) |
|
| 118 | + { |
|
| 119 | + return $this->repository->getDocumentContainerByPath($path); |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + public function getPublishedDocumentsNoFolders() |
|
| 123 | + { |
|
| 124 | + return $this->repository->getPublishedDocumentsNoFolders(); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + public function cleanPublishedDeletedDocuments() |
|
| 128 | + { |
|
| 129 | + $this->repository->cleanPublishedDeletedDocuments(); |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | 132 | } |
| 133 | 133 | \ No newline at end of file |
@@ -11,63 +11,63 @@ |
||
| 11 | 11 | |
| 12 | 12 | abstract class AbstractStorage |
| 13 | 13 | { |
| 14 | - /** |
|
| 15 | - * @var Repository |
|
| 16 | - */ |
|
| 17 | - protected $repository; |
|
| 14 | + /** |
|
| 15 | + * @var Repository |
|
| 16 | + */ |
|
| 17 | + protected $repository; |
|
| 18 | 18 | |
| 19 | - public function __construct($repository) |
|
| 20 | - { |
|
| 21 | - $this->repository = $repository; |
|
| 22 | - } |
|
| 19 | + public function __construct($repository) |
|
| 20 | + { |
|
| 21 | + $this->repository = $repository; |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Converts filename to lowercase, remove non-ascii chars |
|
| 26 | - * And adds "-copy" if the file already exists |
|
| 27 | - * |
|
| 28 | - * @param $filename |
|
| 29 | - * @param $path |
|
| 30 | - * |
|
| 31 | - * @return string |
|
| 32 | - */ |
|
| 33 | - protected function validateFilename($filename, $path) |
|
| 34 | - { |
|
| 35 | - $fileParts = explode('.', $filename); |
|
| 36 | - if (count($fileParts) > 1) { |
|
| 37 | - $extension = end($fileParts); |
|
| 38 | - array_pop($fileParts); |
|
| 39 | - $fileNameWithoutExtension = implode('-', $fileParts); |
|
| 40 | - $fileNameWithoutExtension = StringUtil::slugify($fileNameWithoutExtension); |
|
| 41 | - $filename = $fileNameWithoutExtension . '.' . $extension; |
|
| 42 | - } else { |
|
| 43 | - $filename = StringUtil::slugify($filename); |
|
| 44 | - } |
|
| 24 | + /** |
|
| 25 | + * Converts filename to lowercase, remove non-ascii chars |
|
| 26 | + * And adds "-copy" if the file already exists |
|
| 27 | + * |
|
| 28 | + * @param $filename |
|
| 29 | + * @param $path |
|
| 30 | + * |
|
| 31 | + * @return string |
|
| 32 | + */ |
|
| 33 | + protected function validateFilename($filename, $path) |
|
| 34 | + { |
|
| 35 | + $fileParts = explode('.', $filename); |
|
| 36 | + if (count($fileParts) > 1) { |
|
| 37 | + $extension = end($fileParts); |
|
| 38 | + array_pop($fileParts); |
|
| 39 | + $fileNameWithoutExtension = implode('-', $fileParts); |
|
| 40 | + $fileNameWithoutExtension = StringUtil::slugify($fileNameWithoutExtension); |
|
| 41 | + $filename = $fileNameWithoutExtension . '.' . $extension; |
|
| 42 | + } else { |
|
| 43 | + $filename = StringUtil::slugify($filename); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - if (file_exists($path . '/' . $filename)) { |
|
| 47 | - $fileParts = explode('.', $filename); |
|
| 48 | - if (count($fileParts) > 1) { |
|
| 49 | - $extension = end($fileParts); |
|
| 50 | - array_pop($fileParts); |
|
| 51 | - $fileNameWithoutExtension = implode('-', $fileParts); |
|
| 52 | - $fileNameWithoutExtension .= '-copy'; |
|
| 53 | - $filename = $fileNameWithoutExtension . '.' . $extension; |
|
| 54 | - } else { |
|
| 55 | - $filename .= '-copy'; |
|
| 56 | - } |
|
| 46 | + if (file_exists($path . '/' . $filename)) { |
|
| 47 | + $fileParts = explode('.', $filename); |
|
| 48 | + if (count($fileParts) > 1) { |
|
| 49 | + $extension = end($fileParts); |
|
| 50 | + array_pop($fileParts); |
|
| 51 | + $fileNameWithoutExtension = implode('-', $fileParts); |
|
| 52 | + $fileNameWithoutExtension .= '-copy'; |
|
| 53 | + $filename = $fileNameWithoutExtension . '.' . $extension; |
|
| 54 | + } else { |
|
| 55 | + $filename .= '-copy'; |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - return $this->validateFilename($filename, $path); |
|
| 59 | - } |
|
| 58 | + return $this->validateFilename($filename, $path); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - return $filename; |
|
| 62 | - } |
|
| 61 | + return $filename; |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * Save changes made to the repository |
|
| 66 | - * |
|
| 67 | - * @throws \Exception |
|
| 68 | - */ |
|
| 69 | - protected function save() |
|
| 70 | - { |
|
| 71 | - $this->repository->save(); |
|
| 72 | - } |
|
| 64 | + /** |
|
| 65 | + * Save changes made to the repository |
|
| 66 | + * |
|
| 67 | + * @throws \Exception |
|
| 68 | + */ |
|
| 69 | + protected function save() |
|
| 70 | + { |
|
| 71 | + $this->repository->save(); |
|
| 72 | + } |
|
| 73 | 73 | } |
| 74 | 74 | \ No newline at end of file |
@@ -10,75 +10,75 @@ |
||
| 10 | 10 | |
| 11 | 11 | class ApplicationComponentsStorage extends AbstractStorage |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * @return array |
|
| 15 | - */ |
|
| 16 | - public function getApplicationComponents() |
|
| 17 | - { |
|
| 18 | - return $this->repository->applicationComponents; |
|
| 19 | - } |
|
| 13 | + /** |
|
| 14 | + * @return array |
|
| 15 | + */ |
|
| 16 | + public function getApplicationComponents() |
|
| 17 | + { |
|
| 18 | + return $this->repository->applicationComponents; |
|
| 19 | + } |
|
| 20 | 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; |
|
| 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 | 30 | |
| 31 | - $this->save(); |
|
| 32 | - } |
|
| 31 | + $this->save(); |
|
| 32 | + } |
|
| 33 | 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 | - } |
|
| 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 | 47 | |
| 48 | - return null; |
|
| 49 | - } |
|
| 48 | + return null; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @param $slug |
|
| 53 | - * @param $postValues |
|
| 54 | - */ |
|
| 55 | - public function saveApplicationComponent($slug, $postValues) |
|
| 56 | - { |
|
| 57 | - $newApplicationComponent = ApplicationComponentFactory::createApplicationComponentFromPostValues($postValues); |
|
| 51 | + /** |
|
| 52 | + * @param $slug |
|
| 53 | + * @param $postValues |
|
| 54 | + */ |
|
| 55 | + public function saveApplicationComponent($slug, $postValues) |
|
| 56 | + { |
|
| 57 | + $newApplicationComponent = ApplicationComponentFactory::createApplicationComponentFromPostValues($postValues); |
|
| 58 | 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 | - } |
|
| 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 | 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 | - } |
|
| 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 | 84 | } |
| 85 | 85 | \ No newline at end of file |
@@ -12,111 +12,111 @@ |
||
| 12 | 12 | |
| 13 | 13 | class SitemapStorage extends AbstractStorage |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * @return array |
|
| 17 | - */ |
|
| 18 | - public function getSitemap() |
|
| 19 | - { |
|
| 20 | - return $this->repository->sitemap; |
|
| 21 | - } |
|
| 15 | + /** |
|
| 16 | + * @return array |
|
| 17 | + */ |
|
| 18 | + public function getSitemap() |
|
| 19 | + { |
|
| 20 | + return $this->repository->sitemap; |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Add a sitemap item |
|
| 25 | - * |
|
| 26 | - * @param $postValues |
|
| 27 | - * |
|
| 28 | - * @throws \Exception |
|
| 29 | - */ |
|
| 30 | - public function addSitemapItem($postValues) |
|
| 31 | - { |
|
| 32 | - $sitemapObject = SitemapItemFactory::createSitemapItemFromPostValues($postValues); |
|
| 33 | - $sitemap = $this->repository->sitemap; |
|
| 34 | - $sitemap[] = $sitemapObject; |
|
| 35 | - $this->repository->sitemap = $sitemap; |
|
| 36 | - $this->save(); |
|
| 37 | - } |
|
| 23 | + /** |
|
| 24 | + * Add a sitemap item |
|
| 25 | + * |
|
| 26 | + * @param $postValues |
|
| 27 | + * |
|
| 28 | + * @throws \Exception |
|
| 29 | + */ |
|
| 30 | + public function addSitemapItem($postValues) |
|
| 31 | + { |
|
| 32 | + $sitemapObject = SitemapItemFactory::createSitemapItemFromPostValues($postValues); |
|
| 33 | + $sitemap = $this->repository->sitemap; |
|
| 34 | + $sitemap[] = $sitemapObject; |
|
| 35 | + $this->repository->sitemap = $sitemap; |
|
| 36 | + $this->save(); |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * Save changes to a sitemap item |
|
| 41 | - * |
|
| 42 | - * @param $slug |
|
| 43 | - * @param $postValues |
|
| 44 | - * |
|
| 45 | - * @throws \Exception |
|
| 46 | - */ |
|
| 47 | - public function saveSitemapItem($slug, $postValues) |
|
| 48 | - { |
|
| 49 | - $sitemapObject = SitemapItemFactory::createSitemapItemFromPostValues($postValues); |
|
| 39 | + /** |
|
| 40 | + * Save changes to a sitemap item |
|
| 41 | + * |
|
| 42 | + * @param $slug |
|
| 43 | + * @param $postValues |
|
| 44 | + * |
|
| 45 | + * @throws \Exception |
|
| 46 | + */ |
|
| 47 | + public function saveSitemapItem($slug, $postValues) |
|
| 48 | + { |
|
| 49 | + $sitemapObject = SitemapItemFactory::createSitemapItemFromPostValues($postValues); |
|
| 50 | 50 | |
| 51 | - $sitemap = $this->repository->sitemap; |
|
| 52 | - foreach ($sitemap as $key => $sitemapItem) { |
|
| 53 | - if ($sitemapItem->slug == $slug) { |
|
| 54 | - $sitemap[$key] = $sitemapObject; |
|
| 55 | - } |
|
| 56 | - } |
|
| 57 | - $this->repository->sitemap = $sitemap; |
|
| 58 | - $this->save(); |
|
| 59 | - } |
|
| 51 | + $sitemap = $this->repository->sitemap; |
|
| 52 | + foreach ($sitemap as $key => $sitemapItem) { |
|
| 53 | + if ($sitemapItem->slug == $slug) { |
|
| 54 | + $sitemap[$key] = $sitemapObject; |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | + $this->repository->sitemap = $sitemap; |
|
| 58 | + $this->save(); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * Delete a sitemap item by its slug |
|
| 63 | - * |
|
| 64 | - * @param $slug |
|
| 65 | - * |
|
| 66 | - * @throws \Exception |
|
| 67 | - */ |
|
| 68 | - public function deleteSitemapItemBySlug($slug) |
|
| 69 | - { |
|
| 70 | - $sitemap = $this->repository->sitemap; |
|
| 71 | - foreach ($sitemap as $key => $sitemapItem) { |
|
| 72 | - if ($sitemapItem->slug == $slug) { |
|
| 73 | - unset($sitemap[$key]); |
|
| 74 | - } |
|
| 75 | - } |
|
| 76 | - $sitemap = array_values($sitemap); |
|
| 77 | - $this->repository->sitemap = $sitemap; |
|
| 78 | - $this->save(); |
|
| 79 | - } |
|
| 61 | + /** |
|
| 62 | + * Delete a sitemap item by its slug |
|
| 63 | + * |
|
| 64 | + * @param $slug |
|
| 65 | + * |
|
| 66 | + * @throws \Exception |
|
| 67 | + */ |
|
| 68 | + public function deleteSitemapItemBySlug($slug) |
|
| 69 | + { |
|
| 70 | + $sitemap = $this->repository->sitemap; |
|
| 71 | + foreach ($sitemap as $key => $sitemapItem) { |
|
| 72 | + if ($sitemapItem->slug == $slug) { |
|
| 73 | + unset($sitemap[$key]); |
|
| 74 | + } |
|
| 75 | + } |
|
| 76 | + $sitemap = array_values($sitemap); |
|
| 77 | + $this->repository->sitemap = $sitemap; |
|
| 78 | + $this->save(); |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * Save changes to a sitemap item |
|
| 83 | - * |
|
| 84 | - * @param $postValues |
|
| 85 | - * |
|
| 86 | - * @throws \Exception |
|
| 87 | - */ |
|
| 88 | - public function saveSitemap($postValues) |
|
| 89 | - { |
|
| 90 | - if (isset($postValues['sitemapitem']) && is_array($postValues['sitemapitem'])) { |
|
| 91 | - $sitemap = array(); |
|
| 92 | - foreach ($postValues['sitemapitem'] as $sitemapItem) { |
|
| 93 | - $sitemapItemObject = json_decode($sitemapItem); |
|
| 94 | - if (isset($sitemapItemObject->object)) { |
|
| 95 | - unset($sitemapItemObject->object); |
|
| 96 | - } |
|
| 97 | - $sitemap[] = $sitemapItemObject; |
|
| 98 | - } |
|
| 99 | - $this->repository->sitemap = $sitemap; |
|
| 100 | - $this->save(); |
|
| 101 | - } |
|
| 102 | - } |
|
| 81 | + /** |
|
| 82 | + * Save changes to a sitemap item |
|
| 83 | + * |
|
| 84 | + * @param $postValues |
|
| 85 | + * |
|
| 86 | + * @throws \Exception |
|
| 87 | + */ |
|
| 88 | + public function saveSitemap($postValues) |
|
| 89 | + { |
|
| 90 | + if (isset($postValues['sitemapitem']) && is_array($postValues['sitemapitem'])) { |
|
| 91 | + $sitemap = array(); |
|
| 92 | + foreach ($postValues['sitemapitem'] as $sitemapItem) { |
|
| 93 | + $sitemapItemObject = json_decode($sitemapItem); |
|
| 94 | + if (isset($sitemapItemObject->object)) { |
|
| 95 | + unset($sitemapItemObject->object); |
|
| 96 | + } |
|
| 97 | + $sitemap[] = $sitemapItemObject; |
|
| 98 | + } |
|
| 99 | + $this->repository->sitemap = $sitemap; |
|
| 100 | + $this->save(); |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - /** |
|
| 105 | - * Get a sitemap item by its slug |
|
| 106 | - * |
|
| 107 | - * @param $slug |
|
| 108 | - * |
|
| 109 | - * @return mixed |
|
| 110 | - */ |
|
| 111 | - public function getSitemapItemBySlug($slug) |
|
| 112 | - { |
|
| 113 | - $sitemap = $this->repository->sitemap; |
|
| 114 | - foreach ($sitemap as $sitemapItem) { |
|
| 115 | - if ($sitemapItem->slug == $slug) { |
|
| 116 | - return $sitemapItem; |
|
| 117 | - } |
|
| 118 | - } |
|
| 104 | + /** |
|
| 105 | + * Get a sitemap item by its slug |
|
| 106 | + * |
|
| 107 | + * @param $slug |
|
| 108 | + * |
|
| 109 | + * @return mixed |
|
| 110 | + */ |
|
| 111 | + public function getSitemapItemBySlug($slug) |
|
| 112 | + { |
|
| 113 | + $sitemap = $this->repository->sitemap; |
|
| 114 | + foreach ($sitemap as $sitemapItem) { |
|
| 115 | + if ($sitemapItem->slug == $slug) { |
|
| 116 | + return $sitemapItem; |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - return null; |
|
| 121 | - } |
|
| 120 | + return null; |
|
| 121 | + } |
|
| 122 | 122 | } |
| 123 | 123 | \ No newline at end of file |