Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 20 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| taoQtiTest_models_classes_QtiTestCompilationFailedException | |
0.00% |
0 / 20 |
|
0.00% |
0 / 4 |
90 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| getTest | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setTest | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getUserMessage | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
42 | |||
| 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) 2013 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | /** |
| 24 | * The User Readable exception to be used when an error occurs |
| 25 | * at QTI Test compilation-time. |
| 26 | * |
| 27 | * @author Jérôme Bogaerts <jerome@taotesting.com> |
| 28 | * @package taoQtiTest |
| 29 | * |
| 30 | * phpcs:disable Generic.Files.LineLength |
| 31 | */ |
| 32 | class taoQtiTest_models_classes_QtiTestCompilationFailedException extends tao_models_classes_CompilationFailedException implements |
| 33 | common_exception_UserReadableException |
| 34 | { |
| 35 | // phpcs:enable Generic.Files.LineLength |
| 36 | |
| 37 | /** |
| 38 | * Error code to use when the error is unknown. |
| 39 | * |
| 40 | * @var integer |
| 41 | */ |
| 42 | public const UNKNOWN = 0; |
| 43 | |
| 44 | /** |
| 45 | * Error code to use when no items are composing |
| 46 | * the test to be compiled. |
| 47 | * |
| 48 | * @var integer |
| 49 | */ |
| 50 | public const NO_ITEMS = 1; |
| 51 | |
| 52 | /** |
| 53 | * Error code to use when a remote resource (e.g. image |
| 54 | * referenced with absolute URL) cannot be retrieved. |
| 55 | * |
| 56 | * @var integer |
| 57 | */ |
| 58 | public const REMOTE_RESOURCE = 2; |
| 59 | |
| 60 | /** |
| 61 | * Error code to use when a dependent item failed to |
| 62 | * be compiled. |
| 63 | * |
| 64 | * @var integer |
| 65 | */ |
| 66 | public const ITEM_COMPILATION = 3; |
| 67 | |
| 68 | /** |
| 69 | * The resource in database describing the test that failed |
| 70 | * to be compiled. |
| 71 | * |
| 72 | * @var core_kernel_classes_Resource |
| 73 | */ |
| 74 | private $test; |
| 75 | |
| 76 | /** |
| 77 | * Create a new QtiTestCompilationFailedException object. |
| 78 | * |
| 79 | * @param string $message A technical message to developers. |
| 80 | * @param core_kernel_classes_Resource A Resource object in database describing the test that failed to compiled. |
| 81 | * @param integer $code A code to explicitely identify the nature of the error. |
| 82 | */ |
| 83 | public function __construct($message, core_kernel_classes_Resource $test, $code = 0) |
| 84 | { |
| 85 | parent::__construct($message, $code); |
| 86 | $this->setTest($test); |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Get the resource in database describing the test that failed to |
| 91 | * be compiled. |
| 92 | * |
| 93 | * @return core_kernel_classes_Resource A core_kernel_classes_Resource object. |
| 94 | */ |
| 95 | protected function getTest() |
| 96 | { |
| 97 | return $this->test; |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Set the resource in database describing the test that failed |
| 102 | * to be compiled. |
| 103 | * |
| 104 | * @param core_kernel_classes_Resource $test a core_kernel_classes_Resource object. |
| 105 | */ |
| 106 | protected function setTest(core_kernel_classes_Resource $test) |
| 107 | { |
| 108 | $this->test = $test; |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Returns a translated human-readable message destinated to the end-user. The content |
| 113 | * of the message will depend on the $code given at instantiation-time. |
| 114 | * |
| 115 | * @return string A human-readable message. |
| 116 | */ |
| 117 | public function getUserMessage() |
| 118 | { |
| 119 | $testLabel = $this->getTest()->getLabel(); |
| 120 | |
| 121 | switch ($this->getCode()) { |
| 122 | case self::UNKNOWN: |
| 123 | return sprintf(__("An unknown error occured while compiled QTI Test '%s'."), $testLabel); |
| 124 | break; |
| 125 | |
| 126 | case self::NO_ITEMS: |
| 127 | // phpcs:disable Generic.Files.LineLength |
| 128 | return sprintf(__("The QTI Test '%s' to be compiled must contain at least 1 QTI Item. None found."), $testLabel); |
| 129 | // phpcs:enable Generic.Files.LineLength |
| 130 | break; |
| 131 | |
| 132 | case self::REMOTE_RESOURCE: |
| 133 | return sprintf(__("A remote resource referenced in QTI test '%s' could not be retrieved.", $testLabel)); |
| 134 | break; |
| 135 | |
| 136 | case self::ITEM_COMPILATION: |
| 137 | return sprintf(__("A QTI Item involved in the QTI Test '%s' could not be compiled.", $testLabel)); |
| 138 | break; |
| 139 | |
| 140 | default: |
| 141 | return sprintf(__("An unknown error occured while compiling QTI test '%s'."), $testLabel); |
| 142 | break; |
| 143 | } |
| 144 | } |
| 145 | } |