Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 26 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| ListStylesheetsService | |
0.00% |
0 / 26 |
|
0.00% |
0 / 2 |
30 | |
0.00% |
0 / 1 |
| getList | |
0.00% |
0 / 25 |
|
0.00% |
0 / 1 |
20 | |||
| getStylesheetRepository | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 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) 2021 (original work) Open Assessment Technologies SA; |
| 19 | */ |
| 20 | |
| 21 | declare(strict_types=1); |
| 22 | |
| 23 | namespace oat\taoMediaManager\model\sharedStimulus\css\service; |
| 24 | |
| 25 | use oat\oatbox\service\ConfigurableService; |
| 26 | use oat\taoMediaManager\model\sharedStimulus\css\dto\ListStylesheets; |
| 27 | use oat\taoMediaManager\model\sharedStimulus\css\repository\StylesheetRepository; |
| 28 | |
| 29 | class ListStylesheetsService extends ConfigurableService |
| 30 | { |
| 31 | public function getList(ListStylesheets $listStylesheetsDTO): array |
| 32 | { |
| 33 | $stylesheetRepository = $this->getStylesheetRepository(); |
| 34 | |
| 35 | $path = $stylesheetRepository->getPath($listStylesheetsDTO->getUri()); |
| 36 | $list = $stylesheetRepository->listContents( |
| 37 | $path . DIRECTORY_SEPARATOR . StylesheetRepository::STYLESHEETS_DIRECTORY |
| 38 | )->toArray(); |
| 39 | /** |
| 40 | * here sorting files by creation date so that in case of css .selector collisions |
| 41 | * the rules will be applied from the last stylesheet added to the passage |
| 42 | */ |
| 43 | usort($list, function ($a, $b) { |
| 44 | return ($a['lastModified'] < $b['lastModified']) ? -1 : 1; |
| 45 | }); |
| 46 | |
| 47 | $data = []; |
| 48 | foreach ($list as $file) { |
| 49 | if ($file['type'] == 'file') { |
| 50 | $data[] = [ |
| 51 | 'name' => basename($file['path']), |
| 52 | 'uri' => DIRECTORY_SEPARATOR . basename($file['path']), |
| 53 | 'mime' => 'text/css', |
| 54 | 'filePath' => DIRECTORY_SEPARATOR . basename($file['path']), |
| 55 | 'size' => $file['fileSize'] |
| 56 | ]; |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | return [ |
| 61 | 'path' => DIRECTORY_SEPARATOR, |
| 62 | 'label' => 'Passage stylesheets', |
| 63 | 'childrenLimit' => 100, |
| 64 | 'total' => count($data), |
| 65 | 'children' => $data |
| 66 | ]; |
| 67 | } |
| 68 | |
| 69 | private function getStylesheetRepository(): StylesheetRepository |
| 70 | { |
| 71 | return $this->getServiceLocator()->get(StylesheetRepository::class); |
| 72 | } |
| 73 | } |