Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 20 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| editInstanceForm | |
0.00% |
0 / 20 |
|
0.00% |
0 / 4 |
42 | |
0.00% |
0 / 1 |
| initForm | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
6 | |||
| isEnabled | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| isReplaceEnabled | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getReplaceAssetButtonTemplate | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 | |||
| 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) 2014-2021 (original work) Open Assessment Technologies SA; |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | declare(strict_types=1); |
| 23 | |
| 24 | namespace oat\taoMediaManager\model; |
| 25 | |
| 26 | /** |
| 27 | * Service methods to manage the Media |
| 28 | * |
| 29 | * @access public |
| 30 | * @package taoMediaManager |
| 31 | */ |
| 32 | class editInstanceForm extends \tao_actions_form_Instance |
| 33 | { |
| 34 | public const IS_REPLACE_ASSET_DISABLED = 'is_replace_asset_disabled'; |
| 35 | |
| 36 | protected function initForm() |
| 37 | { |
| 38 | parent::initForm(); |
| 39 | $bottom = $this->form->getActions('bottom'); |
| 40 | $top = $this->form->getActions('top'); |
| 41 | |
| 42 | $edit = \tao_helpers_form_FormFactory::getElement('edit', 'Free'); |
| 43 | $value = $edit ? $this->getReplaceAssetButtonTemplate() : ''; |
| 44 | |
| 45 | $edit->setValue($value); |
| 46 | $top[] = $edit; |
| 47 | $bottom[] = $edit; |
| 48 | |
| 49 | $this->form->setActions($bottom, 'bottom'); |
| 50 | $this->form->setActions($top, 'top'); |
| 51 | } |
| 52 | |
| 53 | private function isEnabled(): bool |
| 54 | { |
| 55 | return empty($this->options[self::IS_DISABLED] ?? false); |
| 56 | } |
| 57 | |
| 58 | private function isReplaceEnabled(): bool |
| 59 | { |
| 60 | return empty($this->options[self::IS_REPLACE_ASSET_DISABLED] ?? false); |
| 61 | } |
| 62 | |
| 63 | private function getReplaceAssetButtonTemplate(): string |
| 64 | { |
| 65 | return sprintf( |
| 66 | '<button |
| 67 | type="button" |
| 68 | id="edit-media" %s |
| 69 | data-classuri="%s" |
| 70 | data-uri="%s" |
| 71 | class="edit-instance btn-success small"> |
| 72 | <span class="icon-loop"></span> |
| 73 | %s |
| 74 | </button>', |
| 75 | ($this->isReplaceEnabled() ? '' : 'disabled="disabled" '), |
| 76 | $this->getClazz()->getUri(), |
| 77 | $this->getInstance()->getUri(), |
| 78 | __('Replace Asset') |
| 79 | ); |
| 80 | } |
| 81 | } |