Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 19 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| tao_helpers_form_elements_xhtml_File | |
0.00% |
0 / 19 |
|
0.00% |
0 / 4 |
72 | |
0.00% |
0 / 1 |
| feed | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| render | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
20 | |||
| getEvaluatedValue | |
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\generis\model\fileReference\FileReferenceSerializer; |
| 26 | use oat\oatbox\filesystem\File; |
| 27 | use oat\oatbox\service\ServiceManager; |
| 28 | use oat\tao\helpers\form\elements\xhtml\XhtmlRenderingTrait; |
| 29 | |
| 30 | /** |
| 31 | * Short description of class tao_helpers_form_elements_xhtml_File |
| 32 | * |
| 33 | * @access public |
| 34 | * @author Joel Bout, <joel.bout@tudor.lu> |
| 35 | * @package tao |
| 36 | */ |
| 37 | class tao_helpers_form_elements_xhtml_File extends tao_helpers_form_elements_File |
| 38 | { |
| 39 | use XhtmlRenderingTrait; |
| 40 | |
| 41 | /** |
| 42 | * Short description of method feed |
| 43 | * |
| 44 | * @access public |
| 45 | * @author Joel Bout, <joel.bout@tudor.lu> |
| 46 | */ |
| 47 | public function feed() |
| 48 | { |
| 49 | if (isset($_FILES[$this->getName()])) { |
| 50 | $this->setValue($_FILES[$this->getName()]); |
| 51 | } else { |
| 52 | throw new tao_helpers_form_Exception('cannot evaluate the element ' . __CLASS__); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Short description of method render |
| 58 | * |
| 59 | * @access public |
| 60 | * @author Joel Bout, <joel.bout@tudor.lu> |
| 61 | * @return string |
| 62 | */ |
| 63 | public function render() |
| 64 | { |
| 65 | if (! empty($this->value)) { |
| 66 | if (common_Utils::isUri($this->value)) { |
| 67 | $referencer = $this->getServiceLocator()->get(FileReferenceSerializer::SERVICE_ID); |
| 68 | /** @var File $file */ |
| 69 | $file = $referencer->unserialize($this->value); |
| 70 | if (!$file->exists()) { |
| 71 | $referencer->cleanup($this->value); |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | $returnValue = $this->renderLabel(); |
| 77 | $returnValue .= "<input type='hidden' name='MAX_FILE_SIZE' value='" |
| 78 | . tao_helpers_form_elements_File::MAX_FILE_SIZE . "' />"; |
| 79 | $returnValue .= "<input type='file' name='{$this->name}' id='{$this->name}' " |
| 80 | . "data-testid='{$this->getDescription()}' "; |
| 81 | $returnValue .= $this->renderAttributes(); |
| 82 | $returnValue .= " value='{$this->value}' />"; |
| 83 | |
| 84 | return (string) $returnValue; |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Short description of method getEvaluatedValue |
| 89 | * |
| 90 | * @access public |
| 91 | * @author Joel Bout, <joel.bout@tudor.lu> |
| 92 | * @return mixed |
| 93 | */ |
| 94 | public function getEvaluatedValue() |
| 95 | { |
| 96 | return $this->getRawValue(); |
| 97 | } |
| 98 | |
| 99 | public function getServiceLocator() |
| 100 | { |
| 101 | return ServiceManager::getServiceManager(); |
| 102 | } |
| 103 | } |