Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 39 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| Groups | |
0.00% |
0 / 39 |
|
0.00% |
0 / 4 |
56 | |
0.00% |
0 / 1 |
| getClassService | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| editGroup | |
0.00% |
0 / 36 |
|
0.00% |
0 / 1 |
20 | |||
| moveResource | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getDependsOnPropertyValidator | |
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 | * 2013-2023 (update and modification) Open Assessment Technologies SA |
| 25 | */ |
| 26 | |
| 27 | namespace oat\taoGroups\controller; |
| 28 | |
| 29 | use common_exception_Error; |
| 30 | use common_exception_MethodNotAllowed; |
| 31 | use common_ext_ExtensionException; |
| 32 | use common_ext_ExtensionsManager; |
| 33 | use oat\oatbox\validator\ValidatorInterface; |
| 34 | use oat\tao\model\controller\SignedFormInstance; |
| 35 | use oat\tao\model\Lists\Business\Validation\DependsOnPropertyValidator; |
| 36 | use oat\tao\model\resources\ResourceWatcher; |
| 37 | use oat\taoDeliveryRdf\helper\DeliveryWidget; |
| 38 | use oat\taoGroups\models\GroupsService; |
| 39 | use tao_actions_SaSModule; |
| 40 | use tao_helpers_form_FormContainer as FormContainer; |
| 41 | use tao_helpers_form_GenerisTreeForm; |
| 42 | use tao_helpers_Uri; |
| 43 | use tao_models_classes_dataBinding_GenerisFormDataBinder; |
| 44 | use tao_models_classes_dataBinding_GenerisFormDataBindingException; |
| 45 | use tao_models_classes_MissingRequestParameterException; |
| 46 | |
| 47 | /** |
| 48 | * This Module aims at managing the Group class and its instances. |
| 49 | * |
| 50 | * @author Bertrand Chevrier, <bertrand@taotesting.com> |
| 51 | * |
| 52 | * @package taoGroups |
| 53 | * |
| 54 | * @license GPLv2 http://www.opensource.org/licenses/gpl-2.0.php |
| 55 | */ |
| 56 | class Groups extends tao_actions_SaSModule |
| 57 | { |
| 58 | /** |
| 59 | * (non-PHPdoc) |
| 60 | * |
| 61 | * @see tao_actions_SaSModule::getClassService() |
| 62 | */ |
| 63 | protected function getClassService() |
| 64 | { |
| 65 | return GroupsService::singleton(); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Edit a group instance |
| 70 | * |
| 71 | * @throws common_exception_Error |
| 72 | * @throws common_ext_ExtensionException |
| 73 | * @throws \oat\tao\model\security\SecurityException |
| 74 | * @throws tao_models_classes_MissingRequestParameterException |
| 75 | * @throws tao_models_classes_dataBinding_GenerisFormDataBindingException |
| 76 | * |
| 77 | * @return void |
| 78 | */ |
| 79 | public function editGroup() |
| 80 | { |
| 81 | $this->defaultData(); |
| 82 | |
| 83 | $clazz = $this->getCurrentClass(); |
| 84 | $group = $this->getCurrentInstance(); |
| 85 | |
| 86 | $formContainer = new SignedFormInstance( |
| 87 | $clazz, |
| 88 | $group, |
| 89 | [ |
| 90 | FormContainer::CSRF_PROTECTION_OPTION => true, |
| 91 | FormContainer::ATTRIBUTE_VALIDATORS => [ |
| 92 | 'data-depends-on-property' => [ |
| 93 | $this->getDependsOnPropertyValidator(), |
| 94 | ], |
| 95 | ], |
| 96 | ] |
| 97 | ); |
| 98 | $myForm = $formContainer->getForm(); |
| 99 | |
| 100 | if ($myForm->isSubmited() && $myForm->isValid()) { |
| 101 | $this->validateInstanceRoot($group->getUri()); |
| 102 | |
| 103 | $binder = new tao_models_classes_dataBinding_GenerisFormDataBinder($group); |
| 104 | $group = $binder->bind($myForm->getValues()); |
| 105 | |
| 106 | $this->setData('selectNode', tao_helpers_Uri::encode($group->getUri())); |
| 107 | $this->setData('selectNode', tao_helpers_Uri::encode($group->getUri())); |
| 108 | $this->setData('message', __('Group saved')); |
| 109 | $this->setData('reload', true); |
| 110 | } |
| 111 | |
| 112 | $memberProperty = $this->getProperty(GroupsService::PROPERTY_MEMBERS_URI); |
| 113 | $memberForm = tao_helpers_form_GenerisTreeForm::buildReverseTree($group, $memberProperty); |
| 114 | $memberForm->setData('title', __('Select group test takers')); |
| 115 | |
| 116 | $memberForm->setData('saveUrl', _url('setReverseValues', 'TestTakerGenerisTree', 'taoTestTaker')); |
| 117 | |
| 118 | $this->setData('memberForm', $memberForm->render()); |
| 119 | |
| 120 | if ($this->getServiceLocator()->get(common_ext_ExtensionsManager::SERVICE_ID)->isEnabled('taoDeliveryRdf')) { |
| 121 | $this->setData('deliveryForm', DeliveryWidget::renderDeliveryTree($group)); |
| 122 | } |
| 123 | $updatedAt = $this->getServiceLocator()->get(ResourceWatcher::SERVICE_ID)->getUpdatedAt($group); |
| 124 | $this->setData('updatedAt', $updatedAt); |
| 125 | $this->setData('formTitle', __('Edit group')); |
| 126 | $this->setData('myForm', $myForm->render()); |
| 127 | $this->setView('form_group.tpl'); |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * @throws common_exception_Error |
| 132 | * @throws common_exception_MethodNotAllowed |
| 133 | * |
| 134 | * @requiresRight classUri WRITE |
| 135 | */ |
| 136 | public function moveResource() |
| 137 | { |
| 138 | parent::moveResource(); |
| 139 | } |
| 140 | |
| 141 | private function getDependsOnPropertyValidator(): ValidatorInterface |
| 142 | { |
| 143 | return $this->getPsrContainer()->get(DependsOnPropertyValidator::class); |
| 144 | } |
| 145 | } |