*/ namespace oat\taoDeliveryRdf\helper; use common_ext_ExtensionsManager; use oat\oatbox\service\ServiceManager; use oat\taoTests\models\runner\features\TestRunnerFeatureService; use tao_helpers_form_FormElement; use taoItems_models_classes_TemplateRenderer; /** * Allow the selection of the Test Runner Features wanted for a specific delivery */ class TestRunnerFeatureWidget extends tao_helpers_form_FormElement { public const WIDGET_ID = 'http://www.tao.lu/datatypes/WidgetDefinitions.rdf#DeliveryTestRunnerFeature'; private const WIDGET_TPL = 'views/templates/widgets/testRunnerFeature.tpl.php'; /** * Data is stored as a coma-separated list of active test runner features ids * ex: progressBar,accessibility,security */ public function feed() { $activeFeatures = []; $expression = "/^" . preg_quote($this->name, "/") . "(.)*[0-9]+$/"; foreach ($_POST as $key => $value) { if (preg_match($expression, $key)) { $activeFeatures[] = $value; } } $this->setValue(implode(',', $activeFeatures)); } /** * Render the Widget to allow Test Runner Features selection * * @return string */ public function render() { $serviceManager = ServiceManager::getServiceManager(); $testRunnerFeatureService = $serviceManager->get(TestRunnerFeatureService::SERVICE_ID); $allFeatures = $testRunnerFeatureService->getAll(); $activeFeatures = explode(',', $this->value); $choicesList = []; $i = 0; if (count($allFeatures) > 0) { foreach ($allFeatures as $feature) { $choicesList[] = [ "title" => $feature->getDescription(), "value" => $feature->getId(), "id" => $this->name . "_" . $i, "checked" => (in_array($feature->getId(), $activeFeatures)) ? ' checked="checked" ' : '', "label" => _dh($feature->getLabel()) ]; $i++; } } $tpl = common_ext_ExtensionsManager::singleton()->getExtensionById('taoDeliveryRdf')->getDir() . self::WIDGET_TPL ; $templateRenderer = new taoItems_models_classes_TemplateRenderer($tpl, [ 'propLabel' => _dh($this->getDescription()), 'choicesList' => $choicesList ]); return $templateRenderer->render(); } }