Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 16 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| TestCategoryRulesService | |
0.00% |
0 / 16 |
|
0.00% |
0 / 4 |
56 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
20 | |||
| setGenerator | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getGenerator | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| apply | |
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) 2016 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\taoQtiTest\models; |
| 23 | |
| 24 | use oat\oatbox\service\ConfigurableService; |
| 25 | use qtism\data\AssessmentTest; |
| 26 | |
| 27 | /** |
| 28 | * The TestCategoryRulesService service implementation. |
| 29 | * |
| 30 | * This service acts as a wrapper for the TestCategoryRulesGenerator class. The category |
| 31 | * rules generation process is triggered using the TestCategoryRulesService::apply() method. |
| 32 | * |
| 33 | * @see oat\taoQtiTest\models\TestCategoryRulesGenerator class for a in-depth documentation of the category-based rule |
| 34 | * generation process. |
| 35 | */ |
| 36 | class TestCategoryRulesService extends ConfigurableService |
| 37 | { |
| 38 | public const SERVICE_ID = 'taoQtiTest/TestCategoryRules'; |
| 39 | |
| 40 | private $generator; |
| 41 | |
| 42 | /** |
| 43 | * Create a new TestCategoryRulesService instance. |
| 44 | * |
| 45 | * This constructor allows you to instantiate a new TestCategoryRulesService object with the following options |
| 46 | * available: |
| 47 | * |
| 48 | * * 'score-variable-identifier' (string) : The identifier of the item session outcome variable to be used when |
| 49 | * generating <testVariables> based rules. |
| 50 | * * 'weight-identifier' (string) : The identifier of the item reference weight to be used when generating |
| 51 | * <testVariables> based rules. |
| 52 | * * 'category-exclusions' (array) : An array of PCREs describing what are the categories to be excluded from the |
| 53 | * rule generation process. |
| 54 | * * 'flags' (integer) : A binary flags configuration of the rule generation process composed by values described |
| 55 | * by the TestCategoryRulesGenerator class constants. |
| 56 | * |
| 57 | * @param array $options (optional) An optional array of options. |
| 58 | */ |
| 59 | public function __construct(array $options = []) |
| 60 | { |
| 61 | parent::__construct($options); |
| 62 | |
| 63 | $generator = new TestCategoryRulesGenerator(); |
| 64 | $generator->setScoreVariableIdentifier( |
| 65 | empty($options['score-variable-identifier']) ? 'SCORE' : (string) $options['score-variable-identifier'] |
| 66 | ); |
| 67 | $generator->setWeightIdentifier( |
| 68 | array_key_exists('weight-identifier', $options) ? (string) $options['weight-identifier'] : '' |
| 69 | ); |
| 70 | $generator->setCategoryExclusions( |
| 71 | empty($options['category-exclusions']) ? [] : $options['category-exclusions'] |
| 72 | ); |
| 73 | $this->setGenerator($generator); |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Set the generator. |
| 78 | * |
| 79 | * Set the TestCategoryRulesGenerator object to be used by the service. |
| 80 | * |
| 81 | * @param oat\taoQtiTest\models\TestCategoryRulesGenerator $generator A TestCategoryRulesGenerator object. |
| 82 | */ |
| 83 | protected function setGenerator(TestCategoryRulesGenerator $generator) |
| 84 | { |
| 85 | $this->generator = $generator; |
| 86 | } |
| 87 | |
| 88 | |
| 89 | /** |
| 90 | * Get the generator. |
| 91 | * |
| 92 | * Get the TestCategoryRulesGenerator object to be used by the service. |
| 93 | * |
| 94 | * @return oat\taoQtiTest\models\TestCategoryRulesGenerator A TestCategoryRulesGenerator object. |
| 95 | */ |
| 96 | protected function getGenerator() |
| 97 | { |
| 98 | return $this->generator; |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Apply the category based rule generation process on a given Assessment Test. |
| 103 | * |
| 104 | * Calling this method will trigger the category based rule generation process on the given |
| 105 | * AssessmentTest $test object, depending on the $options parameters provided to the constructor |
| 106 | * of the service. |
| 107 | * |
| 108 | * @param qtism\data\AssessmentTest $test A QTI-SDK AssessmentTest object. |
| 109 | */ |
| 110 | public function apply(AssessmentTest $test) |
| 111 | { |
| 112 | $this->getGenerator()->apply($test, (int) $this->getOption('flags')); |
| 113 | } |
| 114 | } |