From 2c60e2e88d7fd915bbd278b466d81be01c47f435 Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Thu, 11 Oct 2018 16:47:25 -0500 Subject: [PATCH] Ims LTI add support for deep linking - refs BT#13469 --- plugin/ims_lti/Entity/ImsLtiTool.php | 34 +++++++++++++++ plugin/ims_lti/ImsLtiPlugin.php | 2 +- plugin/ims_lti/form.php | 27 +++++++++--- plugin/ims_lti/item_return.php | 62 ++++++++++++++++++++++++++++ plugin/ims_lti/view/add.tpl | 6 ++- 5 files changed, 124 insertions(+), 7 deletions(-) create mode 100644 plugin/ims_lti/item_return.php diff --git a/plugin/ims_lti/Entity/ImsLtiTool.php b/plugin/ims_lti/Entity/ImsLtiTool.php index 6c4ba10ea0..c1c1befe5b 100644 --- a/plugin/ims_lti/Entity/ImsLtiTool.php +++ b/plugin/ims_lti/Entity/ImsLtiTool.php @@ -63,6 +63,20 @@ class ImsLtiTool * @ORM\Column(name="is_global", type="boolean") */ private $isGlobal = false; + /** + * @var bool + * + * @ORM\Column(name="active_deep_linking", type="boolean", nullable=false, options={"default": false}) + */ + private $activeDeepLinking = false; + + public function __construct() + { + $this->description = null; + $this->customParams = null; + $this->isGlobal = false; + $this->activeDeepLinking = false; + } /** * @return int @@ -218,4 +232,24 @@ class ImsLtiTool 'value' => $pairs[1] ]; } + + /** + * Set activeDeepLinking. + * + * @param bool $activeDeepLinking + */ + public function setActiveDeepLinking($activeDeepLinking) + { + $this->activeDeepLinking = $activeDeepLinking; + } + + /** + * Get activeDeepLinking. + * + * @return bool + */ + public function isActiveDeepLinking() + { + return $this->activeDeepLinking; + } } diff --git a/plugin/ims_lti/ImsLtiPlugin.php b/plugin/ims_lti/ImsLtiPlugin.php index 4aa660a8b5..71a84ea856 100644 --- a/plugin/ims_lti/ImsLtiPlugin.php +++ b/plugin/ims_lti/ImsLtiPlugin.php @@ -260,7 +260,7 @@ class ImsLtiPlugin extends Plugin } if (!api_is_allowed_to_edit(false, true)) { - return 'Learner/Learner'; + return 'Learner'; } $roles = ['Instructor']; diff --git a/plugin/ims_lti/form.php b/plugin/ims_lti/form.php index c4d59729a7..72feb52d26 100644 --- a/plugin/ims_lti/form.php +++ b/plugin/ims_lti/form.php @@ -9,7 +9,8 @@ use Chamilo\PluginBundle\Entity\ImsLti\ImsLtiTool; require_once __DIR__.'/../../main/inc/global.inc.php'; require './OAuthSimple.php'; -api_protect_course_script(); +api_protect_course_script(false); +api_block_anonymous_users(false); $em = Database::getManager(); @@ -33,11 +34,27 @@ $siteName = api_get_setting('siteName'); $toolUserId = ImsLtiPlugin::generateToolUserId($user); $params = []; -$params['lti_message_type'] = 'basic-lti-launch-request'; $params['lti_version'] = 'LTI-1p0'; -$params['resource_link_id'] = $tool->getId(); -$params['resource_link_title'] = $tool->getName(); -$params['resource_link_description'] = $tool->getDescription(); + +if ($tool->isActiveDeepLinking()) { + $params['lti_message_type'] = 'ContentItemSelectionRequest'; + $params['content_item_return_url'] = api_get_path(WEB_PLUGIN_PATH).'ims_lti/item_return.php'; + $params['accept_media_types'] = '*/*'; + $params['accept_presentation_document_targets'] = 'iframe'; + //$params['accept_unsigned']; + //$params['accept_multiple']; + //$params['accept_copy_advice']; + //$params['auto_create']'; + $params['title'] = $tool->getName(); + $params['text'] = $tool->getDescription(); + $params['data'] = 'tool:'.$tool->getId(); +} else { + $params['lti_message_type'] = 'basic-lti-launch-request'; + $params['resource_link_id'] = $tool->getId(); + $params['resource_link_title'] = $tool->getName(); + $params['resource_link_description'] = $tool->getDescription(); +} + $params['user_id'] = ImsLtiPlugin::generateToolUserId($user->getId()); $params['user_image'] = UserManager::getUserPicture($user->getId()); $params['roles'] = ImsLtiPlugin::getUserRoles($user); diff --git a/plugin/ims_lti/item_return.php b/plugin/ims_lti/item_return.php new file mode 100644 index 0000000000..27005f9d50 --- /dev/null +++ b/plugin/ims_lti/item_return.php @@ -0,0 +1,62 @@ +find('ChamiloCoreBundle:Course', api_get_course_int_id()); +/** @var Session|null $session */ +$session = $em->find('ChamiloCoreBundle:Session', api_get_session_id()); +/** @var ImsLtiTool|null $ltiTool */ +$ltiTool = $em->find('ChamiloPluginBundle:ImsLti\ImsLtiTool', $toolId); + +if (!$ltiTool) { + api_not_allowed(false); +} + +$contentItems = json_decode($_POST['content_items'], true); +$contentItems = $contentItems['@graph']; + +foreach ($contentItems as $contentItem) { + /** @var ImsLtiTool $newTool */ + $newTool = clone $ltiTool; + + switch ($contentItem['@type']) { + case 'LtiLinkItem': + $newTool + ->setName( + !empty($contentItem['title']) ? $contentItem['title'] : $ltiTool->getName() + ) + ->setDescription( + !empty($contentItem['text']) ? $contentItem['text'] : null + ) + ->setLaunchUrl( + !empty($contentItem['url']) ? $contentItem['url'] : $ltiTool->getLaunchUrl() + ) + ->setIsGlobal(false) + ->setActiveDeepLinking(false); + + $em->persist($newTool); + $em->flush(); + + $plugin->addCourseTool($course, $newTool); + + echo Display::return_message($plugin->get_lang('ToolAdded'), 'success'); + break; + } +} diff --git a/plugin/ims_lti/view/add.tpl b/plugin/ims_lti/view/add.tpl index d0f38d163b..3b577f1290 100644 --- a/plugin/ims_lti/view/add.tpl +++ b/plugin/ims_lti/view/add.tpl @@ -5,7 +5,11 @@