From d41323365e024b55b79377236998264e0d1da5a8 Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Wed, 14 Nov 2018 11:41:09 -0500 Subject: [PATCH 01/10] WIP fixing lti plugin - refs BT#13469 --- plugin/ims_lti/Entity/ImsLtiTool.php | 20 ++++++++++++++++++++ plugin/ims_lti/ImsLtiPlugin.php | 7 +++++++ plugin/ims_lti/configure.php | 4 +++- plugin/ims_lti/form.php | 10 +++++++--- plugin/ims_lti/src/Form/FrmAdd.php | 5 +++-- plugin/ims_lti/src/Form/FrmEdit.php | 7 ++++--- plugin/ims_lti/view/start.tpl | 2 +- 7 files changed, 45 insertions(+), 10 deletions(-) diff --git a/plugin/ims_lti/Entity/ImsLtiTool.php b/plugin/ims_lti/Entity/ImsLtiTool.php index 12bce88a29..1d4e05f25c 100644 --- a/plugin/ims_lti/Entity/ImsLtiTool.php +++ b/plugin/ims_lti/Entity/ImsLtiTool.php @@ -249,6 +249,26 @@ class ImsLtiTool return $this->course === null; } + /** + * @param array $params + * + * @return null|string + */ + public function encodeCustomParams(array $params) + { + if (empty($params)) { + return null; + } + + $pairs = []; + + foreach ($params as $key => $value) { + $pairs[] = "$key=$value"; + } + + return implode("\n", $pairs); + } + /** * @return array */ diff --git a/plugin/ims_lti/ImsLtiPlugin.php b/plugin/ims_lti/ImsLtiPlugin.php index 9c81379aac..b51cfe9578 100644 --- a/plugin/ims_lti/ImsLtiPlugin.php +++ b/plugin/ims_lti/ImsLtiPlugin.php @@ -394,6 +394,13 @@ class ImsLtiPlugin extends Plugin !empty($contentItem['text']) ? $contentItem['text'] : null ); + if (!empty($contentItem['custom'])) { + $newLtiTool + ->setCustomParams( + $newLtiTool->encodeCustomParams($contentItem['custom']) + ); + } + $em->persist($newLtiTool); $em->flush(); diff --git a/plugin/ims_lti/configure.php b/plugin/ims_lti/configure.php index b562f0d8bf..f9eb22f986 100644 --- a/plugin/ims_lti/configure.php +++ b/plugin/ims_lti/configure.php @@ -126,7 +126,9 @@ switch ($action) { $tool ->setName($formValues['name']) - ->setDescription($formValues['description']) + ->setDescription( + empty($formValues['description']) ? null : $formValues['description'] + ) ->setActiveDeepLinking( !empty($formValues['deep_linking']) ) diff --git a/plugin/ims_lti/form.php b/plugin/ims_lti/form.php index 247efc620e..43cf8a3d8c 100644 --- a/plugin/ims_lti/form.php +++ b/plugin/ims_lti/form.php @@ -82,7 +82,7 @@ $params['roles'] = ImsLtiPlugin::getUserRoles($user); if ($tool->isSharingName()) { $params['lis_person_name_given'] = $user->getFirstname(); $params['lis_person_name_family'] = $user->getLastname(); - $params['lis_person_name_full'] = $user->getCompleteName(); + $params['lis_person_name_full'] = $user->getFirstname().' '.$user->getLastname(); } if ($tool->isSharingEmail()) { @@ -90,7 +90,11 @@ if ($tool->isSharingEmail()) { } if (api_is_allowed_to_edit(false, true)) { - $params['role_scope_mentor'] = ImsLtiPlugin::getRoleScopeMentor($course, $session); + $scopeMentor = ImsLtiPlugin::getRoleScopeMentor($course, $session); + + if (!empty($scopeMentor)) { + $params['role_scope_mentor'] = $scopeMentor; + } } $params['context_id'] = $course->getId(); @@ -132,7 +136,7 @@ $result = $oauth->sign(array( encType="application/x-www-form-urlencoded"> $values) { //Dump parameters - echo ''; + echo ''.PHP_EOL; } ?>