Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 24 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| MediaImport | |
0.00% |
0 / 24 |
|
0.00% |
0 / 5 |
90 | |
0.00% |
0 / 1 |
| index | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| editMedia | |
0.00% |
0 / 19 |
|
0.00% |
0 / 1 |
30 | |||
| getAvailableImportHandlers | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getImportHandlerFactory | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getPermissionService | |
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) 2020 (original work) Open Assessment Technologies SA; |
| 19 | */ |
| 20 | |
| 21 | namespace oat\taoMediaManager\controller; |
| 22 | |
| 23 | use oat\taoMediaManager\model\ImportHandlerFactory; |
| 24 | use oat\taoMediaManager\model\accessControl\MediaPermissionService; |
| 25 | use tao_actions_Import; |
| 26 | use tao_models_classes_import_ImportHandler; |
| 27 | |
| 28 | /** |
| 29 | * This controller provides the actions to import medias |
| 30 | */ |
| 31 | class MediaImport extends tao_actions_Import |
| 32 | { |
| 33 | /** @var tao_models_classes_import_ImportHandler[] */ |
| 34 | private $importHandlers; |
| 35 | |
| 36 | /** |
| 37 | * @inheritDoc |
| 38 | * |
| 39 | * @requiresRight id WRITE |
| 40 | * @requiresRight classUri WRITE |
| 41 | */ |
| 42 | public function index() |
| 43 | { |
| 44 | $this->importHandlers = $this->getImportHandlerFactory()->createAvailable(); |
| 45 | |
| 46 | parent::index(); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * This action is called when requesting or submitting the upload form. |
| 51 | */ |
| 52 | public function editMedia() |
| 53 | { |
| 54 | $id = $this->hasRequestParameter('instanceUri') |
| 55 | ? $this->getRequestParameter('instanceUri') |
| 56 | : $this->getRequestParameter('id'); |
| 57 | |
| 58 | if (empty($id)) { |
| 59 | $this->returnError( |
| 60 | __('Request should provide a media identifier as the id or instanceUri parameter'), |
| 61 | true, |
| 62 | 400 |
| 63 | ); |
| 64 | return; |
| 65 | } |
| 66 | |
| 67 | $permissionService = $this->getPermissionService(); |
| 68 | $resource = $this->getResource($id); |
| 69 | $user = $this->getSession()->getUser(); |
| 70 | |
| 71 | if ( |
| 72 | !$permissionService->isAllowedToEditResource($resource, $user) |
| 73 | || !$permissionService->isAllowedToEditMedia($user) |
| 74 | ) { |
| 75 | $this->returnError('Access denied', true, 403); |
| 76 | return; |
| 77 | } |
| 78 | |
| 79 | $this->importHandlers = [$this->getImportHandlerFactory()->createByMediaId($id)]; |
| 80 | |
| 81 | parent::index(); |
| 82 | } |
| 83 | |
| 84 | protected function getAvailableImportHandlers() |
| 85 | { |
| 86 | return $this->importHandlers; |
| 87 | } |
| 88 | |
| 89 | private function getImportHandlerFactory(): ImportHandlerFactory |
| 90 | { |
| 91 | return $this->getPsrContainer()->get(ImportHandlerFactory::class); |
| 92 | } |
| 93 | |
| 94 | private function getPermissionService(): MediaPermissionService |
| 95 | { |
| 96 | return $this->getPsrContainer()->get(MediaPermissionService::class); |
| 97 | } |
| 98 | } |