* @package tao */ class tao_actions_form_IndexProperty extends tao_helpers_form_FormContainer { /** * @var OntologyIndex */ protected $index; protected $prefix; public function __construct(OntologyIndex $index, $prefix) { $this->index = $index; $this->prefix = $prefix; return parent::__construct(); } /** * @return OntologyIndex */ public function getIndex() { return $this->index; } /** * Initialize the form * * @access protected * @author Bertrand Chevrier, * @return mixed */ protected function initForm() { $this->form = tao_helpers_form_FormFactory::getForm('indexform', []); } /** * Initialize the form elements * * @access protected * @author Bertrand Chevrier, * @return mixed */ protected function initElements() { $elementNames = []; //index part $indexProperty = $this->getIndex(); $indexUri = tao_helpers_Uri::encode($indexProperty->getUri()); //get and add Label (Text) $label = (!is_null($indexProperty)) ? $indexProperty->getLabel() : ''; $propIndexElt = tao_helpers_form_FormFactory::getElement("index_" . $this->prefix . "_" . tao_helpers_Uri::encode(OntologyRdfs::RDFS_LABEL), 'Textbox'); $propIndexElt->setDescription(__('Label')); $propIndexElt->addAttribute('class', 'index'); $propIndexElt->addAttribute('data-related-index', $indexUri); $propIndexElt->setValue($label); $this->form->addElement($propIndexElt); $elementNames[] = $propIndexElt->getName(); //get and add Fuzzy matching (Radiobox) $fuzzyMatching = (!is_null($indexProperty)) ? ($indexProperty->isFuzzyMatching()) ? GenerisRdf::GENERIS_TRUE : GenerisRdf::GENERIS_FALSE : ''; $options = [ tao_helpers_Uri::encode(GenerisRdf::GENERIS_TRUE) => __('True'), tao_helpers_Uri::encode(GenerisRdf::GENERIS_FALSE) => __('False') ]; $propIndexElt = tao_helpers_form_FormFactory::getElement($this->prefix . "_" . tao_helpers_Uri::encode(OntologyIndex::PROPERTY_INDEX_FUZZY_MATCHING), 'Radiobox'); $propIndexElt->setOptions($options); $propIndexElt->setDescription(__('Fuzzy Matching')); $propIndexElt->addAttribute('class', 'index'); $propIndexElt->addAttribute('data-related-index', $indexUri); $propIndexElt->setValue(tao_helpers_Uri::encode($fuzzyMatching)); $propIndexElt->addValidator(new tao_helpers_form_validators_NotEmpty()); $this->form->addElement($propIndexElt); $elementNames[] = $propIndexElt->getName(); //get and add identifier (Text) $identifier = (!is_null($indexProperty)) ? $indexProperty->getIdentifier() : ''; $propIndexElt = tao_helpers_form_FormFactory::getElement($this->prefix . "_" . tao_helpers_Uri::encode(OntologyIndex::PROPERTY_INDEX_IDENTIFIER), 'Textbox'); $propIndexElt->setDescription(__('Identifier')); $propIndexElt->addAttribute('class', 'index'); $propIndexElt->addAttribute('data-related-index', $indexUri); $propIndexElt->setValue($identifier); $propIndexElt->addValidator(new tao_helpers_form_validators_IndexIdentifier()); $this->form->addElement($propIndexElt); $elementNames[] = $propIndexElt->getName(); //get and add Default search $defaultSearch = (!is_null($indexProperty)) ? ($indexProperty->isDefaultSearchable()) ? GenerisRdf::GENERIS_TRUE : GenerisRdf::GENERIS_FALSE : ''; $options = [ tao_helpers_Uri::encode(GenerisRdf::GENERIS_TRUE) => __('True'), tao_helpers_Uri::encode(GenerisRdf::GENERIS_FALSE) => __('False') ]; $propIndexElt = tao_helpers_form_FormFactory::getElement($this->prefix . "_" . tao_helpers_Uri::encode(OntologyIndex::PROPERTY_DEFAULT_SEARCH), 'Radiobox'); $propIndexElt->setOptions($options); $propIndexElt->setDescription(__('Default search')); $propIndexElt->addAttribute('class', 'index'); $propIndexElt->addAttribute('data-related-index', $indexUri); $propIndexElt->setValue(tao_helpers_Uri::encode($defaultSearch)); $propIndexElt->addValidator(new tao_helpers_form_validators_NotEmpty()); $this->form->addElement($propIndexElt); $elementNames[] = $propIndexElt->getName(); //get and add Tokenizer (Combobox) $tokenizerRange = new \core_kernel_classes_Class('http://www.tao.lu/Ontologies/TAO.rdf#Tokenizer'); $options = []; /** @var core_kernel_classes_Resource $value */ foreach ($tokenizerRange->getInstances() as $value) { $options[tao_helpers_Uri::encode($value->getUri())] = $value->getLabel(); } $tokenizer = (!is_null($indexProperty)) ? $indexProperty->getOnePropertyValue(new \core_kernel_classes_Property(OntologyIndex::PROPERTY_INDEX_TOKENIZER)) : null; $tokenizer = (get_class($tokenizer) === 'core_kernel_classes_Resource') ? $tokenizer->getUri() : ''; $propIndexElt = tao_helpers_form_FormFactory::getElement($this->prefix . "_" . tao_helpers_Uri::encode(OntologyIndex::PROPERTY_INDEX_TOKENIZER), 'Combobox'); $propIndexElt->setDescription(__('Tokenizer')); $propIndexElt->addAttribute('class', 'index'); $propIndexElt->addAttribute('data-related-index', $indexUri); $propIndexElt->setOptions($options); $propIndexElt->setValue(tao_helpers_Uri::encode($tokenizer)); $propIndexElt->addValidator(new tao_helpers_form_validators_NotEmpty()); $this->form->addElement($propIndexElt); $elementNames[] = $propIndexElt->getName(); $removeIndexElt = tao_helpers_form_FormFactory::getElement("index_{$indexUri}_remove", 'Free'); $removeIndexElt->setValue( " " . __( 'remove index' ) . "" ); $this->form->addElement($removeIndexElt); $elementNames[] = $removeIndexElt; $separatorIndexElt = tao_helpers_form_FormFactory::getElement("index_" . $this->prefix . "_separator", 'Free'); $separatorIndexElt->setValue( "
" ); $this->form->addElement($separatorIndexElt); $elementNames[] = $separatorIndexElt; } }