Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 8 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| Loader | |
0.00% |
0 / 8 |
|
0.00% |
0 / 3 |
12 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| getAssetContent | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| getItemMediaResolver | |
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) 2015 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\taoItems\model\asset; |
| 23 | |
| 24 | use core_kernel_classes_Resource; |
| 25 | use taoItems_models_classes_ItemsService; |
| 26 | use common_Exception; |
| 27 | use tao_helpers_File; |
| 28 | use oat\taoItems\model\media\ItemMediaResolver; |
| 29 | |
| 30 | /** |
| 31 | * To allow packing of Item. The goal of the packaging is to reprensent the data needed |
| 32 | * to run an item (ie. an ItemPack). |
| 33 | * |
| 34 | * @author Bertrand Chevrier <bertrand@taotesting.com> |
| 35 | * @deprecated use ItemMediaResolver directly |
| 36 | */ |
| 37 | class Loader |
| 38 | { |
| 39 | /** |
| 40 | * The item to pack |
| 41 | * @var core_kernel_classes_Resource |
| 42 | */ |
| 43 | private $item; |
| 44 | |
| 45 | /** |
| 46 | * The lang of the item to pack |
| 47 | * @var string |
| 48 | */ |
| 49 | private $lang; |
| 50 | |
| 51 | /** |
| 52 | * The item service |
| 53 | * @var taoItems_models_classes_ItemsService |
| 54 | */ |
| 55 | private $itemService; |
| 56 | |
| 57 | /** |
| 58 | * Create a packer for an item |
| 59 | * @param core_kernel_classes_Resource $item |
| 60 | */ |
| 61 | public function __construct(core_kernel_classes_Resource $item, $lang = '') |
| 62 | { |
| 63 | $this->item = $item; |
| 64 | $this->lang = $lang; |
| 65 | $this->itemService = taoItems_models_classes_ItemsService::singleton(); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Get the content of an asset. |
| 70 | * |
| 71 | * @param string $assetPath the asset path |
| 72 | * @return null|string the asset content or null if not stored locally |
| 73 | * @throws common_Exception if the resource cannot be retrieved |
| 74 | */ |
| 75 | public function getAssetContent($assetPath) |
| 76 | { |
| 77 | $mediaAsset = $this->getItemMediaResolver()->resolve($assetPath); |
| 78 | $mediaSource = $mediaAsset->getMediaSource(); |
| 79 | $srcPath = $mediaSource->download($mediaAsset->getMediaIdentifier()); |
| 80 | return file_get_contents($srcPath); |
| 81 | } |
| 82 | |
| 83 | protected function getItemMediaResolver() |
| 84 | { |
| 85 | return new ItemMediaResolver($this->item, $this->lang); |
| 86 | } |
| 87 | } |