Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 33 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| LinkConfiguration | |
0.00% |
0 / 33 |
|
0.00% |
0 / 4 |
90 | |
0.00% |
0 / 1 |
| selectDelivery | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
12 | |||
| setDelivery | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| configureDelivery | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
6 | |||
| showDelivery | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
12 | |||
| 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\helpers\UrlHelper; |
| 27 | use oat\taoDelivery\model\execution\ServiceProxy; |
| 28 | use oat\taoLti\models\classes\LtiLaunchData; |
| 29 | use oat\taoLti\models\classes\LtiService; |
| 30 | use tao_actions_CommonModule; |
| 31 | use core_kernel_classes_Resource; |
| 32 | use core_kernel_classes_Property; |
| 33 | use oat\taoDeliveryRdf\model\DeliveryAssemblyService; |
| 34 | |
| 35 | /** |
| 36 | * Allows instructors to configure the LTI remote_link |
| 37 | * |
| 38 | * @author CRP Henri Tudor - TAO Team - {@link http://www.tao.lu} |
| 39 | * @license GPLv2 http://www.opensource.org/licenses/gpl-2.0.php |
| 40 | * @package ltiDeliveryProvider |
| 41 | |
| 42 | */ |
| 43 | class LinkConfiguration extends tao_actions_CommonModule |
| 44 | { |
| 45 | /** |
| 46 | * Displays the form to select a delivery |
| 47 | * |
| 48 | * @throws \common_Exception |
| 49 | * @throws \common_exception_Error |
| 50 | * @throws \oat\taoLti\models\classes\LtiException |
| 51 | * @throws \oat\taoLti\models\classes\LtiVariableMissingException |
| 52 | */ |
| 53 | protected function selectDelivery() |
| 54 | { |
| 55 | |
| 56 | $ltiSession = LtiService::singleton()->getLtiSession(); |
| 57 | if ($ltiSession->getLaunchData()->hasVariable(LtiLaunchData::RESOURCE_LINK_TITLE)) { |
| 58 | $this->setData('linkTitle', $ltiSession->getLaunchData()->getVariable(LtiLaunchData::RESOURCE_LINK_TITLE)); |
| 59 | } |
| 60 | $this->setData('link', $ltiSession->getLtiLinkResource()->getUri()); |
| 61 | $this->setData('submitUrl', _url('setDelivery')); |
| 62 | |
| 63 | $deliveries = DeliveryAssemblyService::singleton()->getAllAssemblies(); |
| 64 | if (count($deliveries) > 0) { |
| 65 | $this->setData('deliveries', $deliveries); |
| 66 | $this->setView('instructor/selectDelivery.tpl'); |
| 67 | } else { |
| 68 | $this->returnError(__('No deliveries available')); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * called onSelect of a delivery |
| 74 | */ |
| 75 | public function setDelivery() |
| 76 | { |
| 77 | $link = new core_kernel_classes_Resource($this->getRequestParameter('link')); |
| 78 | $compiled = new core_kernel_classes_Resource($this->getRequestParameter('uri')); |
| 79 | $link->editPropertyValues(new core_kernel_classes_Property(LTIDeliveryTool::PROPERTY_LINK_DELIVERY), $compiled); |
| 80 | $this->redirect(_url('showDelivery', null, null, ['uri' => $compiled->getUri()])); |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Either displays the currently associated delivery |
| 85 | * or calls selectDelivery in order to allow the user to select a delivery |
| 86 | * |
| 87 | * Only accessible to LTI instructors |
| 88 | */ |
| 89 | public function configureDelivery() |
| 90 | { |
| 91 | $compiledDelivery = $this->getServiceLocator()->get(LTIDeliveryTool::class)->getDeliveryFromLink(); |
| 92 | if (is_null($compiledDelivery)) { |
| 93 | $this->selectDelivery(); |
| 94 | } else { |
| 95 | $showDeliveryUrl = $this->getServiceLocator()->get(UrlHelper::class)->buildUrl( |
| 96 | 'showDelivery', |
| 97 | null, |
| 98 | null, |
| 99 | ['uri' => $compiledDelivery->getUri()] |
| 100 | ); |
| 101 | |
| 102 | $this->redirect($showDeliveryUrl); |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * Displays the currently associated delivery |
| 108 | * |
| 109 | * Only accessible to LTI instructors |
| 110 | * @throws \common_exception_Error |
| 111 | * @throws \common_exception_NoImplementation |
| 112 | * @throws \oat\taoLti\models\classes\LtiException |
| 113 | * @throws \oat\taoLti\models\classes\LtiVariableMissingException |
| 114 | */ |
| 115 | public function showDelivery() |
| 116 | { |
| 117 | $delivery = new core_kernel_classes_Resource($this->getRequestParameter('uri')); |
| 118 | $this->setData('delivery', $delivery); |
| 119 | |
| 120 | $ltiSession = LtiService::singleton()->getLtiSession(); |
| 121 | if ($ltiSession->getLaunchData()->hasVariable(LtiLaunchData::RESOURCE_LINK_TITLE)) { |
| 122 | $this->setData('linkTitle', $ltiSession->getLaunchData()->getVariable(LtiLaunchData::RESOURCE_LINK_TITLE)); |
| 123 | } |
| 124 | |
| 125 | if (ServiceProxy::singleton()->implementsMonitoring()) { |
| 126 | $executions = ServiceProxy::singleton()->getExecutionsByDelivery($delivery); |
| 127 | $this->setData('executionCount', count($executions)); |
| 128 | } |
| 129 | |
| 130 | $this->setView('instructor/viewDelivery.tpl'); |
| 131 | } |
| 132 | } |