Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
95.24% |
20 / 21 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| AssetTreeBuilder | |
95.24% |
20 / 21 |
|
50.00% |
1 / 2 |
5 | |
0.00% |
0 / 1 |
| build | |
95.00% |
19 / 20 |
|
0.00% |
0 / 1 |
4 | |||
| getPaginationLimit | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2020-2021 (original work) Open Assessment Technologies SA; |
| 19 | */ |
| 20 | |
| 21 | declare(strict_types=1); |
| 22 | |
| 23 | namespace oat\taoItems\model\media; |
| 24 | |
| 25 | use oat\oatbox\service\ConfigurableService; |
| 26 | use oat\tao\model\accessControl\AccessControlEnablerInterface; |
| 27 | use oat\tao\model\media\mediaSource\DirectorySearchQuery; |
| 28 | use tao_helpers_Uri; |
| 29 | |
| 30 | class AssetTreeBuilder extends ConfigurableService implements AssetTreeBuilderInterface |
| 31 | { |
| 32 | public const SERVICE_ID = 'taoItems/AssetTreeBuilder'; |
| 33 | |
| 34 | public const OPTION_PAGINATION_LIMIT = 'pagination_limit'; |
| 35 | public const DEFAULT_PAGINATION_OFFSET = 0; |
| 36 | private const DEFAULT_PAGINATION_LIMIT = 15; |
| 37 | |
| 38 | public function build(DirectorySearchQuery $search): array |
| 39 | { |
| 40 | $asset = $search->getAsset(); |
| 41 | |
| 42 | $search->setChildrenLimit($this->getPaginationLimit()); |
| 43 | |
| 44 | $mediaSource = $asset->getMediaSource(); |
| 45 | |
| 46 | if ($mediaSource instanceof AccessControlEnablerInterface) { |
| 47 | $mediaSource->enableAccessControl(); |
| 48 | } |
| 49 | |
| 50 | $data = $mediaSource->getDirectories($search); |
| 51 | |
| 52 | foreach ($data['children'] as &$child) { |
| 53 | if (isset($child['parent'])) { |
| 54 | $child['url'] = tao_helpers_Uri::url( |
| 55 | 'files', |
| 56 | 'ItemContent', |
| 57 | 'taoItems', |
| 58 | [ |
| 59 | 'uri' => $search->getItemUri(), |
| 60 | 'lang' => $search->getItemLang(), |
| 61 | '1' => $child['parent'] |
| 62 | ] |
| 63 | ); |
| 64 | |
| 65 | unset($child['parent']); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | return $data; |
| 70 | } |
| 71 | |
| 72 | private function getPaginationLimit(): int |
| 73 | { |
| 74 | return (int)$this->getOption(self::OPTION_PAGINATION_LIMIT, self::DEFAULT_PAGINATION_LIMIT); |
| 75 | } |
| 76 | } |