/** * Short description of method getOptions * * @access public * @author Joel Bout, <*****@*****.**> * @param string format * @return array */ public function getOptions($format = 'flat') { switch ($format) { case 'structured': $returnValue = parent::getOptions(); break; case 'flat': default: $returnValue = tao_helpers_form_GenerisFormFactory::extractTreeData(parent::getOptions()); break; } return (array) $returnValue; }
/** * Short description of method initElements * * @access public * @author Bertrand Chevrier, <*****@*****.**> * @return mixed */ public function initElements() { $property = $this->getPropertyInstance(); isset($this->options['index']) ? $index = $this->options['index'] : ($index = 1); $propertyProperties = array_merge(tao_helpers_form_GenerisFormFactory::getDefaultProperties(), array(new core_kernel_classes_Property(PROPERTY_IS_LG_DEPENDENT), new core_kernel_classes_Property(PROPERTY_WIDGET), new core_kernel_classes_Property(RDFS_RANGE))); $elementNames = array(); foreach ($propertyProperties as $propertyProperty) { //map properties widgets to form elements $element = tao_helpers_form_GenerisFormFactory::elementMap($propertyProperty); if (!is_null($element)) { //take property values to populate the form $values = $property->getPropertyValuesCollection($propertyProperty); foreach ($values->getIterator() as $value) { if (!is_null($value)) { if ($value instanceof core_kernel_classes_Resource) { $element->setValue($value->getUri()); } if ($value instanceof core_kernel_classes_Literal) { $element->setValue((string) $value); } } } $element->setName("property_{$index}_{$element->getName()}"); $element->addClass('property'); if ($propertyProperty->getUri() == RDFS_LABEL) { $element->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty')); } $this->form->addElement($element); $elementNames[] = $element->getName(); } } $encodedUri = tao_helpers_Uri::encode($property->getUri()); $modeElt = tao_helpers_form_FormFactory::getElement("{$index}_uri", 'Hidden'); $modeElt->setValue($encodedUri); $modeElt->addClass('property'); $this->form->addElement($modeElt); $elementNames[] = $modeElt->getName(); if (count($elementNames) > 0) { $groupTitle = $this->getGroupTitle($property); $this->form->createGroup("property_{$encodedUri}", $groupTitle, $elementNames); } }
/** * Initialize the form elements * * @access protected * @author Bertrand Chevrier, <*****@*****.**> * @return mixed */ protected function initElements() { $clazz = $this->getClazz(); $instance = $this->getInstance(); $guiOrderProperty = new core_kernel_classes_Property(TAO_GUIORDER_PROP); //get the list of properties to set in the form $propertyCandidates = tao_helpers_form_GenerisFormFactory::getDefaultProperties(); $classProperties = tao_helpers_form_GenerisFormFactory::getClassProperties($clazz, $this->getTopClazz()); $propertyCandidates = array_merge($propertyCandidates, $classProperties); $additionalProperties = isset($this->options['additionalProperties']) && is_array($this->options['additionalProperties']) ? $this->options['additionalProperties'] : array(); if (!empty($additionalProperties)) { $propertyCandidates = array_merge($propertyCandidates, $additionalProperties); } $excludedProperties = isset($this->options['excludedProperties']) && is_array($this->options['excludedProperties']) ? $this->options['excludedProperties'] : array(); $editedProperties = array(); foreach ($propertyCandidates as $property) { if (!isset($editedProperties[$property->getUri()]) && !in_array($property->getUri(), $excludedProperties)) { $editedProperties[$property->getUri()] = $property; } } $finalElements = array(); foreach ($editedProperties as $property) { $property->feed(); $widget = $property->getWidget(); if ($widget == null || $widget instanceof core_kernel_classes_Literal) { continue; } //map properties widgets to form elments $element = tao_helpers_form_GenerisFormFactory::elementMap($property); if (!is_null($element)) { //take instance values to populate the form if (!is_null($instance)) { $values = $instance->getPropertyValuesCollection($property); foreach ($values->getIterator() as $value) { if (!is_null($value)) { if ($value instanceof core_kernel_classes_Resource) { if ($element instanceof tao_helpers_form_elements_Readonly) { $element->setValue($value->getLabel()); } else { $element->setValue($value->getUri()); } } if ($value instanceof core_kernel_classes_Literal) { $element->setValue((string) $value); } } } } // don't show empty labels if ($element instanceof tao_helpers_form_elements_Label && strlen($element->getRawValue()) == 0) { continue; } //set file element validator: if ($element instanceof tao_helpers_form_elements_AsyncFile) { } if ($property->getUri() == RDFS_LABEL) { // Label will not be a TAO Property. However, it should // be always first. array_splice($finalElements, 0, 0, array(array($element, 1))); } else { if (count($guiOrderPropertyValues = $property->getPropertyValues($guiOrderProperty))) { // get position of this property if it has one. $position = intval($guiOrderPropertyValues[0]); // insert the element at the right place. $i = 0; while ($i < count($finalElements) && ($position >= $finalElements[$i][1] && $finalElements[$i][1] !== null)) { $i++; } array_splice($finalElements, $i, 0, array(array($element, $position))); } else { // Unordered properties will go at the end of the form. $finalElements[] = array($element, null); } } } } // Add elements related to class properties to the form. foreach ($finalElements as $element) { $this->form->addElement($element[0]); } //add an hidden elt for the class uri $classUriElt = tao_helpers_form_FormFactory::getElement('classUri', 'Hidden'); $classUriElt->setValue(tao_helpers_Uri::encode($clazz->getUri())); $this->form->addElement($classUriElt); if (!is_null($instance)) { //add an hidden elt for the instance Uri $instanceUriElt = tao_helpers_form_FormFactory::getElement('uri', 'Hidden'); $instanceUriElt->setValue(tao_helpers_Uri::encode($instance->getUri())); $this->form->addElement($instanceUriElt); $hiddenId = tao_helpers_form_FormFactory::getElement('id', 'Hidden'); $hiddenId->setValue($instance->getUri()); $this->form->addElement($hiddenId); } }
/** * Initialize the form elements * * @access protected * @author Bertrand Chevrier, <*****@*****.**> * @return mixed */ protected function initElements() { $property = new core_kernel_classes_Property($this->instance->getUri()); isset($this->options['index']) ? $index = $this->options['index'] : ($index = 1); $propertyProperties = array_merge(tao_helpers_form_GenerisFormFactory::getDefaultProperties(), array(new core_kernel_classes_Property(PROPERTY_IS_LG_DEPENDENT), new core_kernel_classes_Property(TAO_GUIORDER_PROP))); $elementNames = array(); foreach ($propertyProperties as $propertyProperty) { //map properties widgets to form elements $element = tao_helpers_form_GenerisFormFactory::elementMap($propertyProperty); if (!is_null($element)) { //take property values to populate the form $values = $property->getPropertyValuesCollection($propertyProperty); foreach ($values->getIterator() as $value) { if (!is_null($value)) { if ($value instanceof core_kernel_classes_Resource) { $element->setValue($value->getUri()); } if ($value instanceof core_kernel_classes_Literal) { $element->setValue((string) $value); } } } $element->setName("{$index}_{$element->getName()}"); $element->addClass('property'); if ($propertyProperty->getUri() == TAO_GUIORDER_PROP) { $element->addValidator(tao_helpers_form_FormFactory::getValidator('Integer')); } if ($propertyProperty->getUri() == RDFS_LABEL) { $element->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty')); } $this->form->addElement($element); $elementNames[] = $element->getName(); } } //build the type list from the "widget/range to type" map $typeElt = tao_helpers_form_FormFactory::getElement("{$index}_type", 'Combobox'); $typeElt->setDescription(__('Type')); $typeElt->addAttribute('class', 'property-type property'); $typeElt->setEmptyOption(' --- ' . __('select') . ' --- '); $options = array(); $checkRange = false; foreach (tao_helpers_form_GenerisFormFactory::getPropertyMap() as $typeKey => $map) { $options[$typeKey] = $map['title']; $widget = $property->getWidget(); if ($widget instanceof core_kernel_classes_Resource) { if ($widget->getUri() == $map['widget']) { $typeElt->setValue($typeKey); $checkRange = is_null($map['range']); } } } $typeElt->setOptions($options); $this->form->addElement($typeElt); $elementNames[] = $typeElt->getName(); //list drop down $listService = tao_models_classes_ListService::singleton(); $listElt = tao_helpers_form_FormFactory::getElement("{$index}_range", 'Combobox'); $listElt->setDescription(__('List values')); $listElt->addAttribute('class', 'property-listvalues property'); $listElt->setEmptyOption(' --- ' . __('select') . ' --- '); $listOptions = array(); foreach ($listService->getLists() as $list) { $listOptions[tao_helpers_Uri::encode($list->getUri())] = $list->getLabel(); $range = $property->getRange(); if (!is_null($range)) { if ($range->getUri() == $list->getUri()) { $listElt->setValue($list->getUri()); } } } $listOptions['new'] = ' + ' . __('Add / Edit lists'); $listElt->setOptions($listOptions); if ($checkRange) { $listElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty')); } $this->form->addElement($listElt); $elementNames[] = $listElt->getName(); //index part $indexes = $property->getPropertyValues(new \core_kernel_classes_Property(INDEX_PROPERTY)); foreach ($indexes as $i => $indexUri) { $indexProperty = new \oat\tao\model\search\Index($indexUri); $indexFormContainer = new tao_actions_form_IndexProperty($this->getClazz(), $indexProperty, array('property' => $property->getUri(), 'propertyindex' => $index, 'index' => $i)); /** @var tao_helpers_form_Form $indexForm */ $indexForm = $indexFormContainer->getForm(); foreach ($indexForm->getElements() as $element) { $this->form->addElement($element); $elementNames[] = $element->getName(); } } //add this element only when the property is defined (type) if (!is_null($property->getRange())) { $addIndexElt = tao_helpers_form_FormFactory::getElement("index_{$index}_add", 'Free'); $addIndexElt->setValue("<a href='#' class='btn-info index-adder small index'><span class='icon-add'></span> " . __('Add index') . "</a><div class='clearfix'></div>"); $this->form->addElement($addIndexElt); $elementNames[] = $addIndexElt; } else { $addIndexElt = tao_helpers_form_FormFactory::getElement("index_{$index}_p", 'Free'); $addIndexElt->setValue("<p class='index' >" . __('Choose a type for your property first') . "</p>"); $this->form->addElement($addIndexElt); $elementNames[] = $addIndexElt; } //add an hidden elt for the property uri $encodedUri = tao_helpers_Uri::encode($property->getUri()); $propUriElt = tao_helpers_form_FormFactory::getElement("{$index}_uri", 'Hidden'); $propUriElt->addAttribute('class', 'property-uri property'); $propUriElt->setValue($encodedUri); $this->form->addElement($propUriElt); $elementNames[] = $propUriElt; if (count($elementNames) > 0) { $groupTitle = $this->getGroupTitle($property); $this->form->createGroup("property_{$encodedUri}", $groupTitle, $elementNames); } }
/** * Initialize the form elements * * @access protected * @author Bertrand Chevrier, <*****@*****.**> * @return mixed */ protected function initElements() { $chainingElt = tao_helpers_form_FormFactory::getElement('chaining', 'Radiobox'); $chainingElt->setDescription(__('Filtering mode')); $chainingElt->setOptions(array('or' => __('Exclusive (OR)'), 'and' => __('Inclusive (AND)'))); $chainingElt->setValue('or'); $this->form->addElement($chainingElt); $recursiveElt = tao_helpers_form_FormFactory::getElement('recursive', 'Checkbox'); $recursiveElt->setDescription(__('Scope')); $recursiveElt->setOptions(array('0' => __('Search sub-classes'))); $this->form->addElement($recursiveElt); $searchClassUriElt = tao_helpers_form_FormFactory::getElement("clazzUri", "Hidden"); $searchClassUriElt->setValue(tao_helpers_Uri::encode($this->clazz->getUri())); $this->form->addElement($searchClassUriElt); $langElt = tao_helpers_form_FormFactory::getElement('lang', 'Combobox'); $langElt->setDescription(__('Language')); $languages = array_merge(array('-- any --'), tao_helpers_I18n::getAvailableLangsByUsage(new core_kernel_classes_Resource(INSTANCE_LANGUAGE_USAGE_DATA))); $langElt->setOptions($languages); $langElt->setValue(0); $this->form->addElement($langElt); $this->form->createGroup('params', __('<del>Options</del>'), array('chaining', 'recursive', 'lang')); $filters = array(); $defaultProperties = tao_helpers_form_GenerisFormFactory::getDefaultProperties(); $classProperties = $this->getClassProperties(); $properties = array_merge($defaultProperties, $classProperties); isset($this->options['recursive']) ? $recursive = $this->options['recursive'] : ($recursive = false); if ($recursive) { foreach ($this->clazz->getSubClasses(true) as $subClass) { $properties = array_merge($subClass->getProperties(false), $properties); } } foreach ($properties as $property) { $element = tao_helpers_form_GenerisFormFactory::elementMap($property); if (!is_null($element) && !$element instanceof tao_helpers_form_elements_Authoring && !$element instanceof tao_helpers_form_elements_Hiddenbox && !$element instanceof tao_helpers_form_elements_Hidden) { if ($element instanceof tao_helpers_form_elements_MultipleElement) { $newElement = tao_helpers_form_FormFactory::getElement($element->getName(), 'Checkbox'); $newElement->setDescription($element->getDescription()); $newElement->setOptions($element->getOptions()); $element = $newElement; } if ($element instanceof tao_helpers_form_elements_Htmlarea) { $newElement = tao_helpers_form_FormFactory::getElement($element->getName(), 'Textarea'); $newElement->setDescription($element->getDescription()); $element = $newElement; } $this->form->addElement($element); $filters[] = $element->getName(); } } $this->form->createGroup('filters', __('<del>Filters</del>'), $filters); }
/** * Initialize the form elements * * @access protected * @author Bertrand Chevrier, <*****@*****.**> * @return mixed */ protected function initElements() { $clazz = $this->getClassInstance(); //add a group form for the class edition $elementNames = array(); foreach (tao_helpers_form_GenerisFormFactory::getDefaultProperties() as $property) { //map properties widgets to form elements $element = tao_helpers_form_GenerisFormFactory::elementMap($property); if (!is_null($element)) { //take property values to populate the form $values = $clazz->getPropertyValues($property); if (!$property->isMultiple()) { if (count($values) > 1) { $values = array_slice($values, 0, 1); } } foreach ($values as $value) { if (!is_null($value)) { $element->setValue($value); } } $element->setName('class_' . $element->getName()); //set label validator if ($property->getUri() == RDFS_LABEL) { $element->addValidators(array(tao_helpers_form_FormFactory::getValidator('NotEmpty'))); $ns = substr($clazz->getUri(), 0, strpos($clazz->getUri(), '#')); if ($ns != LOCAL_NAMESPACE) { $readonly = tao_helpers_form_FormFactory::getElement($element->getName(), 'Readonly'); $readonly->setDescription($element->getDescription()); $readonly->setValue($element->getRawValue()); $element = $readonly; } } $element->addClass('global'); $this->form->addElement($element); $elementNames[] = $element->getName(); } } //add an hidden elt for the class uri $classUriElt = tao_helpers_form_FormFactory::getElement('classUri', 'Hidden'); $classUriElt->setValue(tao_helpers_Uri::encode($clazz->getUri())); $classUriElt->addClass('global'); $this->form->addElement($classUriElt); $hiddenId = tao_helpers_form_FormFactory::getElement('id', 'Hidden'); $hiddenId->setValue($clazz->getUri()); $hiddenId->addClass('global'); $this->form->addElement($hiddenId); $localNamespace = common_ext_NamespaceManager::singleton()->getLocalNamespace()->getUri(); //class properties edition: add a group form for each property $classProperties = tao_helpers_form_GenerisFormFactory::getClassProperties($clazz, $this->getTopClazz()); $i = 0; $systemProperties = $this->getSystemProperties(); foreach ($classProperties as $classProperty) { $i++; $useEditor = (bool) preg_match("/^" . preg_quote($localNamespace, '/') . "/", $classProperty->getUri()); $parentProp = true; $domains = $classProperty->getDomain(); foreach ($domains->getIterator() as $domain) { if (array_search($classProperty->getUri(), $systemProperties) !== false || $domain->getUri() == $clazz->getUri()) { $parentProp = false; //@todo use the getPrivileges method once implemented break; } } if ($useEditor) { $propData = array(); if (isset($this->propertyData[$classProperty->getUri()])) { foreach ($this->propertyData[$classProperty->getUri()] as $key => $value) { $propData[$i . '_' . $key] = $value; } } $propForm = $this->getPropertyForm($classProperty, $i, $parentProp, $propData); //and get its elements and groups $this->form->setElements(array_merge($this->form->getElements(), $propForm->getElements())); $this->form->setGroups(array_merge($this->form->getGroups(), $propForm->getGroups())); unset($propForm); } else { $roElement = tao_helpers_form_FormFactory::getElement('roProperty' . $i, 'Free'); $roElement->setValue(__('Cannot be edited')); $this->form->addElement($roElement); $groupTitle = '<span class="property-heading-label">' . _dh($classProperty->getLabel()) . '</span>'; $this->form->createGroup("ro_property_{$i}", $groupTitle, array('roProperty' . $i)); } } }
/** * Default property handling * * @param array $propertyValues */ protected function saveSimpleProperty($propertyValues) { $propertyMap = tao_helpers_form_GenerisFormFactory::getPropertyMap(); $type = $propertyValues['type']; $range = isset($propertyValues['range']) ? tao_helpers_Uri::decode(trim($propertyValues['range'])) : null; unset($propertyValues['type']); unset($propertyValues['range']); if (isset($propertyMap[$type])) { $values[PROPERTY_WIDGET] = $propertyMap[$type]['widget']; } foreach ($propertyValues as $key => $value) { $values[tao_helpers_Uri::decode($key)] = tao_helpers_Uri::decode($value); } // if the label is empty $validator = new tao_helpers_form_validators_NotEmpty(array('message' => __('Property\'s label field is required'))); if (!$validator->evaluate($values[RDFS_LABEL])) { throw new Exception($validator->getMessage()); } $property = new core_kernel_classes_Property($values['uri']); unset($values['uri']); $this->bindProperties($property, $values); // set the range $property->removePropertyValues(new core_kernel_classes_Property(RDFS_RANGE)); if (!empty($range)) { $property->setRange(new core_kernel_classes_Class($range)); } elseif (isset($propertyMap[$type]) && !empty($propertyMap[$type]['range'])) { $property->setRange(new core_kernel_classes_Class($propertyMap[$type]['range'])); } // set cardinality if (isset($propertyMap[$type]['multiple'])) { $property->setMultiple($propertyMap[$type]['multiple'] == GENERIS_TRUE); } }
/** * Generis API searchInstances function as an action * Developed for the facet based filter ... * @todo Is it a dangerous action ? */ public function searchInstances() { $returnValue = array(); $filter = array(); $properties = array(); if (!tao_helpers_Request::isAjax()) { //throw new Exception("wrong request mode"); } // Get the class paramater if ($this->hasRequestParameter('classUri')) { $clazz = $this->getCurrentClass(); } else { $clazz = $this->getRootClass(); } // Get filter parameter if ($this->hasRequestParameter('filter')) { $filter = $this->getFilterState('filter'); } $properties = tao_helpers_form_GenerisFormFactory::getClassProperties($clazz); // ADD Label property if (!array_key_exists(RDFS_LABEL, $properties)) { $new_properties = array(); $new_properties[RDFS_LABEL] = new core_kernel_classes_Property(RDFS_LABEL); $properties = array_merge($new_properties, $properties); } // Remove item content property if (array_key_exists(TAO_ITEM_CONTENT_PROPERTY, $properties)) { unset($properties[TAO_ITEM_CONTENT_PROPERTY]); } $instances = $this->getClassService()->searchInstances($filter, $clazz, array('recursive' => true)); $index = 0; foreach ($instances as $instance) { $returnValue[$index]['uri'] = $instance->getUri(); $formatedProperties = array(); foreach ($properties as $property) { //$formatedProperties[] = (string)$instance->getOnePropertyValue (new core_kernel_classes_Property($property)); $value = $instance->getOnePropertyValue($property); if ($value instanceof core_kernel_classes_Resource) { $value = $value->getLabel(); } else { $value = (string) $value; } $formatedProperties[] = $value; } $returnValue[$index]['properties'] = (object) $formatedProperties; $index++; } echo json_encode($returnValue); }
/** * Short description of method initElements * * @access public * @author Bertrand Chevrier, <*****@*****.**> * @throws Exception * @throws common_Exception * @return mixed */ public function initElements() { if (!isset($this->options['class_properties'])) { throw new Exception('No class properties found'); } if (!isset($this->options['csv_column'])) { throw new Exception('No csv columns found'); } $columnsOptions = array(); $columnsOptionsLiteral = array(); $columnsOptionsLiteral['csv_select'] = ' --- ' . __('Select') . ' --- '; $columnsOptionsLiteral['csv_null'] = ' --- ' . __("Don't set"); $columnsOptionsRanged = array(); $columnsOptionsRanged['csv_select'] = ' --- ' . __('Select') . ' --- '; $columnsOptionsRanged['csv_null'] = ' --- ' . __('Use default value'); // We build the list of CSV columns that can be mapped to // the target class properties. if ($this->options[tao_helpers_data_CsvFile::FIRST_ROW_COLUMN_NAMES]) { foreach ($this->options['csv_column'] as $i => $column) { $columnsOptions[$i . tao_models_classes_import_CsvImporter::OPTION_POSTFIX] = __('Column') . ' ' . ($i + 1) . ' : ' . $column; } } else { // We do not know column so we display more neutral information // about columns to the end user. for ($i = 0; $i < count($this->options['csv_column']); $i++) { $columnsOptions[$i . tao_models_classes_import_CsvImporter::OPTION_POSTFIX] = __('Column') . ' ' . ($i + 1); } } $i = 0; foreach ($this->options['class_properties'] as $propertyUri => $propertyLabel) { $propElt = tao_helpers_form_FormFactory::getElement($propertyUri, 'Combobox'); $propElt->setDescription($propertyLabel); // literal or ranged? if (array_key_exists($propertyUri, $this->options['ranged_properties'])) { $propElt->setOptions(array_merge($columnsOptionsRanged, $columnsOptions)); } else { $propElt->setOptions(array_merge($columnsOptionsLiteral, $columnsOptions)); } $value = 'csv_select'; if (isset($_POST[$propertyUri]) && isset($columnsOptions[$_POST[$propertyUri]])) { $value = $_POST[$propertyUri]; } $propElt->setValue($value); $this->form->addElement($propElt); $i++; } $this->form->createGroup('property_mapping', __('Map the properties to the CSV columns'), array_keys($this->options['class_properties'])); $ranged = array(); foreach ($this->options['ranged_properties'] as $propertyUri => $propertyLabel) { $property = new core_kernel_classes_Property(tao_helpers_Uri::decode($propertyUri)); $propElt = tao_helpers_form_GenerisFormFactory::elementMap($property); if (!is_null($propElt)) { $defName = tao_helpers_Uri::encode($property->getUri()) . self::DEFAULT_VALUES_SUFFIX; $propElt->setName($defName); $propElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty')); $this->form->addElement($propElt); $ranged[$defName] = $propElt; } } if (count($this->options['ranged_properties']) > 0) { $this->form->createGroup('ranged_property', __('Define the default values'), array_keys($ranged)); } $importFileEle = tao_helpers_form_FormFactory::getElement('importFile', 'Hidden'); $this->form->addElement($importFileEle); $optDelimiter = tao_helpers_form_FormFactory::getElement(tao_helpers_data_CsvFile::FIELD_DELIMITER, 'Hidden'); $this->form->addElement($optDelimiter); $optEncloser = tao_helpers_form_FormFactory::getElement(tao_helpers_data_CsvFile::FIELD_ENCLOSER, 'Hidden'); $this->form->addElement($optEncloser); $optMulti = tao_helpers_form_FormFactory::getElement(tao_helpers_data_CsvFile::MULTI_VALUES_DELIMITER, 'Hidden'); $this->form->addElement($optMulti); $optFirstColumn = tao_helpers_form_FormFactory::getElement(tao_helpers_data_CsvFile::FIRST_ROW_COLUMN_NAMES . '_0', 'Hidden'); $this->form->addElement($optFirstColumn); }
/** * Short description of method initElements * * @access public * @author Bertrand Chevrier, <*****@*****.**> * @throws Exception * @throws common_Exception * @return mixed */ public function initElements() { if (!isset($this->options['class_properties'])) { throw new Exception('No class properties found'); } if (!isset($this->options['csv_column'])) { throw new Exception('No csv columns found'); } $columnsOptions = array(); $columnsOptionsLabels = array(); $columnsOptionsLiteral = array(); $columnsOptionsLiteral['csv_select'] = ' --- ' . __('Select') . ' --- '; $columnsOptionsLiteral['csv_null'] = ' --- ' . __("Don't set"); $columnsOptionsRanged = array(); $columnsOptionsRanged['csv_select'] = ' --- ' . __('Select') . ' --- '; $columnsOptionsRanged['csv_null'] = ' --- ' . __('Use default value'); // We build the list of CSV columns that can be mapped to // the target class properties. if ($this->options[tao_helpers_data_CsvFile::FIRST_ROW_COLUMN_NAMES]) { foreach ($this->options['csv_column'] as $i => $column) { $columnsOptions[$i . tao_models_classes_import_CsvImporter::OPTION_POSTFIX] = __('Column') . ' ' . ($i + 1) . ' : ' . $column; $columnsOptionsLabels[$i . tao_models_classes_import_CsvImporter::OPTION_POSTFIX] = $this->prepareString($column); } } else { // We do not know column so we display more neutral information // about columns to the end user. for ($i = 0; $i < count($this->options['csv_column']); $i++) { $columnsOptions[$i . tao_models_classes_import_CsvImporter::OPTION_POSTFIX] = __('Column') . ' ' . ($i + 1); } } foreach ($this->options['class_properties'] as $propertyUri => $propertyLabel) { $propElt = tao_helpers_form_FormFactory::getElement($propertyUri, 'Combobox'); $propElt->setDescription($propertyLabel); // literal or ranged? $options = array_key_exists($propertyUri, $this->options['ranged_properties']) ? array_merge($columnsOptionsRanged, $columnsOptions) : array_merge($columnsOptionsLiteral, $columnsOptions); $value = 'csv_select'; if (isset($_POST[$propertyUri]) && isset($options[$_POST[$propertyUri]])) { $value = $_POST[$propertyUri]; } // We trying compare current label with option labels from file and set most suitable $label = $this->prepareString($propertyLabel); $value = key(preg_grep("/^{$label}\$/", $columnsOptionsLabels)) ?: $value; $propElt->setOptions($options); $propElt->setValue($value); /** Add mandatory label */ if (tao_helpers_Uri::decode($propertyUri) == RDFS_LABEL) { $elementEqualsToCsvSelect = new tao_helpers_form_elements_xhtml_Hidden(); $elementEqualsToCsvSelect->setValue('csv_select'); $elementEqualsToCsvSelect->setDescription(' to null'); $propElt->addValidator(tao_helpers_form_FormFactory::getValidator('Equals', array('reference' => $elementEqualsToCsvSelect, 'invert' => true))); } $this->form->addElement($propElt); } $this->form->createGroup('property_mapping', __('Map the properties to the CSV columns'), array_keys($this->options['class_properties'])); $ranged = array(); foreach ($this->options['ranged_properties'] as $propertyUri => $propertyLabel) { $property = new core_kernel_classes_Property(tao_helpers_Uri::decode($propertyUri)); $propElt = tao_helpers_form_GenerisFormFactory::elementMap($property); if (!is_null($propElt)) { $defName = tao_helpers_Uri::encode($property->getUri()) . self::DEFAULT_VALUES_SUFFIX; $propElt->setName($defName); if ($this->form->getElement($propertyUri)->getRawValue() == 'csv_null') { $propElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty')); } $this->form->addElement($propElt); $ranged[$defName] = $propElt; } } if (count($this->options['ranged_properties']) > 0) { $this->form->createGroup('ranged_property', __('Define the default values'), array_keys($ranged)); } $importFileEle = tao_helpers_form_FormFactory::getElement('importFile', 'Hidden'); $this->form->addElement($importFileEle); $optDelimiter = tao_helpers_form_FormFactory::getElement(tao_helpers_data_CsvFile::FIELD_DELIMITER, 'Hidden'); $this->form->addElement($optDelimiter); $optEncloser = tao_helpers_form_FormFactory::getElement(tao_helpers_data_CsvFile::FIELD_ENCLOSER, 'Hidden'); $this->form->addElement($optEncloser); $optMulti = tao_helpers_form_FormFactory::getElement(tao_helpers_data_CsvFile::MULTI_VALUES_DELIMITER, 'Hidden'); $this->form->addElement($optMulti); $optFirstColumn = tao_helpers_form_FormFactory::getElement(tao_helpers_data_CsvFile::FIRST_ROW_COLUMN_NAMES, 'Hidden'); $this->form->addElement($optFirstColumn); }
protected function getIndexedProperties() { $classProperties = array(new \core_kernel_classes_Property(RDFS_LABEL)); foreach ($this->resource->getTypes() as $type) { $classProperties = array_merge($classProperties, \tao_helpers_form_GenerisFormFactory::getClassProperties($type)); } return $classProperties; }
/** * Short description of method initElements * * @access public * @author Joel Bout, <*****@*****.**> * @return mixed */ public function initElements() { $guiOrderProperty = new core_kernel_classes_Property(TAO_GUIORDER_PROP); //get the list of properties to set in the form $defaultProperties = tao_helpers_form_GenerisFormFactory::getDefaultProperties(); $editedProperties = $defaultProperties; $excludedProperties = isset($this->options['excludedProperties']) && is_array($this->options['excludedProperties']) ? $this->options['excludedProperties'] : array(); $additionalProperties = isset($this->options['additionalProperties']) && is_array($this->options['additionalProperties']) ? $this->options['additionalProperties'] : array(); $finalElements = array(); $classProperties = array(); foreach ($this->classes as $class) { $classProperties = array_merge(tao_helpers_form_GenerisFormFactory::getClassProperties($class)); } if (!empty($additionalProperties)) { $classProperties = array_merge($classProperties, $additionalProperties); } foreach ($classProperties as $property) { if (!isset($editedProperties[$property->getUri()]) && !in_array($property->getUri(), $excludedProperties)) { $editedProperties[$property->getUri()] = $property; } } foreach ($editedProperties as $property) { $property->feed(); $widget = $property->getWidget(); if ($widget == null || $widget instanceof core_kernel_classes_Literal) { continue; } else { if ($widget instanceof core_kernel_classes_Resource && $widget->getUri() == WIDGET_TREEVIEW) { continue; } } //map properties widgets to form elments $element = tao_helpers_form_GenerisFormFactory::elementMap($property); if (!is_null($element)) { //set label validator if ($property->getUri() == RDFS_LABEL) { $element->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty')); } // don't show empty labels if ($element instanceof tao_helpers_form_elements_Label && strlen($element->getRawValue()) == 0) { continue; } //set file element validator: if ($element instanceof tao_helpers_form_elements_AsyncFile) { } if ($property->getUri() == RDFS_LABEL) { // Label will not be a TAO Property. However, it should // be always first. array_splice($finalElements, 0, 0, array(array($element, 1))); } else { if (count($guiOrderPropertyValues = $property->getPropertyValues($guiOrderProperty))) { // get position of this property if it has one. $position = intval($guiOrderPropertyValues[0]); // insert the element at the right place. $i = 0; while ($i < count($finalElements) && ($position >= $finalElements[$i][1] && $finalElements[$i][1] !== null)) { $i++; } array_splice($finalElements, $i, 0, array(array($element, $position))); } else { // Unordered properties will go at the end of the form. $finalElements[] = array($element, null); } } } } // Add elements related to class properties to the form. foreach ($finalElements as $element) { $this->form->addElement($element[0]); } // @todo currently tao cannot handle multiple classes /* $classUriElt = tao_helpers_form_FormFactory::getElement('classes', 'Hidden'); $uris = array(); foreach ($this->classes as $class) { $uris[] = $class->getUri(); } $classUriElt->setValue($uris); */ //add an hidden elt for the class uri $classUriElt = tao_helpers_form_FormFactory::getElement('classUri', 'Hidden'); $classUriElt->setValue(tao_helpers_Uri::encode($class->getUri())); $this->form->addElement($classUriElt); $this->form->addElement($classUriElt); }
/** * Default property handling * * @param array $propertyValues */ protected function saveSimpleProperty($propertyValues) { $propertyMap = tao_helpers_form_GenerisFormFactory::getPropertyMap(); $type = $propertyValues['type']; $range = isset($propertyValues['range']) ? tao_helpers_Uri::decode(trim($propertyValues['range'])) : null; unset($propertyValues['type']); unset($propertyValues['range']); if (isset($propertyMap[$type])) { $values[PROPERTY_WIDGET] = $propertyMap[$type]['widget']; } foreach ($propertyValues as $key => $value) { $values[tao_helpers_Uri::decode($key)] = tao_helpers_Uri::decode($value); } $property = new core_kernel_classes_Property($values['uri']); unset($values['uri']); $this->bindProperties($property, $values); // set the range $property->removePropertyValues(new core_kernel_classes_Property(RDFS_RANGE)); if (!empty($range)) { $property->setRange(new core_kernel_classes_Class($range)); } elseif (isset($propertyMap[$type]) && !empty($propertyMap[$type]['range'])) { $property->setRange(new core_kernel_classes_Class($propertyMap[$type]['range'])); } // set cardinality if (isset($propertyMap[$type]['multiple'])) { $property->setMultiple($propertyMap[$type]['multiple'] == GENERIS_TRUE); } }
public static function connectorEditor(core_kernel_classes_Resource $connector, core_kernel_classes_Resource $connectorType = null, $formName = '', core_kernel_classes_Resource $activity) { if (empty($formName)) { $formName = 'connectorForm'; } $myForm = null; $myForm = tao_helpers_form_FormFactory::getForm($formName, array()); $myForm->setActions(array(), 'bottom'); //delete the default 'save' and 'revert' buttons //add a hidden input to post the uri of the connector that is being edited $elementConnectorUri = tao_helpers_form_FormFactory::getElement('connectorUri', 'Hidden'); $elementConnectorUri->setValue(tao_helpers_Uri::encode($connector->getUri())); $myForm->addElement($elementConnectorUri); //add a hidden input to post the uri of the activity of the connector that is being edited $elementActivityUri = tao_helpers_form_FormFactory::getElement('activityUri', 'Hidden'); $elementActivityUri->setValue(tao_helpers_Uri::encode($activity->getUri())); $myForm->addElement($elementActivityUri); //add label input: authorize connector label editing or not? $elementLabel = tao_helpers_form_FormFactory::getElement('label', 'Textbox'); $elementLabel->setDescription(__('Label')); $elementLabel->setValue($connector->getLabel()); $myForm->addElement($elementLabel); //add a drop down select input to allow selecting Type of Connector $elementConnectorType = tao_helpers_form_FormFactory::getElement(tao_helpers_Uri::encode(PROPERTY_CONNECTORS_TYPE), 'Combobox'); $elementConnectorType->setDescription(__('Connector Type')); $range = new core_kernel_classes_Class(CLASS_TYPEOFCONNECTORS); if ($range != null) { $options = array(); foreach ($range->getInstances(true) as $rangeInstance) { $options[tao_helpers_Uri::encode($rangeInstance->getUri())] = $rangeInstance->getLabel(); } $elementConnectorType->setOptions($options); } //TODO: check if the parent of the current connector is a connector as well: if so, only allow the split type connector, since there will be no use of a sequential one //check if the property value "type of connector" of the current connector exists if (empty($connectorType)) { //get the type of connector of the current connector $collection = $connector->getPropertyValuesCollection(new core_kernel_classes_Property(PROPERTY_CONNECTORS_TYPE)); if ($collection->isEmpty()) { //if the type of connector is not set yet, simply return a dropdown menu of available type of connector $myForm->addElement($elementConnectorType); return $myForm; } else { foreach ($collection->getIterator() as $value) { if ($value instanceof core_kernel_classes_Resource) { //a connector type has been found! $connectorType = $value; $elementConnectorType->setValue($connectorType->getUri()); //no need to use tao_helpers_Uri::encode here: seems like that it would be done sw else $myForm->addElement($elementConnectorType); break; //stop at the first occurence, which should be the unique one (use newly added getOnePropertyValue here instead) } } } } //if the type of connector is still not set here,there is a problem if (empty($connectorType)) { throw new Exception("an empty value of service definition has been found for the call of service that is being edited"); return $myForm; } //continue building the form according the the type of connector: $elementInputs = array(); if ($connectorType->getUri() == INSTANCE_TYPEOFCONNECTORS_SEQUENCE) { $elementInputs = self::nextActivityElements($connector, 'next'); } else { if ($connectorType->getUri() == INSTANCE_TYPEOFCONNECTORS_CONDITIONAL) { $transitionRule = $connector->getOnePropertyValue(new core_kernel_classes_Property(PROPERTY_CONNECTORS_TRANSITIONRULE)); $elementInputs[] = self::getConditionElement($transitionRule); $elementInputs = array_merge($elementInputs, self::nextActivityElements($connector, 'then')); $elementInputs = array_merge($elementInputs, self::nextActivityElements($connector, 'else')); } else { if ($connectorType->getUri() == INSTANCE_TYPEOFCONNECTORS_PARALLEL) { $elementInputs = self::nextActivityElements($connector, 'parallel', false, false, 'Checkbox'); } else { if ($connectorType->getUri() == INSTANCE_TYPEOFCONNECTORS_JOIN) { $elementInputs = self::nextActivityElements($connector, 'join', true, false, 'Combobox'); } else { throw new Exception("the selected type of connector {$connectorType->getLabel()} is not supported"); } } } } foreach ($elementInputs as $elementInput) { $myForm->addElement($elementInput); } //notification system $myForm->addElement(tao_helpers_form_FormFactory::getElement('notify_set', 'Hidden')); $notifyMsgProperty = new core_kernel_classes_Property(PROPERTY_CONNECTORS_NOTIFICATION_MESSAGE); $notifyMsgElt = tao_helpers_form_GenerisFormFactory::elementMap($notifyMsgProperty); $notifyMsgElt->setValue((string) $connector->getOnePropertyValue($notifyMsgProperty)); $myForm->addElement($notifyMsgElt); $notifyProperty = new core_kernel_classes_Property(PROPERTY_CONNECTORS_NOTIFY); $notifyElt = tao_helpers_form_GenerisFormFactory::elementMap($notifyProperty); $notifyElt->addAttribute('class', 'notify-element'); $notifyElt->setValues(tao_helpers_Uri::encodeArray($connector->getPropertyValues($notifyProperty))); $myForm->addElement($notifyElt); $notifyUserProperty = new core_kernel_classes_Property(PROPERTY_CONNECTORS_USER_NOTIFIED); $notifyUserElt = tao_helpers_form_GenerisFormFactory::elementMap($notifyUserProperty); $notifyUserElt->addAttribute('class', 'notify-user'); $notifyUserElt->setValues(tao_helpers_Uri::encodeArray($connector->getPropertyValues($notifyUserProperty))); $myForm->addElement($notifyUserElt); $notifyGroupProperty = new core_kernel_classes_Property(PROPERTY_CONNECTORS_ROLE_NOTIFIED); $notifyGroupElt = tao_helpers_form_GenerisFormFactory::elementMap($notifyGroupProperty); $notifyGroupElt->addAttribute('class', 'notify-group'); $notifyGroupElt->setValues(tao_helpers_Uri::encodeArray($connector->getPropertyValues($notifyGroupProperty))); $myForm->addElement($notifyGroupElt); return $myForm; }
/** * Initialize the form elements * * @access protected * @author Bertrand Chevrier, <*****@*****.**> * @return mixed */ protected function initElements() { $property = new core_kernel_classes_Property($this->instance->getUri()); isset($this->options['index']) ? $index = $this->options['index'] : ($index = 1); $propertyProperties = array_merge(tao_helpers_form_GenerisFormFactory::getDefaultProperties(), array(new core_kernel_classes_Property(PROPERTY_IS_LG_DEPENDENT), new core_kernel_classes_Property(TAO_GUIORDER_PROP))); $elementNames = array(); foreach ($propertyProperties as $propertyProperty) { //map properties widgets to form elements $element = tao_helpers_form_GenerisFormFactory::elementMap($propertyProperty); if (!is_null($element)) { //take property values to populate the form $values = $property->getPropertyValuesCollection($propertyProperty); foreach ($values->getIterator() as $value) { if (!is_null($value)) { if ($value instanceof core_kernel_classes_Resource) { $element->setValue($value->getUri()); } if ($value instanceof core_kernel_classes_Literal) { $element->setValue((string) $value); } } } $element->setName("{$index}_{$element->getName()}"); $element->addClass('property'); $this->form->addElement($element); $elementNames[] = $element->getName(); if ($propertyProperty->getUri() == TAO_GUIORDER_PROP) { $element->addValidator(tao_helpers_form_FormFactory::getValidator('Integer')); } } } //build the type list from the "widget/range to type" map $typeElt = tao_helpers_form_FormFactory::getElement("{$index}_type", 'Combobox'); $typeElt->setDescription(__('Type')); $typeElt->addAttribute('class', 'property-type property'); $typeElt->setEmptyOption(' --- ' . __('select') . ' --- '); $options = array(); $checkRange = false; foreach (tao_helpers_form_GenerisFormFactory::getPropertyMap() as $typeKey => $map) { $options[$typeKey] = $map['title']; $widget = $property->getWidget(); if ($widget instanceof core_kernel_classes_Resource) { if ($widget->getUri() == $map['widget']) { $typeElt->setValue($typeKey); $checkRange = is_null($map['range']); } } } $typeElt->setOptions($options); $this->form->addElement($typeElt); $elementNames[] = $typeElt->getName(); //list drop down $listService = tao_models_classes_ListService::singleton(); $listElt = tao_helpers_form_FormFactory::getElement("{$index}_range", 'Combobox'); $listElt->setDescription(__('List values')); $listElt->addAttribute('class', 'property-listvalues property'); $listElt->setEmptyOption(' --- ' . __('select') . ' --- '); $listOptions = array(); foreach ($listService->getLists() as $list) { $listOptions[tao_helpers_Uri::encode($list->getUri())] = $list->getLabel(); $range = $property->getRange(); if (!is_null($range)) { if ($range->getUri() == $list->getUri()) { $listElt->setValue($list->getUri()); } } } $listOptions['new'] = ' + ' . __('Add / Edit lists'); $listElt->setOptions($listOptions); if ($checkRange) { $listElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty')); } $this->form->addElement($listElt); $elementNames[] = $listElt->getName(); //add an hidden elt for the property uri $encodedUri = tao_helpers_Uri::encode($property->getUri()); $propUriElt = tao_helpers_form_FormFactory::getElement("{$index}_uri", 'Hidden'); $propUriElt->addAttribute('class', 'property-uri property'); $propUriElt->setValue($encodedUri); $this->form->addElement($propUriElt); $elementNames[] = $propUriElt; if (count($elementNames) > 0) { $groupTitle = $this->getGroupTitle($property); $this->form->createGroup("property_{$encodedUri}", $groupTitle, $elementNames); } }
/** * (non-PHPdoc) * @see tao_actions_form_Search::getClassProperties() */ protected function getClassProperties() { $testTakerProps = \tao_helpers_form_GenerisFormFactory::getClassProperties($this->clazz, $this->getTopClazz()); $userProps = \tao_helpers_form_GenerisFormFactory::getClassProperties(new \core_kernel_classes_Class(CLASS_GENERIS_USER), $this->getTopClazz()); return array_merge($testTakerProps, $userProps); }