Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 13 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| tao_actions_RestUser | |
0.00% |
0 / 13 |
|
0.00% |
0 / 3 |
56 | |
0.00% |
0 / 1 |
| getForm | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getResourceParameter | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| getClassParameter | |
0.00% |
0 / 8 |
|
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) 2017-2018 (original work) Open Assessment Technologies SA; |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | use oat\generis\model\GenerisRdf; |
| 23 | |
| 24 | /** |
| 25 | * Class tao_actions_RestUser |
| 26 | * |
| 27 | * Rest interface to manage forms to create and edit users. |
| 28 | * |
| 29 | * Request should contains following data: |
| 30 | * [ |
| 31 | * "http://www.tao.lu/Ontologies/generis.rdf#userFirstName" => "Bertrand", |
| 32 | * "http://www.tao.lu/Ontologies/generis.rdf#userLastName" => "Chevrier", |
| 33 | * "http://www.tao.lu/Ontologies/generis.rdf#userMail" => "bertrand@taotesting.com", |
| 34 | * "http://www.tao.lu/Ontologies/generis.rdf#userDefLg" => "http://www.tao.lu/Ontologies/TAO.rdf#Langfr-FR", |
| 35 | * "http://www.tao.lu/Ontologies/generis.rdf#userUILg" => "http://www.tao.lu/Ontologies/TAO.rdf#Langfr-FR", |
| 36 | * "http://www.tao.lu/Ontologies/generis.rdf#login" => "berty", |
| 37 | * "http://www.w3.org/2000/01/rdf-schema#label" => "bertounet", |
| 38 | * "http://www.tao.lu/Ontologies/generis.rdf#userRoles"=> [ |
| 39 | * 'http://www.tao.lu/Ontologies/TAOProctor.rdf#ProctorRole', |
| 40 | * 'http://www.tao.lu/Ontologies/TAO.rdf#SysAdminRole' |
| 41 | * ], |
| 42 | * 'password1' => 'ctl789@CTL789@', |
| 43 | * 'password2' => 'ctl789@CTL789@', |
| 44 | * ] |
| 45 | */ |
| 46 | class tao_actions_RestUser extends tao_actions_RestResource |
| 47 | { |
| 48 | /** |
| 49 | * Return the form object to manage user edition or creation |
| 50 | * |
| 51 | * @param $instance |
| 52 | * @return tao_actions_form_RestUserForm |
| 53 | */ |
| 54 | protected function getForm($instance) |
| 55 | { |
| 56 | return $this->propagate(new \tao_actions_form_RestUserForm($instance)); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Return the resource parameter |
| 61 | * |
| 62 | * @return core_kernel_classes_Resource |
| 63 | * @InvalidArgumentException If resource does not belong to GenerisRdf::CLASS_GENERIS_USER |
| 64 | */ |
| 65 | protected function getResourceParameter() |
| 66 | { |
| 67 | $resource = parent::getResourceParameter(); |
| 68 | if ($resource->isInstanceOf($this->getClass(GenerisRdf::CLASS_GENERIS_USER))) { |
| 69 | return $resource; |
| 70 | } |
| 71 | |
| 72 | throw new InvalidArgumentException('Only user resource are allowed.'); |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Return the class parameter |
| 77 | * |
| 78 | * @return core_kernel_classes_Resource |
| 79 | * @InvalidArgumentException If class is not an instance GenerisRdf::CLASS_GENERIS_USER |
| 80 | */ |
| 81 | protected function getClassParameter() |
| 82 | { |
| 83 | $class = parent::getClassParameter(); |
| 84 | $rootUserClass = $this->getClass(GenerisRdf::CLASS_GENERIS_USER); |
| 85 | |
| 86 | if ($class->getUri() == $rootUserClass->getUri()) { |
| 87 | return $class; |
| 88 | } |
| 89 | |
| 90 | /** @var core_kernel_classes_Class $instance */ |
| 91 | foreach ($rootUserClass->getSubClasses(true) as $instance) { |
| 92 | if ($instance->getUri() == $class->getUri()) { |
| 93 | return $class; |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | throw new InvalidArgumentException('Only user classes are allowed as classUri.'); |
| 98 | } |
| 99 | } |