protected function renderManifest(array $options, array $qtiItemData) { $dir = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiItem')->getDir(); $tpl = $dir . 'model/qti/templates/imsmanifestQti22.tpl.php'; $templateRenderer = new \taoItems_models_classes_TemplateRenderer($tpl, array('qtiItems' => array($qtiItemData), 'manifestIdentifier' => 'MANIFEST-' . \tao_helpers_Display::textCleaner(uniqid('tao', true), '-'))); $renderedManifest = $templateRenderer->render(); $newManifest = new \DOMDocument('1.0', TAO_DEFAULT_ENCODING); $newManifest->loadXML($renderedManifest); return $newManifest; }
/** * Returns html for property * @param $property * @return string */ protected function getGroupTitle($property) { if ($this->isParentProperty()) { foreach ($property->getDomain()->getIterator() as $domain) { $domainLabel[] = $domain->getLabel(); } $groupTitle = '<span class="property-heading-label">' . _dh($property->getLabel()) . '</span>' . '<span class="property-heading-toolbar">' . _dh(implode(' ', $domainLabel)) . ' <span class="icon-edit"></span>' . '</span>'; } else { $groupTitle = '<span class="property-heading-label">' . _dh($property->getLabel()) . '</span>' . '<span class="property-heading-toolbar">' . '<span class="icon-edit"></span>' . '<span class="icon-bin property-deleter" data-uri=\'' . tao_helpers_Display::encodeAttrValue($property->getUri()) . '\'></span>' . '</span>'; } return $groupTitle; }
/** * overriden * * @access public * @author Joel Bout, <*****@*****.**> * @return mixed */ public function initElements() { $testService = taoTests_models_classes_TestsService::singleton(); $testModel = new core_kernel_classes_Resource(INSTANCE_TEST_MODEL_QTI); $fileName = ''; $options = array(); if (isset($this->data['instance'])) { $test = $this->data['instance']; if ($test instanceof core_kernel_classes_Resource) { if ($testModel->equals($testService->getTestModel($test))) { $fileName = strtolower(tao_helpers_Display::textCleaner($test->getLabel())); $options[$test->getUri()] = $test->getLabel(); } } } else { if (isset($this->data['class'])) { $class = $this->data['class']; } else { $class = $itemService->getRootClass(); } if ($class instanceof core_kernel_classes_Class) { $fileName = strtolower(tao_helpers_Display::textCleaner($class->getLabel(), '*')); foreach ($class->getInstances() as $instance) { if ($testModel->equals($testService->getTestModel($instance))) { $options[$instance->getUri()] = $instance->getLabel(); } } } } $nameElt = tao_helpers_form_FormFactory::getElement('filename', 'Textbox'); $nameElt->setDescription(__('File name')); $nameElt->setValue($fileName); $nameElt->setUnit(".zip"); $nameElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty')); $this->form->addElement($nameElt); $instanceElt = tao_helpers_form_FormFactory::getElement('instances', 'Checkbox'); $instanceElt->setDescription(__('Test')); //$instanceElt->setAttribute('checkAll', true); $instanceElt->setOptions(tao_helpers_Uri::encodeArray($options, tao_helpers_Uri::ENCODE_ARRAY_KEYS)); foreach (array_keys($options) as $value) { $instanceElt->setValue($value); } $this->form->addElement($instanceElt); $this->form->createGroup('options', __('Export QTI 2.1 Test Package'), array('filename', 'instances')); }
/** * Rendering of the XHTML implementation of the Calendar Widget. * * @author Bertrand Chevrier, <*****@*****.**> * @return The XHTML stream of the Calendar Widget. */ public function render() { $returnValue = $this->renderLabel(); $uniqueId = uniqid('calendar_'); $elementId = tao_helpers_Display::TextCleaner($this->getDescription()) . '_' . $uniqueId; if (!isset($this->attributes['size'])) { $this->attributes['size'] = 20; } $returnValue .= "<input class='datepicker-input' type='text' name='{$this->name}' id='{$elementId}' "; $returnValue .= $this->renderAttributes(); if (!empty($this->value)) { $timeStamp = is_numeric($this->getRawValue()) ? $this->getRawValue() : $this->getEvaluatedValue(); $returnValue .= ' value="' . _dh(tao_helpers_Date::displayeDate($timeStamp, tao_helpers_Date::FORMAT_DATEPICKER)) . '"'; } $returnValue .= ' />'; $returnValue .= "<script type=\"text/javascript\">\n\t\t\trequire(['jquery','jqueryui','jquery.timePicker'], function(\$){\n\t\t\t\t\$(\"#{$elementId}\").datetimepicker({\n dateFormat: 'yy-mm-dd',\n beforeShow: function (textbox, instance) {\n \$(textbox).parent().append(instance.dpDiv);\n }\n\t\t\t\t});\n \n\t\t\t});</script>"; return (string) $returnValue; }
public function initElements() { if (isset($this->data['resource'])) { $resource = $this->data['resource']; } else { throw new \common_Exception('No class nor instance specified for export'); } $fileName = strtolower(\tao_helpers_Display::textCleaner($resource->getLabel(), '*')); $hiddenElt = \tao_helpers_form_FormFactory::getElement('resource', 'Hidden'); $hiddenElt->setValue($resource->getUri()); $this->form->addElement($hiddenElt); $nameElt = \tao_helpers_form_FormFactory::getElement('filename', 'Textbox'); $nameElt->setDescription(__('File name')); $nameElt->addValidator(\tao_helpers_form_FormFactory::getValidator('NotEmpty')); $nameElt->setValue($fileName); $nameElt->setUnit(".zip"); $this->form->addElement($nameElt); $this->form->createGroup('options', __('Export Media as Zip file'), array('filename', 'ziptpl')); }
/** * export a compiled delivery into an archive * * @param core_kernel_classes_Resource $compiledDelivery * @throws Exception * @return string */ public static function exportCompiledDelivery(core_kernel_classes_Resource $compiledDelivery) { $fileName = tao_helpers_Display::textCleaner($compiledDelivery->getLabel()) . '.zip'; $path = tao_helpers_File::concat(array(tao_helpers_Export::getExportPath(), $fileName)); if (!tao_helpers_File::securityCheck($path, true)) { throw new Exception('Unauthorized file name'); } $zipArchive = new ZipArchive(); if ($zipArchive->open($path, ZipArchive::CREATE) !== true) { throw new Exception('Unable to create archive at ' . $path); } $taoDeliveryVersion = common_ext_ExtensionsManager::singleton()->getInstalledVersion('taoDelivery'); $data = array('dir' => array(), 'label' => $compiledDelivery->getLabel(), 'version' => $taoDeliveryVersion); $directories = $compiledDelivery->getPropertyValues(new core_kernel_classes_Property(PROPERTY_COMPILEDDELIVERY_DIRECTORY)); foreach ($directories as $id) { $directory = tao_models_classes_service_FileStorage::singleton()->getDirectoryById($id); tao_helpers_File::addFilesToZip($zipArchive, $directory->getPath(), $directory->getRelativePath()); $data['dir'][$id] = $directory->getRelativePath(); } $runtime = $compiledDelivery->getUniquePropertyValue(new core_kernel_classes_Property(PROPERTY_COMPILEDDELIVERY_RUNTIME)); $serviceCall = tao_models_classes_service_ServiceCall::fromResource($runtime); $data['runtime'] = base64_encode($serviceCall->serializeToString()); $rdfExporter = new tao_models_classes_export_RdfExporter(); $rdfdata = $rdfExporter->getRdfString(array($compiledDelivery)); if (!$zipArchive->addFromString('delivery.rdf', $rdfdata)) { throw common_Exception('Unable to add metadata to exported delivery assembly'); } $data['meta'] = 'delivery.rdf'; $content = json_encode($data); //'<?php return '.common_Utils::toPHPVariableString($data).";"; if (!$zipArchive->addFromString(self::MANIFEST_FILE, $content)) { $zipArchive->close(); unlink($path); throw common_Exception('Unable to add manifest to exported delivery assembly'); } $zipArchive->close(); return $path; }
/** * overriden * * @access public * @author Joel Bout, <*****@*****.**> * @return mixed */ public function initElements() { $fileName = ''; $instances = array(); if (isset($this->data['instance'])) { $resource = $this->data['instance']; } elseif (isset($this->data['class'])) { $resource = $this->data['class']; } else { throw new common_Exception('No class nor instance specified for export'); } $fileName = strtolower(tao_helpers_Display::textCleaner($resource->getLabel(), '*')); $hiddenElt = tao_helpers_form_FormFactory::getElement('resource', 'Hidden'); $hiddenElt->setValue($resource->getUri()); $this->form->addElement($hiddenElt); $nameElt = tao_helpers_form_FormFactory::getElement('filename', 'Textbox'); $nameElt->setDescription(__('File name')); $nameElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty')); $nameElt->setValue($fileName); $nameElt->setUnit(".rdf"); $this->form->addElement($nameElt); $instances = tao_helpers_Uri::encodeArray($instances, tao_helpers_Uri::ENCODE_ARRAY_KEYS); $this->form->createGroup('options', __('Export Metadata as RDF/XML file'), array('rdf_desc', 'filename', 'rdftpl')); }
/** * Short description of method toTree * * @access public * @author Jerome Bogaerts, <*****@*****.**> * @param Class clazz * @param array options * @return array */ public function toTree(core_kernel_classes_Class $clazz, $options) { $returnValue = array(); $users = $this->getAllUsers(array('order' => PROPERTY_USER_LOGIN)); foreach ($users as $user) { $login = (string) $user->getOnePropertyValue(new core_kernel_classes_Property(PROPERTY_USER_LOGIN)); $returnValue[] = array('data' => tao_helpers_Display::textCutter($login, 16), 'attributes' => array('id' => tao_helpers_Uri::encode($user->getUri()), 'class' => 'node-instance')); } return (array) $returnValue; }
/** * Try to get the action's icon the old way. * I/O impact (file_exists) is limited as the results can be serialized. * * @return Icon the icon with the src property set to the icon URL. */ private function inferLegacyIcon() { $ext = $this->getExtensionId(); $name = strtolower(\tao_helpers_Display::textCleaner($this->data['name'])); $file = $ext . '/views/img/actions/' . $name . '.png'; $src = 'actions/' . $name . '.png'; if (file_exists(ROOT_PATH . $file)) { return Icon::fromArray(array('src' => $src), $ext); } else { if (file_exists(ROOT_PATH . 'tao/views/img/actions/' . $name . '.png')) { return Icon::fromArray(array('src' => $src), 'tao'); } else { return Icon::fromArray(array('src' => 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAAAAAA6fptVAAAAAnRSTlMA/1uRIrUAAAAKSURBVHjaY/gPAAEBAQAcsIyZAAAAAElFTkSuQmCC'), 'tao'); } } }
/** * Create the defautl content directory of a QTI test. * * @param core_kernel_classes_Resource $test * @param boolean $createTestFile Whether or not create an empty QTI XML test file. Default is (boolean) true. * @return core_kernel_file_File the content file * @throws taoQtiTest_models_classes_QtiTestServiceException If a runtime error occurs while creating the test content. */ public function createContent(core_kernel_classes_Resource $test, $createTestFile = true) { $props = self::getQtiTestDirectory()->getPropertiesValues(array(PROPERTY_FILE_FILESYSTEM, PROPERTY_FILE_FILEPATH)); $repository = new core_kernel_versioning_Repository(current($props[PROPERTY_FILE_FILESYSTEM])); $path = (string) current($props[PROPERTY_FILE_FILEPATH]); // $directory is the directory where test related resources will be stored. $directory = $repository->createFile('', $path . DIRECTORY_SEPARATOR . md5($test->getUri()) . DIRECTORY_SEPARATOR); $dirPath = $directory->getAbsolutePath() . DIRECTORY_SEPARATOR; if (!file_exists($dirPath)) { mkdir($dirPath, 0770, true); } if ($createTestFile === true) { $emptyTestXml = $this->getQtiTestTemplateFileAsString(); $doc = new DOMDocument(); $doc->loadXML($emptyTestXml); // Set the test label as title. $doc->documentElement->setAttribute('title', $test->getLabel()); //generate a valid qti identifier $identifier = tao_helpers_Display::textCleaner($test->getLabel(), '*', 32); $identifier = str_replace('_', '-', $identifier); if (preg_match('/^[0-9]/', $identifier)) { $identifier = '_' . $identifier; } $doc->documentElement->setAttribute('identifier', $identifier); $doc->documentElement->setAttribute('toolVersion', TAO_VERSION); $filePath = $dirPath . TAOQTITEST_FILENAME; if ($doc->save($filePath) === false) { $msg = "Unable to write raw QTI Test template at location '{$filePath}'."; throw new taoQtiTest_models_classes_QtiTestServiceException($msg, taoQtiTest_models_classes_QtiTestServiceException::TEST_WRITE_ERROR); } common_Logger::i("Created QTI Test content at location '" . $filePath . "'."); } $test->editPropertyValues(new core_kernel_classes_Property(TEST_TESTCONTENT_PROP), $directory); return $directory; }
/** * Short description of method initCSVElements * * @access protected * @author Bertrand Chevrier, <*****@*****.**> * @return mixed */ protected function initCSVElements() { $adapter = new tao_helpers_data_GenerisAdapterCsv(); $options = $adapter->getOptions(); //create import options form foreach ($options as $optName => $optValue) { is_bool($optValue) ? $eltType = 'Checkbox' : ($eltType = 'Textbox'); $optElt = tao_helpers_form_FormFactory::getElement($optName, $eltType); $optElt->setDescription(tao_helpers_Display::textCleaner($optName, ' ')); $optElt->setValue(addslashes($optValue)); $optElt->addAttribute("size", $optName == 'column_order' ? 40 : 6); if (is_null($optValue) || $optName == 'line_break') { $optElt->addAttribute("disabled", "true"); } $optElt->setValue($optValue); if ($eltType == 'Checkbox') { $optElt->setOptions(array($optName => '')); $optElt->setValue($optName); } if (!preg_match("/column/", strtolower($optName))) { $optElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty')); } $this->form->addElement($optElt); } $this->form->createGroup('options', __('CSV Options'), array_keys($options)); $descElt = tao_helpers_form_FormFactory::getElement('csv_desc', 'Label'); $descElt->setValue(__("Please upload a CSV file formated as \"defined\" %min by %max the options above.")); $this->form->addElement($descElt); //create file upload form box $fileElt = tao_helpers_form_FormFactory::getElement('source', 'AsyncFile'); $fileElt->setDescription(__("Add the source file")); if (isset($_POST['import_sent_csv'])) { $fileElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty')); } else { $fileElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty', array('message' => ''))); } $fileElt->addValidators(array(tao_helpers_form_FormFactory::getValidator('FileMimeType', array('mimetype' => array('text/plain', 'text/csv', 'text/comma-separated-values', 'application/csv', 'application/csv-tab-delimited-table'), 'extension' => array('csv', 'txt'))), tao_helpers_form_FormFactory::getValidator('FileSize', array('max' => self::UPLOAD_MAX)))); $this->form->addElement($fileElt); $this->form->createGroup('file', __('Upload CSV File'), array('csv_desc', 'source')); $csvSentElt = tao_helpers_form_FormFactory::getElement('import_sent_csv', 'Hidden'); $csvSentElt->setValue(1); $this->form->addElement($csvSentElt); }
/** * Get property values for a sub set of filtered instances * @param {RequestParameter|string} propertyUri Uri of the target property * @param {RequestParameter|string} classUri Uri of the target class * @param {RequestParameter|array} filter Array of propertyUri/propertyValue used to filter instances of the target class * @param {RequestParameter|array} filterNodesOptions Array of options used by other filter nodes * @return {array} formated for tree */ public function getFilteredInstancesPropertiesValues() { $data = array(); // The filter nodes options $filterNodesOptions = array(); // The filter $filter = array(); // Filter itself ? $filterItself = $this->hasRequestParameter('filterItself') ? $this->getRequestParameter('filterItself') == 'false' ? false : true : false; if (!tao_helpers_Request::isAjax()) { throw new Exception("wrong request mode"); } // Get the target property if ($this->hasRequestParameter('propertyUri')) { $propertyUri = $this->getRequestParameter('propertyUri'); } else { $propertyUri = RDFS_LABEL; } $property = new core_kernel_classes_Property($propertyUri); // Get the class paramater if ($this->hasRequestParameter('classUri')) { $clazz = $this->getCurrentClass(); } else { $clazz = $this->getRootClass(); } // Get filter nodes parameters if ($this->hasRequestParameter('filterNodesOptions')) { $filterNodesOptions = $this->getRequestParameter('filterNodesOptions'); } // Get filter parameter if ($this->hasRequestParameter('filter')) { $filter = $this->getFilterState('filter'); } // Get used property values for a class functions of the given filter $propertyValues = $clazz->getInstancesPropertyValues($property, $filter, array("distinct" => true, "recursive" => true)); $propertyValuesFormated = array(); foreach ($propertyValues as $propertyValue) { $value = ""; $id = ""; if ($propertyValue instanceof core_kernel_classes_Resource) { $value = $propertyValue->getLabel(); $id = tao_helpers_Uri::encode($propertyValue->getUri()); } else { $value = (string) $propertyValue; $id = $value; } $propertyValueFormated = array('data' => $value, 'type' => 'instance', 'attributes' => array('id' => $id, 'class' => 'node-instance')); $propertyValuesFormated[] = $propertyValueFormated; } $data = array('data' => $this->hasRequestParameter('rootNodeName') ? $this->getRequestParameter('rootNodeName') : tao_helpers_Display::textCutter($property->getLabel(), 16), 'type' => 'class', 'count' => count($propertyValuesFormated), 'attributes' => array('id' => tao_helpers_Uri::encode($property->getUri()), 'class' => 'node-class'), 'children' => $propertyValuesFormated); echo json_encode($data); }
public static function elementMap(core_kernel_classes_Property $property, $displayCode = false) { $returnValue = null; //create the element from the right widget $widgetResource = $property->getWidget(); if (is_null($widgetResource)) { return null; } $widget = ucfirst(strtolower(substr($widgetResource->getUri(), strrpos($widgetResource->getUri(), '#') + 1))); $element = tao_helpers_form_FormFactory::getElementByWidget(tao_helpers_Uri::encode($property->getUri()), $widgetResource); if (!is_null($element)) { if ($element->getWidget() != $widgetResource->getUri()) { return null; } //use the property label as element description strlen(trim($property->getLabel())) > 0 ? $propDesc = tao_helpers_Display::textCleaner($property->getLabel(), ' ') : ($propDesc = 'field ' . (count($myForm->getElements()) + 1)); $element->setDescription($propDesc); //multi elements use the property range as options if (method_exists($element, 'setOptions')) { $range = $property->getRange(); if ($range != null) { $options = array(); foreach ($range->getInstances(true) as $rangeInstance) { $value = $rangeInstance->getLabel(); if ($displayCode) { //get the code of the process variable: $code = $rangeInstance->getOnePropertyValue(new core_kernel_classes_Property(PROPERTY_PROCESSVARIABLES_CODE)); if (!empty($code) && $code instanceof core_kernel_classes_Literal) { $value .= " (code:{$code->literal})"; } } $options[tao_helpers_Uri::encode($rangeInstance->getUri())] = $value; } //set the default value to an empty space if (method_exists($element, 'setEmptyOption')) { $element->setEmptyOption(' '); } //complete the options listing $element->setOptions($options); } } $returnValue = $element; } return $returnValue; }
/** * Build the script tag * @param array $attributes key/val to create tag's attributes * * @return the generated script tag */ private function buildScriptTag($attributes) { $amdScript = '<script id="' . self::LOADER_ID . '" '; foreach ($attributes as $attr => $value) { $amdScript .= $attr . '="' . \tao_helpers_Display::htmlize($value) . '" '; } return trim($amdScript) . '></script>'; }
/** * Test {@link tao_helpers_Display::} * @dataProvider stringToCleanProvider */ public function testCleaner($input, $joker, $maxLength, $output) { $this->assertEquals(tao_helpers_Display::textCleaner($input, $joker, $maxLength), $output); }
/** * Returns an empty IMS Manifest file as a DOMDocument, ready to be fill with * new information about IMS QTI Items and Tests. * * @return DOMDocument */ public static function emptyImsManifest() { $templateRenderer = new taoItems_models_classes_TemplateRenderer(ROOT_PATH . 'taoQtiItem/model/qti/templates/imsmanifest.tpl.php', array('qtiItems' => array(), 'manifestIdentifier' => 'QTI-TEST-MANIFEST-' . tao_helpers_Display::textCleaner(uniqid('tao', true), '-'))); $manifest = new DOMDocument('1.0', TAO_DEFAULT_ENCODING); $manifest->loadXML($templateRenderer->render()); return $manifest; }
/** * Convenience function clean the input string (replace all no alphanum chars). * * @param string $input The input string. * @return string $output The output string without non alphanum characters. */ function _clean($input) { return tao_helpers_Display::textCleaner($input); }
/** * Create the default content directory of a QTI test. * * @param core_kernel_classes_Resource $test * @param boolean $createTestFile Whether or not create an empty QTI XML test file. Default is (boolean) true. * @return Directory the content directory * @throws taoQtiTest_models_classes_QtiTestServiceException If a runtime error occurs while creating the test content. */ public function createContent(core_kernel_classes_Resource $test, $createTestFile = true) { $dir = $this->getDefaultDir()->getDirectory(md5($test->getUri())); if ($dir->exists()) { throw new common_exception_InconsistentData('Data dir fir test ' . $test->getUri() . ' already exists'); } $file = $dir->getFile(TAOQTITEST_FILENAME); if ($createTestFile === true) { $emptyTestXml = $this->getQtiTestTemplateFileAsString(); $doc = new DOMDocument('1.0', 'UTF-8'); $doc->loadXML($emptyTestXml); // Set the test label as title. $doc->documentElement->setAttribute('title', $test->getLabel()); //generate a valid qti identifier $identifier = tao_helpers_Display::textCleaner($test->getLabel(), '*', 32); $identifier = str_replace('_', '-', $identifier); if (preg_match('/^[0-9]/', $identifier)) { $identifier = '_' . $identifier; } $doc->documentElement->setAttribute('identifier', $identifier); $doc->documentElement->setAttribute('toolVersion', TAO_VERSION); if (!$file->write($doc->saveXML())) { $msg = "Unable to write raw QTI Test template."; throw new taoQtiTest_models_classes_QtiTestServiceException($msg, taoQtiTest_models_classes_QtiTestServiceException::TEST_WRITE_ERROR); } common_Logger::i("Created QTI Test content for test '" . $test->getUri() . "'."); } else { if ($file->exists()) { $doc = new DOMDocument('1.0', 'UTF-8'); $doc->loadXML($file->read()); // Label update only. $doc->documentElement->setAttribute('title', $test->getLabel()); if (!$file->update($doc->saveXML())) { $msg = "Unable to update QTI Test file."; throw new taoQtiTest_models_classes_QtiTestServiceException($msg, taoQtiTest_models_classes_QtiTestServiceException::TEST_WRITE_ERROR); } } } $directory = $this->getFileReferenceSerializer()->serialize($dir); $test->editPropertyValues($this->getProperty(TEST_TESTCONTENT_PROP), $directory); return $dir; }