Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 29 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| TestRunnerFeatureWidget | |
0.00% |
0 / 29 |
|
0.00% |
0 / 2 |
56 | |
0.00% |
0 / 1 |
| feed | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 | |||
| render | |
0.00% |
0 / 23 |
|
0.00% |
0 / 1 |
20 | |||
| 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 | * @author Christophe Noël <christophe@taotesting.com> |
| 21 | */ |
| 22 | |
| 23 | namespace oat\taoDeliveryRdf\helper; |
| 24 | |
| 25 | use common_ext_ExtensionsManager; |
| 26 | use oat\oatbox\service\ServiceManager; |
| 27 | use oat\taoTests\models\runner\features\TestRunnerFeatureService; |
| 28 | use tao_helpers_form_FormElement; |
| 29 | use taoItems_models_classes_TemplateRenderer; |
| 30 | |
| 31 | /** |
| 32 | * Allow the selection of the Test Runner Features wanted for a specific delivery |
| 33 | */ |
| 34 | class TestRunnerFeatureWidget extends tao_helpers_form_FormElement |
| 35 | { |
| 36 | public const WIDGET_ID = 'http://www.tao.lu/datatypes/WidgetDefinitions.rdf#DeliveryTestRunnerFeature'; |
| 37 | |
| 38 | private const WIDGET_TPL = 'views/templates/widgets/testRunnerFeature.tpl.php'; |
| 39 | |
| 40 | /** |
| 41 | * Data is stored as a coma-separated list of active test runner features ids |
| 42 | * ex: progressBar,accessibility,security |
| 43 | */ |
| 44 | public function feed() |
| 45 | { |
| 46 | $activeFeatures = []; |
| 47 | |
| 48 | $expression = "/^" . preg_quote($this->name, "/") . "(.)*[0-9]+$/"; |
| 49 | foreach ($_POST as $key => $value) { |
| 50 | if (preg_match($expression, $key)) { |
| 51 | $activeFeatures[] = $value; |
| 52 | } |
| 53 | } |
| 54 | $this->setValue(implode(',', $activeFeatures)); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Render the Widget to allow Test Runner Features selection |
| 59 | * |
| 60 | * @return string |
| 61 | */ |
| 62 | public function render() |
| 63 | { |
| 64 | $serviceManager = ServiceManager::getServiceManager(); |
| 65 | $testRunnerFeatureService = $serviceManager->get(TestRunnerFeatureService::SERVICE_ID); |
| 66 | |
| 67 | $allFeatures = $testRunnerFeatureService->getAll(); |
| 68 | |
| 69 | $activeFeatures = explode(',', $this->value); |
| 70 | |
| 71 | $choicesList = []; |
| 72 | $i = 0; |
| 73 | |
| 74 | if (count($allFeatures) > 0) { |
| 75 | foreach ($allFeatures as $feature) { |
| 76 | $choicesList[] = [ |
| 77 | "title" => $feature->getDescription(), |
| 78 | "value" => $feature->getId(), |
| 79 | "id" => $this->name . "_" . $i, |
| 80 | "checked" => (in_array($feature->getId(), $activeFeatures)) ? ' checked="checked" ' : '', |
| 81 | "label" => _dh($feature->getLabel()) |
| 82 | ]; |
| 83 | $i++; |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | $tpl = common_ext_ExtensionsManager::singleton()->getExtensionById('taoDeliveryRdf')->getDir() |
| 88 | . self::WIDGET_TPL ; |
| 89 | $templateRenderer = new taoItems_models_classes_TemplateRenderer($tpl, [ |
| 90 | 'propLabel' => _dh($this->getDescription()), |
| 91 | 'choicesList' => $choicesList |
| 92 | ]); |
| 93 | |
| 94 | return $templateRenderer->render(); |
| 95 | } |
| 96 | } |