Ims LTI add support for deep linking - refs BT#13469

pull/2729/head
Angel Fernando Quiroz Campos 7 years ago
parent 385a6aed5c
commit 2c60e2e88d
  1. 34
      plugin/ims_lti/Entity/ImsLtiTool.php
  2. 2
      plugin/ims_lti/ImsLtiPlugin.php
  3. 27
      plugin/ims_lti/form.php
  4. 62
      plugin/ims_lti/item_return.php
  5. 6
      plugin/ims_lti/view/add.tpl

@ -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;
}
}

@ -260,7 +260,7 @@ class ImsLtiPlugin extends Plugin
}
if (!api_is_allowed_to_edit(false, true)) {
return 'Learner/Learner';
return 'Learner';
}
$roles = ['Instructor'];

@ -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);

@ -0,0 +1,62 @@
<?php
/* For license terms, see /license.txt */
use Chamilo\CoreBundle\Entity\Session;
use Chamilo\CoreBundle\Entity\Course;
use Chamilo\PluginBundle\Entity\ImsLti\ImsLtiTool;
require_once __DIR__.'/../../main/inc/global.inc.php';
api_protect_course_script(false);
api_block_anonymous_users(false);
if (empty($_POST['content_items']) || empty($_POST['data'])) {
api_not_allowed(false);
}
$toolId = str_replace('tool:', '', $_POST['data']);
$plugin = ImsLtiPlugin::create();
$em = Database::getManager();
/** @var Course $course */
$course = $em->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;
}
}

@ -5,7 +5,11 @@
<ul class="nav nav-pills nav-stacked">
{% for tool in tools %}
<li class="{{ type == tool.id ? 'active' : '' }}">
<a href="{{ _p.web_self }}?type={{ tool.id }}&{{ _p.web_cid_query }}">{{ tool.name }}</a>
{% if tool.isActiveDeepLinking %}
<a href="{{ _p.web_plugin }}ims_lti/start.php?id={{ tool.id }}&{{ _p.web_cid_query }}">{{ tool.name }}</a>
{% else %}
<a href="{{ _p.web_self }}?type={{ tool.id }}&{{ _p.web_cid_query }}">{{ tool.name }}</a>
{% endif %}
</li>
{% endfor %}
</ul>

Loading…
Cancel
Save