Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 74 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
| taoItems_actions_SaSItems | |
0.00% |
0 / 74 |
|
0.00% |
0 / 6 |
342 | |
0.00% |
0 / 1 |
| getCurrentClass | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| sasEditInstance | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
12 | |||
| viewItem | |
0.00% |
0 / 42 |
|
0.00% |
0 / 1 |
110 | |||
| getItemClasses | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
| loadStandaloneMode | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getItemClassListService | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 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) 2002-2008 (original work) Public Research Centre Henri Tudor & University of Luxembourg |
| 19 | * (under the project TAO & TAO2); |
| 20 | * 2008-2010 (update and modification) Deutsche Institut für Internationale Pädagogische Forschung |
| 21 | * (under the project TAO-TRANSFER); |
| 22 | * 2009-2012 (update and modification) Public Research Centre Henri Tudor |
| 23 | * (under the project TAO-SUSTAIN & TAO-DEV); |
| 24 | */ |
| 25 | |
| 26 | use oat\generis\model\OntologyRdfs; |
| 27 | use oat\taoItems\model\search\ItemClassListService; |
| 28 | use tao_helpers_form_FormContainer as FormContainer; |
| 29 | |
| 30 | /** |
| 31 | * SaSItems Controller provide process services for in the Items |
| 32 | * |
| 33 | * @author Bertrand Chevrier, <taosupport@tudor.lu> |
| 34 | * @package taoItems |
| 35 | |
| 36 | * @license GPLv2 http://www.opensource.org/licenses/gpl-2.0.php |
| 37 | */ |
| 38 | class taoItems_actions_SaSItems extends taoItems_actions_Items |
| 39 | { |
| 40 | /** |
| 41 | * overrided to prevent exception: |
| 42 | * if no class is selected, the root class is returned |
| 43 | * @see TaoModule::getCurrentClass() |
| 44 | * @return core_kernel_classes_Class |
| 45 | */ |
| 46 | protected function getCurrentClass() |
| 47 | { |
| 48 | if ($this->hasRequestParameter('classUri')) { |
| 49 | return parent::getCurrentClass(); |
| 50 | } |
| 51 | return $this->getRootClass(); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Edit an instances |
| 56 | * @return void |
| 57 | */ |
| 58 | public function sasEditInstance() |
| 59 | { |
| 60 | $this->loadStandaloneMode(); |
| 61 | |
| 62 | $clazz = $this->getCurrentClass(); |
| 63 | $instance = $this->getCurrentInstance(); |
| 64 | |
| 65 | $formContainer = new tao_actions_form_Instance( |
| 66 | $clazz, |
| 67 | $instance, |
| 68 | [ |
| 69 | FormContainer::CSRF_PROTECTION_OPTION => true, |
| 70 | ] |
| 71 | ); |
| 72 | $myForm = $formContainer->getForm(); |
| 73 | |
| 74 | if ($myForm->isSubmited() && $myForm->isValid()) { |
| 75 | $binder = new tao_models_classes_dataBinding_GenerisFormDataBinder($instance); |
| 76 | $instance = $binder->bind($myForm->getValues()); |
| 77 | $instance = $this->getClassService()->setDefaultItemContent($instance); |
| 78 | $this->setData('message', __('Item saved')); |
| 79 | } |
| 80 | |
| 81 | $this->setData('uri', tao_helpers_Uri::encode($instance->getUri())); |
| 82 | $this->setData('classUri', tao_helpers_Uri::encode($clazz->getUri())); |
| 83 | $this->setData('formTitle', __('Edit item')); |
| 84 | $this->setData('myForm', $myForm->render()); |
| 85 | $this->setView('form.tpl', 'tao'); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * view and item |
| 90 | * @throws common_exception_BadRequest |
| 91 | * @throws common_exception_Error |
| 92 | * @throws tao_models_classes_MissingRequestParameterException |
| 93 | * @return void |
| 94 | */ |
| 95 | public function viewItem() |
| 96 | { |
| 97 | $this->loadStandaloneMode(); |
| 98 | |
| 99 | if (!$this->isXmlHttpRequest()) { |
| 100 | throw new common_exception_BadRequest('wrong request mode'); |
| 101 | } |
| 102 | |
| 103 | $itemClass = $this->getCurrentClass(); |
| 104 | $item = $this->getCurrentInstance(); |
| 105 | |
| 106 | $lang = null; |
| 107 | if ($this->hasRequestParameter('target_lang')) { |
| 108 | $lang = $this->getRequestParameter('target_lang'); |
| 109 | } |
| 110 | |
| 111 | $hiddenProperties = [ |
| 112 | taoItems_models_classes_ItemsService::PROPERTY_ITEM_CONTENT |
| 113 | ]; |
| 114 | |
| 115 | $properties = []; |
| 116 | foreach ($this->getClassService()->getClazzProperties($itemClass) as $property) { |
| 117 | if (in_array($property->getUri(), $hiddenProperties)) { |
| 118 | continue; |
| 119 | } |
| 120 | $range = $property->getRange(); |
| 121 | |
| 122 | if (is_null($lang)) { |
| 123 | $propValues = $item->getPropertyValues($property); |
| 124 | } else { |
| 125 | $propContainer = $item->getPropertyValuesByLg($property, $lang); |
| 126 | $propValues = $propContainer->getIterator(); |
| 127 | } |
| 128 | foreach ($propValues as $propValue) { |
| 129 | if ($range->getUri() == OntologyRdfs::RDFS_LITERAL) { |
| 130 | $value = (string)$propValue; |
| 131 | } else { |
| 132 | $resource = new core_kernel_classes_Resource($propValue); |
| 133 | $value = $resource->getLabel(); |
| 134 | } |
| 135 | $properties[] = [ |
| 136 | 'name' => $property->getLabel(), |
| 137 | 'value' => $value |
| 138 | ]; |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | $previewData = $this->initPreview($item, $itemClass); |
| 143 | if (count($previewData) == 0) { |
| 144 | $this->setData('preview', false); |
| 145 | $this->setData('previewMsg', __('Not yet available')); |
| 146 | } else { |
| 147 | $this->setData('preview', true); |
| 148 | $this->setData('instanceUri', tao_helpers_Uri::encode($item->getUri(), false)); |
| 149 | foreach ($previewData as $key => $value) { |
| 150 | $this->setData($key, $value); |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | $this->setData('uri', tao_helpers_Uri::encode($item->getUri())); |
| 155 | $this->setData('classUri', tao_helpers_Uri::encode($itemClass->getUri())); |
| 156 | |
| 157 | $this->setData('label', $item->getLabel()); |
| 158 | $this->setData('itemProperties', $properties); |
| 159 | $this->setView('view.tpl'); |
| 160 | } |
| 161 | |
| 162 | public function getItemClasses() |
| 163 | { |
| 164 | $this->returnJson( |
| 165 | $this->getItemClassListService()->getList( |
| 166 | $this->getGetParameter('q'), |
| 167 | $this->getGetParameter('page') |
| 168 | ) |
| 169 | ); |
| 170 | } |
| 171 | |
| 172 | /** |
| 173 | * Load the standalone mode |
| 174 | */ |
| 175 | protected function loadStandaloneMode() |
| 176 | { |
| 177 | tao_helpers_Context::load('STANDALONE_MODE'); |
| 178 | } |
| 179 | |
| 180 | private function getItemClassListService(): ItemClassListService |
| 181 | { |
| 182 | return $this->getServiceManager()->getContainer()->get(ItemClassListService::class); |
| 183 | } |
| 184 | } |