/** * Enable you to map an rdf property to a form element using the Widget * * @access public * @author Bertrand Chevrier, <*****@*****.**> * @param Property property * @return tao_helpers_form_FormElement */ public static function elementMap(core_kernel_classes_Property $property) { $returnValue = null; //create the element from the right widget $property->feed(); $widgetResource = $property->getWidget(); if (is_null($widgetResource)) { return null; } //authoring widget is not used in standalone mode if ($widgetResource->getUri() == 'http://www.tao.lu/datatypes/WidgetDefinitions.rdf#Authoring' && tao_helpers_Context::check('STANDALONE_MODE')) { return null; } // horrible hack to fix file widget if ($widgetResource->getUri() == 'http://www.tao.lu/datatypes/WidgetDefinitions.rdf#AsyncFile') { $widgetResource = new core_kernel_classes_Resource('http://www.tao.lu/datatypes/WidgetDefinitions.rdf#GenerisAsyncFile'); } $element = tao_helpers_form_FormFactory::getElementByWidget(tao_helpers_Uri::encode($property->getUri()), $widgetResource); if (!is_null($element)) { if ($element->getWidget() != $widgetResource->getUri()) { common_Logger::w('Widget definition differs from implementation: ' . $element->getWidget() . ' != ' . $widgetResource->getUri()); return null; } //use the property label as element description $propDesc = strlen(trim($property->getLabel())) > 0 ? $property->getLabel() : str_replace(LOCAL_NAMESPACE, '', $property->getUri()); $element->setDescription($propDesc); //multi elements use the property range as options if (method_exists($element, 'setOptions')) { $range = $property->getRange(); if ($range != null) { $options = array(); if ($element instanceof tao_helpers_form_elements_Treeview) { if ($property->getUri() == RDFS_RANGE) { $options = self::rangeToTree(new core_kernel_classes_Class(RDFS_RESOURCE)); } else { $options = self::rangeToTree($range); } } else { foreach ($range->getInstances(true) as $rangeInstance) { $options[tao_helpers_Uri::encode($rangeInstance->getUri())] = $rangeInstance->getLabel(); } //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; }
/** * @see taoItems_models_classes_itemModel::getPreviewUrl() */ public function getAuthoringUrl(core_kernel_classes_Resource $item) { return _url('index', 'QtiCreator', 'taoQtiItem', array('instance' => $item->getUri(), 'STANDALONE_MODE' => intval(\tao_helpers_Context::check('STANDALONE_MODE')))); }
/** * Enable you to map an rdf property to a form element using the Widget * * @access public * @author Bertrand Chevrier, <*****@*****.**> * @param core_kernel_classes_Property $property * @return tao_helpers_form_FormElement */ public static function elementMap(core_kernel_classes_Property $property) { $returnValue = null; //create the element from the right widget $property->feed(); $widgetResource = $property->getWidget(); if (is_null($widgetResource)) { return null; } //authoring widget is not used in standalone mode if ($widgetResource->getUri() === 'http://www.tao.lu/datatypes/WidgetDefinitions.rdf#Authoring' && tao_helpers_Context::check('STANDALONE_MODE')) { return null; } // horrible hack to fix file widget if ($widgetResource->getUri() === 'http://www.tao.lu/datatypes/WidgetDefinitions.rdf#AsyncFile') { $widgetResource = new core_kernel_classes_Resource('http://www.tao.lu/datatypes/WidgetDefinitions.rdf#GenerisAsyncFile'); } $element = tao_helpers_form_FormFactory::getElementByWidget(tao_helpers_Uri::encode($property->getUri()), $widgetResource); if (!is_null($element)) { if ($element->getWidget() !== $widgetResource->getUri()) { common_Logger::w('Widget definition differs from implementation: ' . $element->getWidget() . ' != ' . $widgetResource->getUri()); return null; } //use the property label as element description $propDesc = strlen(trim($property->getLabel())) > 0 ? $property->getLabel() : str_replace(LOCAL_NAMESPACE, '', $property->getUri()); $element->setDescription($propDesc); //multi elements use the property range as options if (method_exists($element, 'setOptions')) { $range = $property->getRange(); if ($range !== null) { $options = array(); if ($element instanceof TreeAware) { $sortedOptions = $element->rangeToTree($property->getUri() === RDFS_RANGE ? new core_kernel_classes_Class(RDFS_RESOURCE) : $range); } else { /** @var core_kernel_classes_Resource $rangeInstance */ foreach ($range->getInstances(true) as $rangeInstance) { $level = $rangeInstance->getOnePropertyValue(new core_kernel_classes_Property(TAO_LIST_LEVEL_PROP)); if (is_null($level)) { $options[tao_helpers_Uri::encode($rangeInstance->getUri())] = array(tao_helpers_Uri::encode($rangeInstance->getUri()), $rangeInstance->getLabel()); } else { $level = $level instanceof core_kernel_classes_Resource ? $level->getUri() : (string) $level; $options[$level] = array(tao_helpers_Uri::encode($rangeInstance->getUri()), $rangeInstance->getLabel()); } } ksort($options); $sortedOptions = array(); foreach ($options as $id => $values) { $sortedOptions[$values[0]] = $values[1]; } //set the default value to an empty space if (method_exists($element, 'setEmptyOption')) { $element->setEmptyOption(' '); } } //complete the options listing $element->setOptions($sortedOptions); } } foreach (ValidationRuleRegistry::getRegistry()->getValidators($property) as $validator) { $element->addValidator($validator); } $returnValue = $element; } return $returnValue; }
/** * search the instances of an ontology * @return */ public function search() { $found = false; try { $clazz = $this->getCurrentClass(); } catch (Exception $e) { common_Logger::i('Search : could not find current class switch to root class'); $clazz = $this->getRootClass(); } $formContainer = $this->getSearchForm($clazz); $myForm = $formContainer->getForm(); if (tao_helpers_Context::check('STANDALONE_MODE')) { $standAloneElt = tao_helpers_form_FormFactory::getElement('standalone', 'Hidden'); $standAloneElt->setValue(true); $myForm->addElement($standAloneElt); } if ($myForm->isSubmited()) { if ($myForm->isValid()) { $filters = $myForm->getValues('filters'); $model = array(); foreach ($filters as $propUri => $filter) { if (preg_match("/^http/", $propUri) && !empty($filter)) { $property = new core_kernel_classes_Property($propUri); $model[$property->getUri()] = array('id' => $property->getUri(), 'label' => $property->getLabel(), 'sortable' => true); } else { unset($filters[$propUri]); } } $clazz = new core_kernel_classes_Class($myForm->getValue('clazzUri')); if (!array_key_exists(RDFS_LABEL, $model)) { $labelProp = new core_kernel_classes_Property(RDFS_LABEL); $model = array_merge(array($labelProp->getUri() => array('id' => $labelProp->getUri(), 'label' => $labelProp->getLabel(), 'sortable' => true)), $model); } $params = $myForm->getValues('params'); if (!isset($params['recursive'])) { // 0 => Current class + sub-classes, 10 => Current class only $params['recursive'] = true; } else { $params['recursive'] = false; } $params['like'] = false; return $this->returnJson(array('url' => _url('searchResults', null, null, array('classUri' => $clazz->getUri())), 'params' => $params, 'model' => $model, 'filters' => $filters, 'result' => true)); } } $this->setData('myForm', $myForm->render()); $this->setData('formTitle', __('Search')); $this->setView('form/search.tpl', 'tao'); }
/** * Start the session */ protected function session() { if (tao_helpers_Context::check('APP_MODE')) { // Set a specific ID to the session. $request = new Request(); if ($request->hasParameter('session_id')) { session_id($request->getParameter('session_id')); } } // set the session cookie to HTTP only. $this->configureSessionHandler(); $sessionParams = session_get_cookie_params(); $cookieDomain = true == tao_helpers_Uri::isValidAsCookieDomain(ROOT_URL) ? tao_helpers_Uri::getDomain(ROOT_URL) : $sessionParams['domain']; session_set_cookie_params($sessionParams['lifetime'], tao_helpers_Uri::getPath(ROOT_URL), $cookieDomain, $sessionParams['secure'], TRUE); session_name(GENERIS_SESSION_NAME); if (isset($_COOKIE[GENERIS_SESSION_NAME])) { // Resume the session session_start(); //cookie keep alive, if lifetime is not 0 if ($sessionParams['lifetime'] !== 0) { $expiryTime = $sessionParams['lifetime'] + time(); setcookie(session_name(), session_id(), $expiryTime, tao_helpers_Uri::getPath(ROOT_URL), $cookieDomain, $sessionParams['secure'], true); } } }