| @@ 27-130 (lines=104) @@ | ||
| 24 | /** |
|
| 25 | * Class GetCategoriesHelper |
|
| 26 | */ |
|
| 27 | class GetCategoriesHelper implements HelperInterface |
|
| 28 | { |
|
| 29 | /** @var EnvironmentInterface */ |
|
| 30 | private $environmentManager; |
|
| 31 | ||
| 32 | use StorageTrait; |
|
| 33 | ||
| 34 | /** |
|
| 35 | * GetCategoriesHelper constructor. |
|
| 36 | * |
|
| 37 | * @param EnvironmentInterface $environmentManager |
|
| 38 | * @param StorageInterface[] ...$dataStorages |
|
| 39 | */ |
|
| 40 | public function __construct(EnvironmentInterface $environmentManager, StorageInterface ...$dataStorages) |
|
| 41 | { |
|
| 42 | $this->environmentManager = $environmentManager; |
|
| 43 | $this->addStorageInstances($dataStorages); |
|
| 44 | } |
|
| 45 | ||
| 46 | /** |
|
| 47 | * Should return the name of the helper. |
|
| 48 | * |
|
| 49 | * @return string |
|
| 50 | */ |
|
| 51 | public static function getName() : string |
|
| 52 | { |
|
| 53 | return 'getCategories'; |
|
| 54 | } |
|
| 55 | ||
| 56 | /** |
|
| 57 | * Should return the name of the helper. |
|
| 58 | * |
|
| 59 | * @return string |
|
| 60 | */ |
|
| 61 | public static function getDefinition() : string |
|
| 62 | { |
|
| 63 | return '{{ getCategories(order_by, limit) }}'; |
|
| 64 | } |
|
| 65 | ||
| 66 | /** |
|
| 67 | * Gets helper options for the render. |
|
| 68 | * |
|
| 69 | * @return array |
|
| 70 | * @codeCoverageIgnore - empty array |
|
| 71 | */ |
|
| 72 | public static function getOptions() : array |
|
| 73 | { |
|
| 74 | return []; |
|
| 75 | } |
|
| 76 | ||
| 77 | /** |
|
| 78 | * Should return a description text. |
|
| 79 | * |
|
| 80 | * @return string |
|
| 81 | */ |
|
| 82 | public static function getDescription() : string |
|
| 83 | { |
|
| 84 | return 'Returns the categories for the current application.'; |
|
| 85 | } |
|
| 86 | ||
| 87 | /** |
|
| 88 | * A renderer helper should be called with its name. |
|
| 89 | * |
|
| 90 | * @return array |
|
| 91 | */ |
|
| 92 | public function __invoke() : array |
|
| 93 | { |
|
| 94 | $categories = []; |
|
| 95 | ||
| 96 | /** @var Storage\ApplicationStorage $applicationStorage */ |
|
| 97 | $applicationStorage = $this->getApplicationStorage(); |
|
| 98 | /** @var Storage\Filesystem\FilesystemCategoryStorage $categoryStorage */ |
|
| 99 | $categoryStorage = $this->getFilesystemCategoryStorage(); |
|
| 100 | /** @var Storage\Filesystem\FilesystemDirectoryStorage $directoryStorage */ |
|
| 101 | $directoryStorage = $this->getFilesystemDirectoryStorage(); |
|
| 102 | ||
| 103 | if (!$applicationStorage || !$categoryStorage || !$directoryStorage) { |
|
| 104 | return []; |
|
| 105 | } |
|
| 106 | ||
| 107 | /** @var Entity\ApplicationEntity $application */ |
|
| 108 | $application = $applicationStorage |
|
| 109 | ->getApplicationByName($this->environmentManager->getSelectedApplication()); |
|
| 110 | $applicationId = $application->getKeyData(); |
|
| 111 | ||
| 112 | /** @var array $categoryDirectoryData */ |
|
| 113 | $categoryDirectoryData = $directoryStorage |
|
| 114 | ->getDirectoryDataByApplicationAndProxy($applicationId, ProxyInterface::LIST_CATEGORY); |
|
| 115 | ||
| 116 | /** @var Entity\Filesystem\FilesystemCategoryEntity[] $categoryList */ |
|
| 117 | $categoryList = $categoryStorage |
|
| 118 | ->getFilesystemCategorysByApplication($applicationId); |
|
| 119 | ||
| 120 | foreach ($categoryList as $categoryEntity) { |
|
| 121 | $categories[] = [ |
|
| 122 | 'path' => $categoryDirectoryData['uri'], |
|
| 123 | 'name' => $categoryEntity->getName(), |
|
| 124 | 'title' => $categoryEntity->getTitle() |
|
| 125 | ]; |
|
| 126 | } |
|
| 127 | ||
| 128 | return $categories; |
|
| 129 | } |
|
| 130 | } |
|
| 131 | ||
| @@ 27-128 (lines=102) @@ | ||
| 24 | /** |
|
| 25 | * Class GetTagsHelper |
|
| 26 | */ |
|
| 27 | class GetTagsHelper implements HelperInterface |
|
| 28 | { |
|
| 29 | /** @var EnvironmentInterface */ |
|
| 30 | private $environmentManager; |
|
| 31 | ||
| 32 | use StorageTrait; |
|
| 33 | ||
| 34 | /** |
|
| 35 | * GetTagsHelper constructor. |
|
| 36 | * |
|
| 37 | * @param EnvironmentInterface $environmentManager |
|
| 38 | * @param StorageInterface[] ...$dataStorages |
|
| 39 | */ |
|
| 40 | public function __construct(EnvironmentInterface $environmentManager, StorageInterface ...$dataStorages) |
|
| 41 | { |
|
| 42 | $this->environmentManager = $environmentManager; |
|
| 43 | $this->addStorageInstances($dataStorages); |
|
| 44 | } |
|
| 45 | ||
| 46 | /** |
|
| 47 | * Should return the name of the helper. |
|
| 48 | * |
|
| 49 | * @return string |
|
| 50 | */ |
|
| 51 | public static function getName() : string |
|
| 52 | { |
|
| 53 | return 'getTags'; |
|
| 54 | } |
|
| 55 | ||
| 56 | /** |
|
| 57 | * Should return the name of the helper. |
|
| 58 | * |
|
| 59 | * @return string |
|
| 60 | */ |
|
| 61 | public static function getDefinition() : string |
|
| 62 | { |
|
| 63 | return '{{ getTags(order_by, limit) }}'; |
|
| 64 | } |
|
| 65 | ||
| 66 | /** |
|
| 67 | * Gets helper options for the render. |
|
| 68 | * |
|
| 69 | * @return array |
|
| 70 | * @codeCoverageIgnore - empty array |
|
| 71 | */ |
|
| 72 | public static function getOptions() : array |
|
| 73 | { |
|
| 74 | return []; |
|
| 75 | } |
|
| 76 | ||
| 77 | /** |
|
| 78 | * Should return a description text. |
|
| 79 | * |
|
| 80 | * @return string |
|
| 81 | */ |
|
| 82 | public static function getDescription() : string |
|
| 83 | { |
|
| 84 | return 'Returns the tags for the current application.'; |
|
| 85 | } |
|
| 86 | ||
| 87 | /** |
|
| 88 | * A renderer helper should be called with its name. |
|
| 89 | * |
|
| 90 | * @return array |
|
| 91 | */ |
|
| 92 | public function __invoke() : array |
|
| 93 | { |
|
| 94 | $tags = []; |
|
| 95 | ||
| 96 | /** @var Storage\ApplicationStorage $applicationStorage */ |
|
| 97 | $applicationStorage = $this->getApplicationStorage(); |
|
| 98 | /** @var Storage\Filesystem\FilesystemTagStorage $tagStorage */ |
|
| 99 | $tagStorage = $this->getFilesystemTagStorage(); |
|
| 100 | /** @var Storage\Filesystem\FilesystemDirectoryStorage $directoryStorage */ |
|
| 101 | $directoryStorage = $this->getFilesystemDirectoryStorage(); |
|
| 102 | ||
| 103 | if (!$applicationStorage || !$tagStorage || !$directoryStorage) { |
|
| 104 | return []; |
|
| 105 | } |
|
| 106 | ||
| 107 | /** @var Entity\ApplicationEntity $application */ |
|
| 108 | $application = $applicationStorage->getApplicationByName($this->environmentManager->getSelectedApplication()); |
|
| 109 | $applicationId = $application->getKeyData(); |
|
| 110 | ||
| 111 | /** @var array $categoryDirectoryData */ |
|
| 112 | $categoryDirectoryData = $directoryStorage |
|
| 113 | ->getDirectoryDataByApplicationAndProxy($applicationId, ProxyInterface::LIST_TAG); |
|
| 114 | ||
| 115 | /** @var Entity\Filesystem\FilesystemTagEntity[] $tagList */ |
|
| 116 | $tagList = $tagStorage->getFilesystemTagsByApplication($applicationId); |
|
| 117 | ||
| 118 | foreach ($tagList as $tagEntity) { |
|
| 119 | $tags[] = [ |
|
| 120 | 'path' => $categoryDirectoryData['uri'], |
|
| 121 | 'name' => $tagEntity->getName(), |
|
| 122 | 'title' => $tagEntity->getTitle() |
|
| 123 | ]; |
|
| 124 | } |
|
| 125 | ||
| 126 | return $tags; |
|
| 127 | } |
|
| 128 | } |
|
| 129 | ||