LTI: Add option to launch tool in iframe or window - refs BT#16379

pull/3114/head
Angel Fernando Quiroz Campos 6 years ago
parent 46d51264e6
commit f3f91a12b1
  1. 37
      plugin/ims_lti/Entity/ImsLtiTool.php
  2. 26
      plugin/ims_lti/ImsLtiPlugin.php
  3. 14
      plugin/ims_lti/README.md
  4. 4
      plugin/ims_lti/auth.php
  5. 2
      plugin/ims_lti/configure.php
  6. 1
      plugin/ims_lti/create.php
  7. 1
      plugin/ims_lti/edit.php
  8. 4
      plugin/ims_lti/form.php
  9. 6
      plugin/ims_lti/src/Form/FrmAdd.php
  10. 6
      plugin/ims_lti/src/Form/FrmEdit.php
  11. 5
      plugin/ims_lti/start.php

@ -147,6 +147,12 @@ class ImsLtiTool
* @ORM\Column(name="version", type="string", options={"default": "lti1p1"})
*/
private $version;
/**
* @var array
*
* @ORM\Column(name="launch_presentation", type="json")
*/
private $launchPresentation;
/**
* ImsLtiTool constructor.
@ -164,6 +170,9 @@ class ImsLtiTool
$this->sharedSecret = null;
$this->lineItems = new ArrayCollection();
$this->version = \ImsLti::V_1P1;
$this->launchPresentation = [
'document_target' => 'iframe',
];
}
/**
@ -794,4 +803,32 @@ class ImsLtiTool
{
return $this->children;
}
/**
* @param string $target
*
* @return $this
*/
public function setDocumenTarget($target)
{
$this->launchPresentation['document_target'] = in_array($target, ['iframe', 'window']) ? $target : 'iframe';
return $this;
}
/**
* @return string
*/
public function getDocumentTarget()
{
return $this->launchPresentation['document_target'] ?: 'iframe';
}
/**
* @return array
*/
public function getLaunchPresentation()
{
return $this->launchPresentation;
}
}

@ -31,7 +31,7 @@ class ImsLtiPlugin extends Plugin
*/
protected function __construct()
{
$version = '1.5.1';
$version = '1.7.0';
$author = 'Angel Fernando Quiroz Campos';
$message = Display::return_message($this->get_lang('GenerateKeyPairInfo'));
@ -186,6 +186,7 @@ class ImsLtiPlugin extends Plugin
redirect_url VARCHAR(255) DEFAULT NULL,
advantage_services LONGTEXT DEFAULT NULL COMMENT '(DC2Type:json)',
version VARCHAR(255) DEFAULT 'lti1p1' NOT NULL,
launch_presentation LONGTEXT NOT NULL COMMENT '(DC2Type:json),
INDEX IDX_C5E47F7C91D79BD3 (c_id),
INDEX IDX_C5E47F7C82F80D8B (gradebook_eval_id),
INDEX IDX_C5E47F7C727ACA70 (parent_id),
@ -337,19 +338,28 @@ class ImsLtiPlugin extends Plugin
}
/**
* Add the course tool
* Add the course tool.
*
* @param Course $course
* @param ImsLtiTool $tool
* @param Course $course
* @param ImsLtiTool $ltiTool
*
* @throws \Doctrine\ORM\OptimisticLockException
*/
public function addCourseTool(Course $course, ImsLtiTool $tool)
public function addCourseTool(Course $course, ImsLtiTool $ltiTool)
{
$this->createLinkToCourseTool(
$tool->getName(),
$cTool = $this->createLinkToCourseTool(
$ltiTool->getName(),
$course->getId(),
null,
self::generateToolLink($tool)
self::generateToolLink($ltiTool)
);
$cTool->setTarget(
$ltiTool->getDocumentTarget() === 'iframe' ? '_self' : '_blank'
);
$em = Database::getManager();
$em->persist($cTool);
$em->flush();
}
/**

@ -1,7 +1,7 @@
IMS/LTI plugin
===
Version 1.5.1
Version 1.7.0
> This plugin is meant to be later integrated into Chamilo (in a major version
release).
@ -24,6 +24,13 @@ external tool.
# Changelog
## v1.7
* Fix auth params
* Add option to show LTI tool in iframe or new window.
## v1.6
* Add support to LTI 1.3 and Advantage Services
## v1.5
* Plugin has passed the tests from the LTI Certification suite.
* Add support for substitution of variable.
@ -55,6 +62,11 @@ external tool.
Run this changes on database:
## To v1.7.0
```sql
ALTER TABLE plugin_ims_lti_tool ADD launch_presentation LONGTEXT NOT NULL COMMENT '(DC2Type:json)';
```
## To v1.6.0
```sql
CREATE TABLE plugin_ims_lti_platform (

@ -154,7 +154,7 @@ try {
// Launch info
$jwtContent['https://purl.imsglobal.org/spec/lti/claim/launch_presentation'] = [
'locale' => api_get_language_isocode($user->getLanguage()),
'document_target' => 'iframe',
'document_target' => $tool->getDocumentTarget(),
//'height' => 320,
//'wdith' => 240,
//'return_url' => api_get_course_url(),
@ -177,7 +177,7 @@ try {
',',
['*/*', ':::asterisk:::/:::asterisk:::']
),
'accept_presentation_document_targets' => ['iframe'],
'accept_presentation_document_targets' => ['iframe', 'window'],
'accept_multiple' => true,
'auto_create' => true,
'title' => $tool->getName(),

@ -60,6 +60,7 @@ switch ($action) {
->setCustomParams(
empty($formValues['custom_params']) ? null : $formValues['custom_params']
)
->setDocumenTarget($formValues['document_target'])
->setCourse($course)
->setPrivacy(
!empty($formValues['share_name']),
@ -188,6 +189,7 @@ switch ($action) {
->setCustomParams(
empty($formValues['custom_params']) ? null : $formValues['custom_params']
)
->setDocumenTarget($formValues['document_target'])
->setPrivacy(
!empty($formValues['share_name']),
!empty($formValues['share_email']),

@ -27,6 +27,7 @@ if ($form->validate()) {
->setCustomParams(
empty($formValues['custom_params']) ? null : $formValues['custom_params']
)
->setDocumenTarget($formValues['document_target'])
->setCourse(null)
->setActiveDeepLinking(
isset($formValues['deep_linking'])

@ -43,6 +43,7 @@ if ($form->validate()) {
->setCustomParams(
empty($formValues['custom_params']) ? null : $formValues['custom_params']
)
->setDocumenTarget($formValues['document_target'])
->setPrivacy(
!empty($formValues['share_name']),
!empty($formValues['share_email']),

@ -42,7 +42,7 @@ if ($tool->isActiveDeepLinking()) {
$params['lti_message_type'] = 'ContentItemSelectionRequest';
$params['content_item_return_url'] = $pluginPath.'item_return.php';
$params['accept_media_types'] = '*/*';
$params['accept_presentation_document_targets'] = 'iframe';
$params['accept_presentation_document_targets'] = 'iframe,window';
//$params['accept_unsigned'];
//$params['accept_multiple'];
//$params['accept_copy_advice'];
@ -99,7 +99,7 @@ $params['context_type'] = 'CourseSection';
$params['context_label'] = $course->getCode();
$params['context_title'] = $course->getTitle();
$params['launch_presentation_locale'] = api_get_language_isocode();
$params['launch_presentation_document_target'] = 'iframe';
$params['launch_presentation_document_target'] = $tool->getDocumentTarget();
$params['tool_consumer_info_product_family_code'] = 'Chamilo LMS';
$params['tool_consumer_info_version'] = api_get_version();
$params['tool_consumer_instance_guid'] = $platformDomain;

@ -81,6 +81,11 @@ class FrmAdd extends FormValidator
'custom_params',
[$plugin->get_lang('CustomParams'), $plugin->get_lang('CustomParamsHelp')]
);
$this->addSelect(
'document_target',
get_lang('LinkTarget'),
['iframe' => 'iframe', 'window' => 'window']
);
if (null === $this->baseTool ||
($this->baseTool && !$this->baseTool->isActiveDeepLinking())
@ -158,6 +163,7 @@ class FrmAdd extends FormValidator
$defaults['name'] = $this->baseTool->getName();
$defaults['description'] = $this->baseTool->getDescription();
$defaults['custom_params'] = $this->baseTool->getCustomParams();
$defaults['document_target'] = $this->baseTool->getDocumentTarget();
$defaults['share_name'] = $this->baseTool->isSharingName();
$defaults['share_email'] = $this->baseTool->isSharingEmail();
$defaults['share_picture'] = $this->baseTool->isSharingPicture();

@ -92,6 +92,11 @@ class FrmEdit extends FormValidator
'custom_params',
[$plugin->get_lang('CustomParams'), $plugin->get_lang('CustomParamsHelp')]
);
$this->addSelect(
'document_target',
get_lang('LinkTarget'),
['iframe' => 'iframe', 'window' => 'window']
);
if (null === $parent ||
(null !== $parent && !$parent->isActiveDeepLinking())
@ -187,6 +192,7 @@ class FrmEdit extends FormValidator
'redirect_url' => $this->tool->getRedirectUrl(),
'1p3_ags' => $advServices['ags'],
'1p3_nrps' => $advServices['nrps'],
'document_target' => $this->tool->getDocumentTarget(),
]
);
}

@ -33,6 +33,11 @@ if ($is1p3) {
$launchUrl = api_get_path(WEB_PLUGIN_PATH).'ims_lti/form.php?'.http_build_query(['id' => $tool->getId()]);
}
if ($tool->getDocumentTarget() == 'window') {
header("Location: $launchUrl");
exit;
}
$template = new Template($pageTitle);
$template->assign('tool', $tool);

Loading…
Cancel
Save