Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
27.78% |
5 / 18 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| tao_helpers_form_validators_FileSize | |
27.78% |
5 / 18 |
|
0.00% |
0 / 2 |
39.51 | |
0.00% |
0 / 1 |
| setOptions | |
50.00% |
5 / 10 |
|
0.00% |
0 / 1 |
6.00 | |||
| evaluate | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
30 | |||
| 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 | /** |
| 26 | * Short description of class tao_helpers_form_validators_FileSize |
| 27 | * |
| 28 | * @access public |
| 29 | * @author Joel Bout, <joel.bout@tudor.lu> |
| 30 | * @package tao |
| 31 | |
| 32 | */ |
| 33 | class tao_helpers_form_validators_FileSize extends tao_helpers_form_Validator |
| 34 | { |
| 35 | // --- ASSOCIATIONS --- |
| 36 | |
| 37 | |
| 38 | // --- ATTRIBUTES --- |
| 39 | |
| 40 | // --- OPERATIONS --- |
| 41 | public function setOptions(array $options) |
| 42 | { |
| 43 | parent::setOptions($options); |
| 44 | |
| 45 | if ($this->hasOption('min') && $this->hasOption('max')) { |
| 46 | $this->setMessage( |
| 47 | // phpcs:disable Generic.Files.LineLength |
| 48 | __('Invalid file size (minimum %1$s bytes, maximum %2$s bytes)', $this->getOption('min'), $this->getOption('max')) |
| 49 | // phpcs:enable Generic.Files.LineLength |
| 50 | ); |
| 51 | } elseif ($this->hasOption('max')) { |
| 52 | $this->setMessage(__('The uploaded file is too large (maximum %s bytes)', $this->getOption('max'))); |
| 53 | $this->setOption('min', 0); |
| 54 | } else { |
| 55 | throw new common_Exception("Please set 'min' and/or 'max' options!"); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | |
| 60 | /** |
| 61 | * Short description of method evaluate |
| 62 | * |
| 63 | * @access public |
| 64 | * @author Joel Bout, <joel.bout@tudor.lu> |
| 65 | * @param values |
| 66 | * @return boolean |
| 67 | */ |
| 68 | public function evaluate($values) |
| 69 | { |
| 70 | $returnValue = (bool) false; |
| 71 | |
| 72 | |
| 73 | |
| 74 | if (is_array($values)) { |
| 75 | if (isset($values['size'])) { |
| 76 | if ($values['size'] >= $this->getOption('min') && $values['size'] <= $this->getOption('max')) { |
| 77 | $returnValue = true; |
| 78 | } |
| 79 | } else { |
| 80 | $returnValue = true; |
| 81 | } |
| 82 | } else { |
| 83 | $returnValue = true; |
| 84 | } |
| 85 | |
| 86 | |
| 87 | |
| 88 | return (bool) $returnValue; |
| 89 | } |
| 90 | } |