Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 18 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| DeliveryRestService | |
0.00% |
0 / 18 |
|
0.00% |
0 / 1 |
30 | |
0.00% |
0 / 1 |
| getUrl | |
0.00% |
0 / 18 |
|
0.00% |
0 / 1 |
30 | |||
| 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 | |
| 23 | namespace oat\ltiDeliveryProvider\controller; |
| 24 | |
| 25 | use oat\ltiDeliveryProvider\model\LTIDeliveryTool; |
| 26 | use oat\tao\model\TaoOntology; |
| 27 | |
| 28 | /** |
| 29 | * LTI Delivery REST API |
| 30 | */ |
| 31 | class DeliveryRestService extends \tao_actions_RestController |
| 32 | { |
| 33 | /** |
| 34 | * return a LTI link URI from a valid delivery id |
| 35 | * @author Christophe GARCIA <christopheg@taotesing.com> |
| 36 | */ |
| 37 | public function getUrl() |
| 38 | { |
| 39 | try { |
| 40 | if ($this->getRequestMethod() != \Request::HTTP_GET) { |
| 41 | throw new \common_exception_NotImplemented('Only GET method is accepted to request this service.'); |
| 42 | } |
| 43 | |
| 44 | if (!$this->hasRequestParameter('deliveryId')) { |
| 45 | $this->returnFailure( |
| 46 | new \common_exception_MissingParameter( |
| 47 | 'At least one mandatory parameter was required but found missing in your request' |
| 48 | ) |
| 49 | ); |
| 50 | } |
| 51 | |
| 52 | $selectedDelivery = new \core_kernel_classes_Resource($this->getRequestParameter('deliveryId')); |
| 53 | if (!$selectedDelivery->isInstanceOf(new \core_kernel_classes_Class(TaoOntology::CLASS_URI_DELIVERY))) { |
| 54 | $this->returnFailure(new \common_exception_NotFound('Delivery not found')); |
| 55 | } |
| 56 | |
| 57 | $this->returnSuccess( |
| 58 | $this->getServiceLocator()->get(LTIDeliveryTool::class)->getLaunchUrl( |
| 59 | ['delivery' => $selectedDelivery->getUri()] |
| 60 | ) |
| 61 | ); |
| 62 | } catch (\Exception $ex) { |
| 63 | $this->returnFailure($ex); |
| 64 | } |
| 65 | } |
| 66 | } |