Differences Between: [Versions 310 and 402] [Versions 311 and 402] [Versions 39 and 402]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle 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 Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Renderer class for LTI enrolment 19 * 20 * @package enrol_lti 21 * @copyright 2016 John Okely <john@moodle.com> 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 namespace enrol_lti\output; 26 27 defined('MOODLE_INTERNAL') || die(); 28 29 use core\output\notification; 30 use enrol_lti\local\ltiadvantage\repository\application_registration_repository; 31 use enrol_lti\local\ltiadvantage\repository\deployment_repository; 32 use Packback\Lti1p3\LtiMessageLaunch; 33 use plugin_renderer_base; 34 35 /** 36 * Renderer class for LTI enrolment 37 * 38 * @package enrol_lti 39 * @copyright 2016 John Okely <john@moodle.com> 40 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 41 */ 42 class renderer extends plugin_renderer_base { 43 /** 44 * Render the enrol_lti/proxy_registration template 45 * 46 * @param registration $registration The registration renderable 47 * @return string html for the page 48 */ 49 public function render_registration(registration $registration) { 50 $data = $registration->export_for_template($this); 51 return parent::render_from_template("enrol_lti/proxy_registration", $data); 52 } 53 54 /** 55 * Render the content item selection (deep linking 2.0) view 56 * 57 * This view is a form containing a list of courses and modules which, once selected and submitted, will result in 58 * a list of LTI Resource Link Content Items being sent back to the platform, allowing resource link creation to 59 * take place. 60 * 61 * @param LtiMessageLaunch $launch the launch data. 62 * @param array $resources array of published resources available to the current user. 63 * @return string html 64 */ 65 public function render_published_resource_selection_view(LtiMessageLaunch $launch, array $resources): string { 66 global $CFG; 67 $context = [ 68 'action' => $CFG->wwwroot . '/enrol/lti/configure.php', 69 'launchid' => $launch->getLaunchId(), 70 'hascontent' => !empty($resources), 71 'sesskey' => sesskey(), 72 'courses' => [] 73 ]; 74 foreach ($resources as $resource) { 75 $context['courses'][$resource->get_courseid()]['fullname'] = $resource->get_coursefullname(); 76 if (!$resource->is_course()) { 77 $context['courses'][$resource->get_courseid()]['modules'][] = [ 78 'name' => $resource->get_name(), 79 'id' => $resource->get_id(), 80 'lineitem' => $resource->supports_grades() 81 ]; 82 if (empty($context['courses'][$resource->get_courseid()]['shared_course'])) { 83 $context['courses'][$resource->get_courseid()]['shared_course'] = false; 84 } 85 } else { 86 $context['courses'][$resource->get_courseid()]['shared_course'] = $resource->is_course(); 87 $context['courses'][$resource->get_courseid()]['id'] = $resource->get_id(); 88 $context['courses'][$resource->get_courseid()]['lineitem'] = $resource->supports_grades(); 89 } 90 } 91 $context['courses'] = array_values($context['courses']); // Reset keys for use in the template. 92 return parent::render_from_template('enrol_lti/local/ltiadvantage/content_select', $context); 93 } 94 95 /** 96 * Render the table applications which have been registered as LTI Advantage platforms. 97 * 98 * @param array $registrations The list of registrations to render. 99 * @return string the html. 100 */ 101 public function render_admin_setting_registered_platforms(array $registrations): string { 102 $registrationscontext = [ 103 'registrations' => [], 104 'addurl' => (new \moodle_url('/enrol/lti/register_platform.php', ['action' => 'add']))->out(false), 105 ]; 106 $registrationscontext['hasregs'] = count($registrations) > 0; 107 108 $deploymentrepository = new deployment_repository(); 109 foreach ($registrations as $reg) { 110 $countdeployments = $deploymentrepository->count_by_registration($reg->get_id()); 111 $status = get_string('registrationstatuspending', 'enrol_lti'); 112 if ($reg->is_complete()) { 113 $status = get_string('registrationstatusactive', 'enrol_lti'); 114 } 115 $registrationscontext['registrations'][] = [ 116 'name' => $reg->get_name(), 117 'issuer' => $reg->get_platformid(), 118 'clientid' => $reg->get_clientid(), 119 'hasdeployments' => $countdeployments > 0, 120 'countdeployments' => $countdeployments, 121 'isactive' => $reg->is_complete(), 122 'statusstring' => $status, 123 'tooldetailsurl' => (new \moodle_url('/enrol/lti/register_platform.php', 124 ['action' => 'view', 'regid' => $reg->get_id(), 'tabselect' => 'tooldetails']))->out(false), 125 'platformdetailsurl' => (new \moodle_url('/enrol/lti/register_platform.php', 126 ['action' => 'view', 'regid' => $reg->get_id(), 'tabselect' => 'platformdetails']))->out(false), 127 'deploymentsurl' => (new \moodle_url('/enrol/lti/register_platform.php', 128 ['action' => 'view', 'regid' => $reg->get_id(), 'tabselect' => 'tooldeployments']))->out(false), 129 'deleteurl' => (new \moodle_url('/enrol/lti/register_platform.php', 130 ['action' => 'delete', 'regid' => $reg->get_id()]))->out(false) 131 ]; 132 } 133 134 // Notice to let users know this is LTI Advantage ONLY. 135 $versionnotice = new notification( 136 get_string('registeredplatformsltiversionnotice', 'enrol_lti'), 137 notification::NOTIFY_INFO 138 ); 139 $versionnotice->set_show_closebutton(false); 140 141 $return = parent::render($versionnotice); 142 $return .= parent::render_from_template('enrol_lti/local/ltiadvantage/registered_platforms', 143 $registrationscontext); 144 return $return; 145 } 146 147 /** 148 * Renders the registration view page, allowing admins to view tool details, platform details and deployments. 149 * 150 * The template uses dynamic tabs, which renders with one active tab and uses js to change tabs if desired. E.g. if an anchor 151 * link is used to go to another tab, the page will first load the active tab, then switch to the tab referenced in the anchor 152 * using JS. To allow navigation to the page with a specific tab selected, and WITHOUT the js slowdown, this renderer method 153 * allows callers to specify which tab is set as the active tab during first render. 154 * Valid values correspond to the tab names in the enrol_lti/local/ltiadvantage/registration_view template, currently: 155 * - 'tooldetails' - to render with the Tool details tab as the active tab 156 * - 'platformdetails' - to render with the Platform details tab as the active tab 157 * - 'tooldeployments' - to render with the Tool deployments tab as the active tab 158 * By default, the platformdetails tab will be selected as active. 159 * 160 * @param int $registrationid the id of the registration to display information for. 161 * @param string $activetab a string identifying the tab to preselect when rendering. 162 * @return bool|string 163 * @throws \coding_exception 164 * @throws \moodle_exception 165 */ 166 public function render_registration_view(int $registrationid, string $activetab = '') { 167 global $CFG; 168 $validtabvals = ['tooldetails', 'platformdetails', 'tooldeployments']; 169 $activetab = !empty($activetab) && in_array($activetab, $validtabvals) ? $activetab : 'platformdetails'; 170 $regrepo = new application_registration_repository(); 171 $registration = $regrepo->find($registrationid); 172 173 $deploymentrepo = new deployment_repository(); 174 $deployments = $deploymentrepo->find_all_by_registration($registration->get_id()); 175 $deploymentscontext = []; 176 foreach ($deployments as $deployment) { 177 $deploymentscontext[] = [ 178 'name' => $deployment->get_deploymentname(), 179 'deploymentid' => $deployment->get_deploymentid(), 180 'deleteurl' => (new \moodle_url( 181 '/enrol/lti/manage_deployment.php', 182 ['action' => 'delete', 'id' => $deployment->get_id(), 'registrationid' => $registration->get_id()] 183 ))->out(false) 184 ]; 185 } 186 187 $regurl = new \moodle_url('/enrol/lti/register.php', ['token' => $registration->get_uniqueid()]); 188 189 $tcontext = [ 190 'tool_details_active' => $activetab == 'tooldetails', 191 'platform_details_active' => $activetab == 'platformdetails', 192 'tool_deployments_active' => $activetab == 'tooldeployments', 193 'back_url' => (new \moodle_url('/admin/settings.php', ['section' => 'enrolsettingslti_registrations']))->out(false), 194 'dynamic_registration_info' => get_string( 195 'registrationurlinfomessage', 196 'enrol_lti', 197 get_docs_url('Publish_as_LTI_tool') 198 ), 199 'dynamic_registration_url' => [ 200 'name' => get_string('registrationurl', 'enrol_lti'), 201 'url' => $regurl, 202 'id' => uniqid() 203 ], 204 'manual_registration_info' => get_string('endpointltiversionnotice', 'enrol_lti'), 205 'manual_registration_urls' => [ 206 [ 207 'name' => get_string('toolurl', 'enrol_lti'), 208 'url' => $CFG->wwwroot . '/enrol/lti/launch.php', 209 'id' => uniqid() 210 ], 211 [ 212 'name' => get_string('loginurl', 'enrol_lti'), 213 'url' => $CFG->wwwroot . '/enrol/lti/login.php?id=' . $registration->get_uniqueid(), 214 'id' => uniqid() 215 ], 216 [ 217 'name' => get_string('jwksurl', 'enrol_lti'), 218 'url' => $CFG->wwwroot . '/enrol/lti/jwks.php', 219 'id' => uniqid() 220 ], 221 [ 222 'name' => get_string('deeplinkingurl', 'enrol_lti'), 223 'url' => $CFG->wwwroot . '/enrol/lti/launch_deeplink.php', 224 'id' => uniqid() 225 ], 226 ], 227 'platform_details_info' => get_string('platformdetailsinfo', 'enrol_lti'), 228 'platform_details' => [ 229 [ 230 'name' => get_string('registerplatform:name', 'enrol_lti'), 231 'value' => $registration->get_name() 232 ], 233 [ 234 'name' => get_string('registerplatform:platformid', 'enrol_lti'), 235 'value' => $registration->get_platformid() ?? '', 236 ], 237 [ 238 'name' => get_string('registerplatform:clientid', 'enrol_lti'), 239 'value' => $registration->get_clientid() ?? '', 240 ], 241 [ 242 'name' => get_string('registerplatform:authrequesturl', 'enrol_lti'), 243 'value' => $registration->get_authenticationrequesturl() ?? '', 244 ], 245 [ 246 'name' => get_string('registerplatform:jwksurl', 'enrol_lti'), 247 'value' => $registration->get_jwksurl() ?? '', 248 ], 249 [ 250 'name' => get_string('registerplatform:accesstokenurl', 'enrol_lti'), 251 'value' => $registration->get_accesstokenurl() ?? '', 252 ] 253 ], 254 'edit_platform_details_url' => (new \moodle_url('/enrol/lti/register_platform.php', 255 ['action' => 'edit', 'regid' => $registration->get_id()]))->out(false), 256 'deployments_info' => get_string('deploymentsinfo', 'enrol_lti'), 257 'has_deployments' => !empty($deploymentscontext), 258 'tool_deployments' => $deploymentscontext, 259 'add_deployment_url' => (new \moodle_url('/enrol/lti/manage_deployment.php', 260 ['action' => 'add', 'registrationid' => $registrationid]))->out(false) 261 ]; 262 263 return parent::render_from_template('enrol_lti/local/ltiadvantage/registration_view', 264 $tcontext); 265 } 266 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body