Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 49 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| DeliveryForm | |
0.00% |
0 / 49 |
|
0.00% |
0 / 3 |
90 | |
0.00% |
0 / 1 |
| initForm | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
| initElements | |
0.00% |
0 / 29 |
|
0.00% |
0 / 1 |
20 | |||
| setThemeNameSelectorOptions | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
20 | |||
| 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 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\taoDeliveryRdf\view\form; |
| 23 | |
| 24 | use oat\tao\model\controller\SignedFormInstance; |
| 25 | use oat\taoDeliveryRdf\model\DeliveryContainerService; |
| 26 | use oat\oatbox\service\ServiceManager; |
| 27 | use oat\tao\model\theme\ThemeService; |
| 28 | use oat\taoDeliveryRdf\model\theme\DeliveryThemeDetailsProvider; |
| 29 | use tao_helpers_form_FormFactory; |
| 30 | use tao_helpers_Uri; |
| 31 | |
| 32 | /** |
| 33 | * Create a form from a resource of your ontology. |
| 34 | * Each property will be a field, regarding it's widget. |
| 35 | * |
| 36 | * @access public |
| 37 | * @package taoDelivery |
| 38 | |
| 39 | */ |
| 40 | class DeliveryForm extends SignedFormInstance |
| 41 | { |
| 42 | protected function initForm() |
| 43 | { |
| 44 | parent::initForm(); |
| 45 | |
| 46 | $saveELt = tao_helpers_form_FormFactory::getElement('Save', 'Free'); |
| 47 | $saveELt->setValue( |
| 48 | '<button class="form-submitter btn-success small" type="button"><span class="icon-save"></span>' |
| 49 | . __('Save') . '</button>' |
| 50 | ); |
| 51 | $this->form->setActions([], 'top'); |
| 52 | $this->form->setActions([$saveELt], 'bottom'); |
| 53 | } |
| 54 | |
| 55 | protected function initElements() |
| 56 | { |
| 57 | parent::initElements(); |
| 58 | $maxExecElt = $this->form->getElement(tao_helpers_Uri::encode(DeliveryContainerService::PROPERTY_MAX_EXEC)); |
| 59 | if (! is_null($maxExecElt)) { |
| 60 | $maxExecElt->addValidators([ |
| 61 | tao_helpers_form_FormFactory::getValidator('Integer', [ |
| 62 | 'min' => 1 |
| 63 | ]) |
| 64 | ]); |
| 65 | $this->form->addElement($maxExecElt); |
| 66 | } |
| 67 | |
| 68 | $periodEndElt = $this->form->getElement(tao_helpers_Uri::encode(DeliveryContainerService::PROPERTY_END)); |
| 69 | if (! is_null($periodEndElt)) { |
| 70 | $periodEndElt->addValidators([ |
| 71 | tao_helpers_form_FormFactory::getValidator('DateTime', [ |
| 72 | 'comparator' => '>=', |
| 73 | 'datetime2_ref' => $this->form->getElement( |
| 74 | tao_helpers_Uri::encode(DeliveryContainerService::PROPERTY_START) |
| 75 | ), |
| 76 | ]) |
| 77 | ]); |
| 78 | $this->form->addElement($periodEndElt); |
| 79 | } |
| 80 | |
| 81 | $resultServerElt = $this->form->getElement( |
| 82 | tao_helpers_Uri::encode(DeliveryContainerService::PROPERTY_RESULT_SERVER) |
| 83 | ); |
| 84 | |
| 85 | if (! is_null($resultServerElt)) { |
| 86 | $resultServerElt->addValidators([ |
| 87 | tao_helpers_form_FormFactory::getValidator('NotEmpty') |
| 88 | ]); |
| 89 | $this->form->addElement($resultServerElt); |
| 90 | } |
| 91 | |
| 92 | $this->setThemeNameSelectorOptions(); |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Sets the theme name selector options. |
| 97 | * |
| 98 | * @return bool |
| 99 | */ |
| 100 | protected function setThemeNameSelectorOptions() |
| 101 | { |
| 102 | $elementUri = tao_helpers_Uri::encode(DeliveryThemeDetailsProvider::DELIVERY_THEME_ID_URI); |
| 103 | if (!$this->form->hasElement($elementUri)) { |
| 104 | return false; |
| 105 | } |
| 106 | |
| 107 | /** @var ThemeService $themeService */ |
| 108 | $themeService = ServiceManager::getServiceManager()->get(ThemeService::SERVICE_ID); |
| 109 | $allThemes = $themeService->getAllThemes(); |
| 110 | $options = []; |
| 111 | foreach ($allThemes as $currentThemeId => $currentTheme) { |
| 112 | $options[$currentThemeId] = $currentThemeId; |
| 113 | if (method_exists($currentTheme, 'getLabel')) { |
| 114 | $options[$currentThemeId] = $currentTheme->getLabel(); |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | $this->form->getElement($elementUri)->setOptions($options); |
| 119 | |
| 120 | return true; |
| 121 | } |
| 122 | } |