Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 63 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| tao_actions_form_Search | |
0.00% |
0 / 63 |
|
0.00% |
0 / 3 |
240 | |
0.00% |
0 / 1 |
| initForm | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
12 | |||
| getClassProperties | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| initElements | |
0.00% |
0 / 50 |
|
0.00% |
0 / 1 |
132 | |||
| 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 | |
| 25 | use oat\tao\model\TaoOntology; |
| 26 | |
| 27 | /** |
| 28 | * Create a form to search the resources of the ontology |
| 29 | * |
| 30 | * @access public |
| 31 | * @author Bertrand Chevrier, <bertrand.chevrier@tudor.lu> |
| 32 | * @package tao |
| 33 | |
| 34 | */ |
| 35 | class tao_actions_form_Search extends tao_actions_form_Instance |
| 36 | { |
| 37 | // --- ASSOCIATIONS --- |
| 38 | |
| 39 | |
| 40 | // --- ATTRIBUTES --- |
| 41 | |
| 42 | // --- OPERATIONS --- |
| 43 | |
| 44 | /** |
| 45 | * Initialize the form |
| 46 | * |
| 47 | * @access protected |
| 48 | * @author Bertrand Chevrier, <bertrand.chevrier@tudor.lu> |
| 49 | * @return mixed |
| 50 | */ |
| 51 | protected function initForm() |
| 52 | { |
| 53 | |
| 54 | |
| 55 | (isset($this->options['name'])) ? $name = $this->options['name'] : $name = ''; |
| 56 | if (empty($name)) { |
| 57 | $name = 'form_' . (count(self::$forms) + 1); |
| 58 | } |
| 59 | unset($this->options['name']); |
| 60 | |
| 61 | $this->form = tao_helpers_form_FormFactory::getForm($name, $this->options); |
| 62 | |
| 63 | //search action in toolbar |
| 64 | $searchElt = tao_helpers_form_FormFactory::getElement('search', 'Free'); |
| 65 | $searchElt->setValue( |
| 66 | '<button type="button" class="form-submitter btn-success small"><span class="icon-find"></span>' |
| 67 | . __('Search') . '</button>' |
| 68 | ); |
| 69 | $this->form->setActions([$searchElt], 'top'); |
| 70 | $this->form->setActions([$searchElt], 'bottom'); |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * |
| 75 | * @author Lionel Lecaque, lionel@taotesting.com |
| 76 | * @return array |
| 77 | */ |
| 78 | protected function getClassProperties() |
| 79 | { |
| 80 | return tao_helpers_form_GenerisFormFactory::getClassProperties($this->clazz, $this->getTopClazz()); |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Initialize the form elements |
| 85 | * |
| 86 | * @access protected |
| 87 | * @author Bertrand Chevrier, <bertrand.chevrier@tudor.lu> |
| 88 | * @return mixed |
| 89 | */ |
| 90 | protected function initElements() |
| 91 | { |
| 92 | |
| 93 | |
| 94 | $chainingElt = tao_helpers_form_FormFactory::getElement('chaining', 'Radiobox'); |
| 95 | $chainingElt->setDescription(__('Filtering mode')); |
| 96 | $chainingElt->setOptions(['or' => __('Exclusive (OR)'), 'and' => __('Inclusive (AND)')]); |
| 97 | $chainingElt->setValue('or'); |
| 98 | $this->form->addElement($chainingElt); |
| 99 | |
| 100 | $recursiveElt = tao_helpers_form_FormFactory::getElement('recursive', 'Checkbox'); |
| 101 | $recursiveElt->setDescription(__('Scope')); |
| 102 | $recursiveElt->setOptions(['0' => __('Search sub-classes')]); |
| 103 | $this->form->addElement($recursiveElt); |
| 104 | |
| 105 | $searchClassUriElt = tao_helpers_form_FormFactory::getElement("clazzUri", "Hidden"); |
| 106 | $searchClassUriElt->setValue(tao_helpers_Uri::encode($this->clazz->getUri())); |
| 107 | $this->form->addElement($searchClassUriElt); |
| 108 | |
| 109 | $langElt = tao_helpers_form_FormFactory::getElement('lang', 'Combobox'); |
| 110 | $langElt->setDescription(__('Language')); |
| 111 | |
| 112 | $languages = array_merge( |
| 113 | ['-- any --'], |
| 114 | tao_helpers_I18n::getAvailableLangsByUsage( |
| 115 | new core_kernel_classes_Resource(tao_models_classes_LanguageService::INSTANCE_LANGUAGE_USAGE_DATA) |
| 116 | ) |
| 117 | ); |
| 118 | $langElt->setOptions($languages); |
| 119 | $langElt->setValue(0); |
| 120 | $this->form->addElement($langElt); |
| 121 | |
| 122 | $this->form->createGroup('params', __('<del>Options</del>'), ['chaining', 'recursive', 'lang']); |
| 123 | |
| 124 | |
| 125 | $filters = []; |
| 126 | |
| 127 | $defaultProperties = tao_helpers_form_GenerisFormFactory::getDefaultProperties(); |
| 128 | $classProperties = $this->getClassProperties(); |
| 129 | |
| 130 | |
| 131 | $properties = array_merge($defaultProperties, $classProperties); |
| 132 | |
| 133 | (isset($this->options['recursive'])) ? $recursive = $this->options['recursive'] : $recursive = false; |
| 134 | if ($recursive) { |
| 135 | foreach ($this->clazz->getSubClasses(true) as $subClass) { |
| 136 | $properties = array_merge($subClass->getProperties(false), $properties); |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | foreach ($properties as $property) { |
| 141 | $element = tao_helpers_form_GenerisFormFactory::elementMap($property); |
| 142 | if ( |
| 143 | ! is_null($element) && |
| 144 | ! $element instanceof tao_helpers_form_elements_Authoring && |
| 145 | ! $element instanceof tao_helpers_form_elements_Hiddenbox && |
| 146 | ! $element instanceof tao_helpers_form_elements_Hidden |
| 147 | ) { |
| 148 | if ($element instanceof tao_helpers_form_elements_MultipleElement) { |
| 149 | $newElement = tao_helpers_form_FormFactory::getElement($element->getName(), 'Checkbox'); |
| 150 | $newElement->setDescription($element->getDescription()); |
| 151 | $newElement->setOptions($element->getOptions()); |
| 152 | $element = $newElement; |
| 153 | } |
| 154 | if ($element instanceof tao_helpers_form_elements_Htmlarea) { |
| 155 | $newElement = tao_helpers_form_FormFactory::getElement($element->getName(), 'Textarea'); |
| 156 | $newElement->setDescription($element->getDescription()); |
| 157 | $element = $newElement; |
| 158 | } |
| 159 | |
| 160 | $this->form->addElement($element); |
| 161 | $filters[] = $element->getName(); |
| 162 | } |
| 163 | } |
| 164 | $this->form->createGroup('filters', __('<del>Filters</del>'), $filters); |
| 165 | } |
| 166 | } |