Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 39 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| WizardForm | |
0.00% |
0 / 39 |
|
0.00% |
0 / 4 |
72 | |
0.00% |
0 / 1 |
| initForm | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
2 | |||
| initElements | |
0.00% |
0 / 20 |
|
0.00% |
0 / 1 |
12 | |||
| initCustomElements | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
12 | |||
| getServiceManager | |
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) 2013-2019 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\taoDeliveryRdf\view\form; |
| 23 | |
| 24 | use oat\generis\model\kernel\persistence\smoothsql\search\ComplexSearchService; |
| 25 | use oat\oatbox\service\ServiceManager; |
| 26 | use oat\taoDeliveryRdf\model\DeliveryFactory; |
| 27 | use oat\tao\model\TaoOntology; |
| 28 | use oat\taoDeliveryRdf\model\NoTestsException; |
| 29 | |
| 30 | /** |
| 31 | * Create a form from a resource of your ontology. |
| 32 | * Each property will be a field, regarding it's widget. |
| 33 | * |
| 34 | * @access public |
| 35 | * @author Bertrand Chevrier, <bertrand.chevrier@tudor.lu> |
| 36 | * @package tao |
| 37 | */ |
| 38 | class WizardForm extends \tao_helpers_form_FormContainer |
| 39 | { |
| 40 | /** |
| 41 | * @return mixed|void |
| 42 | * @throws \common_Exception |
| 43 | */ |
| 44 | protected function initForm() |
| 45 | { |
| 46 | $this->form = new \tao_helpers_form_xhtml_Form('simpleWizard'); |
| 47 | |
| 48 | $createElt = \tao_helpers_form_FormFactory::getElement('create', 'Free'); |
| 49 | $createElt->setValue( |
| 50 | '<button class="form-submitter btn-success small" type="button"><span class="icon-publish"></span> ' |
| 51 | . __('Publish') . '</button>' |
| 52 | ); |
| 53 | $this->form->setDecorators([ |
| 54 | 'actions-bottom' => new \tao_helpers_form_xhtml_TagWrapper(['tag' => 'div', 'cssClass' => 'form-toolbar']), |
| 55 | ]); |
| 56 | $this->form->setActions([], 'top'); |
| 57 | $this->form->setActions([$createElt], 'bottom'); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * @author Joel Bout, <joel.bout@tudor.lu> |
| 62 | * @return mixed|void |
| 63 | * @throws NoTestsException |
| 64 | * @throws \common_Exception |
| 65 | * @throws \common_exception_Error |
| 66 | */ |
| 67 | public function initElements() |
| 68 | { |
| 69 | $class = $this->data['class']; |
| 70 | if (!$class instanceof \core_kernel_classes_Class) { |
| 71 | throw new \common_Exception('missing class in simple delivery creation form'); |
| 72 | } |
| 73 | |
| 74 | $classUriElt = \tao_helpers_form_FormFactory::getElement('classUri', 'Hidden'); |
| 75 | $classUriElt->setValue($class->getUri()); |
| 76 | $this->form->addElement($classUriElt); |
| 77 | |
| 78 | /** @var \tao_helpers_form_elements_xhtml_Hidden $testElt */ |
| 79 | $testElt = \tao_helpers_form_FormFactory::getElement('test', 'Hidden'); |
| 80 | /** @var ComplexSearchService $search */ |
| 81 | $search = $this->getServiceManager()->get(ComplexSearchService::SERVICE_ID); |
| 82 | $queryBuilder = $search->query(); |
| 83 | $query = $search->searchType($queryBuilder, TaoOntology::TEST_CLASS_URI, true); |
| 84 | $queryBuilder->setCriteria($query); |
| 85 | |
| 86 | $count = $search->getGateway()->count($queryBuilder); |
| 87 | |
| 88 | if (0 === $count) { |
| 89 | throw new NoTestsException(); |
| 90 | } |
| 91 | |
| 92 | $selectElt = \tao_helpers_form_FormFactory::getElement('selectelt', 'Free'); |
| 93 | $selectElt->setValue('<div class="test-select-container"></div>'); |
| 94 | $this->form->addElement($selectElt); |
| 95 | |
| 96 | $testElt->addValidator(\tao_helpers_form_FormFactory::getValidator('NotEmpty')); |
| 97 | $this->form->addElement($testElt); |
| 98 | |
| 99 | $this->initCustomElements(); |
| 100 | } |
| 101 | |
| 102 | public function initCustomElements() |
| 103 | { |
| 104 | $deliveryPublishingService = $this->getServiceManager()->get(DeliveryFactory::SERVICE_ID); |
| 105 | if ($deliveryPublishingService->hasOption(DeliveryFactory::OPTION_INITIAL_PROPERTIES)) { |
| 106 | $initialProperties = $deliveryPublishingService->getOption(DeliveryFactory::OPTION_INITIAL_PROPERTIES); |
| 107 | foreach ($initialProperties as $uri) { |
| 108 | $property = new \core_kernel_classes_Property($uri); |
| 109 | $element = \tao_helpers_form_GenerisFormFactory::elementMap($property); |
| 110 | $this->form->addElement($element); |
| 111 | } |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | /**r |
| 116 | * @return ServiceManager |
| 117 | */ |
| 118 | protected function getServiceManager() |
| 119 | { |
| 120 | return ServiceManager::getServiceManager(); |
| 121 | } |
| 122 | } |