Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
76.92% |
10 / 13 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| DependencyPropertyWidgetSpecification | |
76.92% |
10 / 13 |
|
0.00% |
0 / 1 |
7.60 | |
0.00% |
0 / 1 |
| isSatisfiedBy | |
76.92% |
10 / 13 |
|
0.00% |
0 / 1 |
7.60 | |||
| 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) 2021 (original work) Open Assessment Technologies SA; |
| 19 | */ |
| 20 | |
| 21 | declare(strict_types=1); |
| 22 | |
| 23 | namespace oat\tao\helpers\form\Specification; |
| 24 | |
| 25 | use oat\tao\helpers\form\elements\xhtml\SearchDropdown; |
| 26 | use oat\tao\helpers\form\elements\xhtml\SearchTextBox; |
| 27 | use tao_helpers_form_elements_Combobox; |
| 28 | |
| 29 | class DependencyPropertyWidgetSpecification |
| 30 | { |
| 31 | public const DEPENDENT_SINGLE_RESTRICTED_TYPES = [ |
| 32 | tao_helpers_form_elements_Combobox::WIDGET_ID, |
| 33 | SearchDropdown::WIDGET_ID |
| 34 | ]; |
| 35 | |
| 36 | public function isSatisfiedBy( |
| 37 | string $targetWidgetUri, |
| 38 | string $selectedWidgetUri, |
| 39 | string $previewsWidget = null |
| 40 | ): bool { |
| 41 | if ($previewsWidget === null) { |
| 42 | if (in_array($selectedWidgetUri, self::DEPENDENT_SINGLE_RESTRICTED_TYPES, true)) { |
| 43 | return in_array($targetWidgetUri, self::DEPENDENT_SINGLE_RESTRICTED_TYPES, true); |
| 44 | } |
| 45 | |
| 46 | if ($selectedWidgetUri === SearchTextBox::WIDGET_ID) { |
| 47 | return $targetWidgetUri === SearchTextBox::WIDGET_ID; |
| 48 | } |
| 49 | |
| 50 | return false; |
| 51 | } |
| 52 | |
| 53 | if ($previewsWidget === $targetWidgetUri) { |
| 54 | return true; |
| 55 | } |
| 56 | |
| 57 | if (in_array($previewsWidget, self::DEPENDENT_SINGLE_RESTRICTED_TYPES, true)) { |
| 58 | return in_array($targetWidgetUri, self::DEPENDENT_SINGLE_RESTRICTED_TYPES, true); |
| 59 | } |
| 60 | |
| 61 | if ($previewsWidget === SearchTextBox::WIDGET_ID) { |
| 62 | return $targetWidgetUri === SearchTextBox::WIDGET_ID; |
| 63 | } |
| 64 | |
| 65 | return false; |
| 66 | } |
| 67 | } |