Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 13 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| AddClassPropertyFormFactory | |
0.00% |
0 / 13 |
|
0.00% |
0 / 2 |
6 | |
0.00% |
0 / 1 |
| add | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
2 | |||
| isAdvancedSearchEnabled | |
0.00% |
0 / 2 |
|
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) 2021 (original work) Open Assessment Technologies SA; |
| 19 | */ |
| 20 | |
| 21 | declare(strict_types=1); |
| 22 | |
| 23 | namespace oat\tao\model\ClassProperty; |
| 24 | |
| 25 | use tao_helpers_form_Form as Form; |
| 26 | use oat\generis\model\OntologyAwareTrait; |
| 27 | use oat\oatbox\service\ConfigurableService; |
| 28 | use Psr\Http\Message\ServerRequestInterface; |
| 29 | use tao_helpers_form_FormContainer as FormContainer; |
| 30 | use tao_actions_form_SimpleProperty as SimpleProperty; |
| 31 | use oat\tao\model\AdvancedSearch\AdvancedSearchChecker; |
| 32 | |
| 33 | class AddClassPropertyFormFactory extends ConfigurableService |
| 34 | { |
| 35 | use OntologyAwareTrait; |
| 36 | |
| 37 | public function add(ServerRequestInterface $request, bool $hasWriteAccess): ?Form |
| 38 | { |
| 39 | $parsedBody = $request->getParsedBody(); |
| 40 | |
| 41 | $class = $this->getClass($parsedBody['id']); |
| 42 | $index = ($parsedBody['index'] ?? count($class->getProperties(false))) + 1; |
| 43 | |
| 44 | $options = [ |
| 45 | 'index' => $index, |
| 46 | 'disableIndexChanges' => $this->isAdvancedSearchEnabled(), |
| 47 | FormContainer::IS_DISABLED => !$hasWriteAccess, |
| 48 | ]; |
| 49 | |
| 50 | $newProperty = $class->createProperty('Property_' . $index); |
| 51 | |
| 52 | $propFormContainer = new SimpleProperty($class, $newProperty, $options); |
| 53 | |
| 54 | return $propFormContainer->getForm(); |
| 55 | } |
| 56 | |
| 57 | private function isAdvancedSearchEnabled(): bool |
| 58 | { |
| 59 | /** @var AdvancedSearchChecker $advancedSearchChecker */ |
| 60 | $advancedSearchChecker = $this->getServiceLocator()->get(AdvancedSearchChecker::class); |
| 61 | |
| 62 | return $advancedSearchChecker->isEnabled(); |
| 63 | } |
| 64 | } |