Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 104
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
tao_actions_form_IndexProperty
0.00% covered (danger)
0.00%
0 / 104
0.00% covered (danger)
0.00%
0 / 4
182
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 getIndex
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 initForm
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 initElements
0.00% covered (danger)
0.00%
0 / 99
0.00% covered (danger)
0.00%
0 / 1
110
1<?php
2
3/**
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; under version 2
7 * of the License (non-upgradable).
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17 *
18 * Copyright (c) 2008-2010 (original work) Deutsche Institut für Internationale Pädagogische Forschung
19 *                         (under the project TAO-TRANSFER);
20 *               2009-2012 (update and modification) Public Research Centre Henri Tudor
21 *                         (under the project TAO-SUSTAIN & TAO-DEV);
22 *
23 */
24
25use oat\generis\model\GenerisRdf;
26use oat\generis\model\OntologyRdfs;
27use oat\tao\model\search\index\OntologyIndex;
28use oat\tao\model\TaoOntology;
29
30/**
31 * Enable you to edit a property
32 *
33 * @access public
34 * @author Bertrand Chevrier, <bertrand.chevrier@tudor.lu>
35 * @package tao
36 */
37class tao_actions_form_IndexProperty extends tao_helpers_form_FormContainer
38{
39    /**
40     * @var OntologyIndex
41     */
42    protected $index;
43
44    protected $prefix;
45
46    public function __construct(OntologyIndex $index, $prefix)
47    {
48        $this->index = $index;
49        $this->prefix = $prefix;
50        return parent::__construct();
51    }
52
53    /**
54     * @return OntologyIndex
55     */
56    public function getIndex()
57    {
58        return $this->index;
59    }
60
61    /**
62     * Initialize the form
63     *
64     * @access protected
65     * @author Bertrand Chevrier, <bertrand.chevrier@tudor.lu>
66     * @return mixed
67     */
68    protected function initForm()
69    {
70        $this->form = tao_helpers_form_FormFactory::getForm('indexform', []);
71    }
72
73    /**
74     * Initialize the form elements
75     *
76     * @access protected
77     * @author Bertrand Chevrier, <bertrand.chevrier@tudor.lu>
78     * @return mixed
79     */
80    protected function initElements()
81    {
82
83        $elementNames = [];
84
85        //index part
86        $indexProperty = $this->getIndex();
87        $indexUri = tao_helpers_Uri::encode($indexProperty->getUri());
88
89        //get and add Label (Text)
90        $label = (!is_null($indexProperty)) ? $indexProperty->getLabel() : '';
91        $propIndexElt = tao_helpers_form_FormFactory::getElement(
92            "index_" . $this->prefix . "_" . tao_helpers_Uri::encode(OntologyRdfs::RDFS_LABEL),
93            'Textbox'
94        );
95        $propIndexElt->setDescription(__('Label'));
96        $propIndexElt->addAttribute('class', 'index');
97        $propIndexElt->addAttribute('data-related-index', $indexUri);
98        $propIndexElt->setValue($label);
99        $this->form->addElement($propIndexElt);
100        $elementNames[] = $propIndexElt->getName();
101
102
103        //get and add Fuzzy matching (Radiobox)
104        $fuzzyMatching = (!is_null($indexProperty))
105            ? ($indexProperty->isFuzzyMatching()) ? GenerisRdf::GENERIS_TRUE : GenerisRdf::GENERIS_FALSE
106            : '';
107        $options = [
108            tao_helpers_Uri::encode(GenerisRdf::GENERIS_TRUE)  => __('True'),
109            tao_helpers_Uri::encode(GenerisRdf::GENERIS_FALSE) => __('False')
110        ];
111        $propIndexElt = tao_helpers_form_FormFactory::getElement(
112            $this->prefix . "_" . tao_helpers_Uri::encode(OntologyIndex::PROPERTY_INDEX_FUZZY_MATCHING),
113            'Radiobox'
114        );
115        $propIndexElt->setOptions($options);
116        $propIndexElt->setDescription(__('Fuzzy Matching'));
117        $propIndexElt->addAttribute('class', 'index');
118        $propIndexElt->addAttribute('data-related-index', $indexUri);
119        $propIndexElt->setValue(tao_helpers_Uri::encode($fuzzyMatching));
120        $propIndexElt->addValidator(new tao_helpers_form_validators_NotEmpty());
121        $this->form->addElement($propIndexElt);
122        $elementNames[] = $propIndexElt->getName();
123
124        //get and add identifier (Text)
125        $identifier = (!is_null($indexProperty)) ? $indexProperty->getIdentifier() : '';
126        $propIndexElt = tao_helpers_form_FormFactory::getElement(
127            $this->prefix . "_" . tao_helpers_Uri::encode(OntologyIndex::PROPERTY_INDEX_IDENTIFIER),
128            'Textbox'
129        );
130        $propIndexElt->setDescription(__('Identifier'));
131        $propIndexElt->addAttribute('class', 'index');
132        $propIndexElt->addAttribute('data-related-index', $indexUri);
133        $propIndexElt->setValue($identifier);
134        $propIndexElt->addValidator(new tao_helpers_form_validators_IndexIdentifier());
135        $this->form->addElement($propIndexElt);
136        $elementNames[] = $propIndexElt->getName();
137
138
139        //get and add Default search
140        $defaultSearch = (!is_null($indexProperty))
141            ? ($indexProperty->isDefaultSearchable()) ? GenerisRdf::GENERIS_TRUE : GenerisRdf::GENERIS_FALSE
142            : '';
143        $options = [
144            tao_helpers_Uri::encode(GenerisRdf::GENERIS_TRUE)  => __('True'),
145            tao_helpers_Uri::encode(GenerisRdf::GENERIS_FALSE) => __('False')
146        ];
147        $propIndexElt = tao_helpers_form_FormFactory::getElement(
148            $this->prefix . "_" . tao_helpers_Uri::encode(OntologyIndex::PROPERTY_DEFAULT_SEARCH),
149            'Radiobox'
150        );
151        $propIndexElt->setOptions($options);
152        $propIndexElt->setDescription(__('Default search'));
153        $propIndexElt->addAttribute('class', 'index');
154        $propIndexElt->addAttribute('data-related-index', $indexUri);
155        $propIndexElt->setValue(tao_helpers_Uri::encode($defaultSearch));
156        $propIndexElt->addValidator(new tao_helpers_form_validators_NotEmpty());
157        $this->form->addElement($propIndexElt);
158        $elementNames[] = $propIndexElt->getName();
159
160        //get and add Tokenizer (Combobox)
161        $tokenizerRange = new \core_kernel_classes_Class('http://www.tao.lu/Ontologies/TAO.rdf#Tokenizer');
162        $options = [];
163        /** @var core_kernel_classes_Resource $value */
164        foreach ($tokenizerRange->getInstances() as $value) {
165            $options[tao_helpers_Uri::encode($value->getUri())] = $value->getLabel();
166        }
167        $tokenizer = (!is_null($indexProperty))
168            ? $indexProperty->getOnePropertyValue(
169                new \core_kernel_classes_Property(OntologyIndex::PROPERTY_INDEX_TOKENIZER)
170            )
171            : null;
172        $tokenizer = (get_class($tokenizer) === 'core_kernel_classes_Resource') ? $tokenizer->getUri() : '';
173        $propIndexElt = tao_helpers_form_FormFactory::getElement(
174            $this->prefix . "_" . tao_helpers_Uri::encode(OntologyIndex::PROPERTY_INDEX_TOKENIZER),
175            'Combobox'
176        );
177        $propIndexElt->setDescription(__('Tokenizer'));
178        $propIndexElt->addAttribute('class', 'index');
179        $propIndexElt->addAttribute('data-related-index', $indexUri);
180        $propIndexElt->setOptions($options);
181        $propIndexElt->setValue(tao_helpers_Uri::encode($tokenizer));
182        $propIndexElt->addValidator(new tao_helpers_form_validators_NotEmpty());
183        $this->form->addElement($propIndexElt);
184        $elementNames[] = $propIndexElt->getName();
185
186        $removeIndexElt = tao_helpers_form_FormFactory::getElement("index_{$indexUri}_remove", 'Free');
187        $removeIndexElt->setValue(
188            "<a href='#' id='{$indexUri}' class='btn-error index-remover small' data-index='"
189                . $indexProperty->getUri() . "'><span class='icon-remove'></span> " . __('remove index') . "</a>"
190        );
191        $this->form->addElement($removeIndexElt);
192        $elementNames[] = $removeIndexElt;
193
194        $separatorIndexElt = tao_helpers_form_FormFactory::getElement("index_" . $this->prefix . "_separator", 'Free');
195        $separatorIndexElt->setValue(
196            "<hr class='index' data-related-index='{$indexUri}'>"
197        );
198        $this->form->addElement($separatorIndexElt);
199        $elementNames[] = $separatorIndexElt;
200    }
201}