Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 10 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| tao_helpers_form_data_UploadFileDescription | |
0.00% |
0 / 10 |
|
0.00% |
0 / 4 |
42 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
12 | |||
| getType | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getTmpPath | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getAction | |
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) 2008-2010 (original work) Deutsche Institut für Internationale Pädagogische Forschung |
| 19 | * (under the project TAO-TRANSFER); |
| 20 | * 2009-2016 (update and modification) Public Research Centre Henri Tudor |
| 21 | * (under the project TAO-SUSTAIN & TAO-DEV); |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | use oat\oatbox\service\ServiceManager; |
| 26 | use oat\tao\model\upload\UploadService; |
| 27 | |
| 28 | /** |
| 29 | * The description of a file at upload time. |
| 30 | * |
| 31 | * @access public |
| 32 | * @author Jerome Bogaerts, <jerome@taotesting.com> |
| 33 | * @package tao |
| 34 | */ |
| 35 | class tao_helpers_form_data_UploadFileDescription extends tao_helpers_form_data_FileDescription |
| 36 | { |
| 37 | /** Action form: add */ |
| 38 | public const FORM_ACTION_ADD = 'add'; |
| 39 | |
| 40 | /** Action form: delete */ |
| 41 | public const FORM_ACTION_DELETE = 'delete'; |
| 42 | |
| 43 | /** |
| 44 | * The mime/type of the file e.g. text/plain. |
| 45 | * |
| 46 | * @access private |
| 47 | * @var string |
| 48 | */ |
| 49 | private $type = ''; |
| 50 | |
| 51 | /** |
| 52 | * The temporary file path where the file is uploaded, waiting to be moved |
| 53 | * the right place on the file system. |
| 54 | * |
| 55 | * @access private |
| 56 | * @var \oat\oatbox\filesystem\File |
| 57 | */ |
| 58 | private $tmpPath; |
| 59 | |
| 60 | /** |
| 61 | * Allow to specify action to know form purpose |
| 62 | * |
| 63 | * @var string |
| 64 | */ |
| 65 | private $action; |
| 66 | |
| 67 | /** |
| 68 | * The temporary file path where the file is stored before being moved to |
| 69 | * right place. |
| 70 | * |
| 71 | * @access public |
| 72 | * @author Jerome Bogaerts <jerome@taotesting.com> |
| 73 | * @param string $name The name of the file e.g. tmpImage.tmp |
| 74 | * @param int $size The size of the file in bytes |
| 75 | * @param string $type The mime-type of the file e.g. text/plain. |
| 76 | * @param string $tmpPath |
| 77 | * @param string $action |
| 78 | * @return mixed |
| 79 | * @throws \oat\oatbox\service\ServiceNotFoundException |
| 80 | * @throws \common_Exception |
| 81 | */ |
| 82 | public function __construct($name, $size, $type, $tmpPath, $action = null) |
| 83 | { |
| 84 | parent::__construct($name, $size); |
| 85 | $this->type = $type; |
| 86 | if ($tmpPath) { |
| 87 | $this->tmpPath = ServiceManager::getServiceManager() |
| 88 | ->get(UploadService::SERVICE_ID) |
| 89 | ->universalizeUpload($tmpPath); |
| 90 | } |
| 91 | $this->action = is_null($action) ? self::FORM_ACTION_ADD : $action; |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Returns the mime-type of the file. |
| 96 | * |
| 97 | * @access public |
| 98 | * @author Jerome Bogaerts <jerome@taotesting.com> |
| 99 | * @return string |
| 100 | */ |
| 101 | public function getType() |
| 102 | { |
| 103 | return (string) $this->type; |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * Returns the temporary path of the file. |
| 108 | * |
| 109 | * @access public |
| 110 | * @author Jerome Bogaerts <jerome@taotesting.com> |
| 111 | * @return \oat\oatbox\filesystem\File |
| 112 | */ |
| 113 | public function getTmpPath() |
| 114 | { |
| 115 | return $this->tmpPath; |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * Return action form |
| 120 | * |
| 121 | * @return string |
| 122 | */ |
| 123 | public function getAction() |
| 124 | { |
| 125 | return $this->action; |
| 126 | } |
| 127 | } |