Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 15 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| tao_models_classes_TaoService | |
0.00% |
0 / 15 |
|
0.00% |
0 / 3 |
12 | |
0.00% |
0 / 1 |
| setUploadFileSourceId | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| storeUploadedFile | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
2 | |||
| getPlatformVersion | |
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) 2002-2008 (original work) Public Research Centre Henri Tudor & University of Luxembourg |
| 19 | * (under the project TAO & TAO2); |
| 20 | * 2008-2010 (update and modification) Deutsche Institut für Internationale Pädagogische Forschung |
| 21 | * (under the project TAO-TRANSFER); |
| 22 | * 2009-2012 (update and modification) Public Research Centre Henri Tudor |
| 23 | * (under the project TAO-SUSTAIN & TAO-DEV); |
| 24 | * |
| 25 | */ |
| 26 | use oat\oatbox\filesystem\File; |
| 27 | use oat\oatbox\filesystem\FileSystemService; |
| 28 | use oat\generis\model\fileReference\FileReferenceSerializer; |
| 29 | use oat\tao\model\service\ApplicationService; |
| 30 | |
| 31 | /** |
| 32 | * This class provide the services for the Tao extension |
| 33 | * |
| 34 | * @access public |
| 35 | * @author Jerome Bogaerts, <jerome@taotesting.com> |
| 36 | * @package tao |
| 37 | |
| 38 | */ |
| 39 | class tao_models_classes_TaoService extends tao_models_classes_GenerisService |
| 40 | { |
| 41 | /** |
| 42 | * The key to use to store the default TAO Upload File Source Repository URI |
| 43 | * the TAO meta-extension configuration. |
| 44 | * |
| 45 | * @access public |
| 46 | * @var string |
| 47 | */ |
| 48 | public const CONFIG_UPLOAD_FILESOURCE = 'defaultUploadFileSource'; |
| 49 | |
| 50 | /** |
| 51 | * Set the default file source for TAO File Upload. |
| 52 | * |
| 53 | * @access public |
| 54 | * @author Jerome Bogaerts, <jerome@taotesting.com> |
| 55 | * @param string sourceId The repository to be used as the default TAO File Upload Source. |
| 56 | * @return void |
| 57 | */ |
| 58 | public function setUploadFileSourceId($sourceId) |
| 59 | { |
| 60 | |
| 61 | $ext = common_ext_ExtensionsManager::singleton()->getExtensionById('tao'); |
| 62 | $ext->setConfig(self::CONFIG_UPLOAD_FILESOURCE, $sourceId); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Store an uploaded file in the persistant storage and return a serial id |
| 67 | * |
| 68 | * @param File $tmpFile |
| 69 | * @param string $name |
| 70 | * @return string |
| 71 | */ |
| 72 | public function storeUploadedFile(File $tmpFile, $name = '') |
| 73 | { |
| 74 | $ext = common_ext_ExtensionsManager::singleton()->getExtensionById('tao'); |
| 75 | $fsId = $ext->getConfig(self::CONFIG_UPLOAD_FILESOURCE); |
| 76 | $fss = $this->getServiceLocator()->get(FileSystemService::SERVICE_ID); |
| 77 | $baseDir = $fss->getDirectory($fsId); |
| 78 | do { |
| 79 | $unique = uniqid(); |
| 80 | $dir = implode('/', str_split(substr($unique, 0, 3))) . '/' . substr($unique, 3); |
| 81 | $file = $baseDir->getFile($dir . '/' . $name); |
| 82 | } while ($file->exists()); |
| 83 | $file->write($tmpFile->read()); |
| 84 | $referencer = $this->getServiceLocator()->get(FileReferenceSerializer::SERVICE_ID); |
| 85 | $serial = $referencer->serialize($file); |
| 86 | return $serial; |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Get the tao platform version |
| 91 | * @return string |
| 92 | * @deprecated |
| 93 | */ |
| 94 | public function getPlatformVersion() |
| 95 | { |
| 96 | return $this->getServiceLocator()->get(ApplicationService::SERVICE_ID)->getPlatformVersion(); |
| 97 | } |
| 98 | } |