Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 15 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 1 |
| tao_helpers_form_data_FileDescription | |
0.00% |
0 / 15 |
|
0.00% |
0 / 7 |
156 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| getName | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
12 | |||
| getSize | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
12 | |||
| getFile | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| getFileSerial | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setFile | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getServiceLocator | |
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-2012 (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\oatbox\filesystem\File; |
| 27 | use oat\generis\model\fileReference\FileReferenceSerializer; |
| 28 | |
| 29 | /** |
| 30 | * The FileDescription data type contains all the data that a form collects or |
| 31 | * about a file. |
| 32 | * |
| 33 | * @abstract |
| 34 | * @access public |
| 35 | * @author Jerome Bogaerts <jerome@taotesting.com> |
| 36 | * @package tao |
| 37 | |
| 38 | */ |
| 39 | abstract class tao_helpers_form_data_FileDescription |
| 40 | { |
| 41 | // --- ASSOCIATIONS --- |
| 42 | |
| 43 | |
| 44 | // --- ATTRIBUTES --- |
| 45 | |
| 46 | /** |
| 47 | * The name of the file e.g. thumbnail.png. |
| 48 | * |
| 49 | * @access private |
| 50 | * @var string |
| 51 | */ |
| 52 | private $name = null; |
| 53 | |
| 54 | /** |
| 55 | * The size of the file in bytes. |
| 56 | * |
| 57 | * @access private |
| 58 | * @var int |
| 59 | */ |
| 60 | private $size = null; |
| 61 | |
| 62 | /** |
| 63 | * Reference to the stored file |
| 64 | * @var string |
| 65 | */ |
| 66 | private $fileSerial = null; |
| 67 | |
| 68 | /** |
| 69 | * The filed stored in persistent memory (if already stored). |
| 70 | * |
| 71 | * @access private |
| 72 | * @var File |
| 73 | */ |
| 74 | private $file = null; |
| 75 | |
| 76 | // --- OPERATIONS --- |
| 77 | |
| 78 | /** |
| 79 | * Creates a new instance of FileDescription. |
| 80 | * |
| 81 | * @access public |
| 82 | * @author Jerome Bogaerts <jerome@taotesting.com> |
| 83 | * @param string name The name of the file such as thumbnail.svg |
| 84 | * @param int size The size of the file in bytes. |
| 85 | * @return mixed |
| 86 | */ |
| 87 | public function __construct($name, $size) |
| 88 | { |
| 89 | |
| 90 | $this->name = $name; |
| 91 | $this->size = $size; |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Returns the name of the file e.g. test.xml. |
| 96 | * |
| 97 | * @access public |
| 98 | * @author Jerome Bogaerts <jerome@taotesting.com> |
| 99 | * @return string |
| 100 | */ |
| 101 | public function getName() |
| 102 | { |
| 103 | if (is_null($this->name)) { |
| 104 | $this->name = is_null($this->getFile()) ? '' : $this->getFile()->getBasename(); |
| 105 | } |
| 106 | return $this->name; |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Returns the size of the file in bytes. |
| 111 | * |
| 112 | * @access public |
| 113 | * @author Jerome Bogaerts <jerome@taotesting.com> |
| 114 | * @return int |
| 115 | */ |
| 116 | public function getSize() |
| 117 | { |
| 118 | if (is_null($this->size)) { |
| 119 | $this->size = is_null($this->getFile()) ? 0 : $this->getFile()->getSize(); |
| 120 | } |
| 121 | return $this->size; |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * Gets the file bound to the FileDescription (returns null if not file |
| 126 | * in persistent memory). |
| 127 | * |
| 128 | * @access public |
| 129 | * @author Jerome Bogaerts, <jerome@taotesting.com> |
| 130 | * @return File |
| 131 | */ |
| 132 | public function getFile() |
| 133 | { |
| 134 | if (is_null($this->file)) { |
| 135 | $referencer = $this->getServiceLocator()->get(FileReferenceSerializer::SERVICE_ID); |
| 136 | $this->file = $referencer->unserialize($this->getFileSerial()); |
| 137 | } |
| 138 | return $this->file; |
| 139 | } |
| 140 | |
| 141 | public function getFileSerial() |
| 142 | { |
| 143 | return $this->fileSerial; |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * Set the File corresponding to the FileDescription in persistent memory. |
| 148 | * |
| 149 | * @access public |
| 150 | * @author Jerome Bogaerts, <jerome@taotesting.com> |
| 151 | * @param File file |
| 152 | * @return void |
| 153 | */ |
| 154 | public function setFile($serial) |
| 155 | { |
| 156 | $this->fileSerial = $serial; |
| 157 | } |
| 158 | |
| 159 | public function getServiceLocator() |
| 160 | { |
| 161 | return ServiceManager::getServiceManager(); |
| 162 | } |
| 163 | } |