item_return.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /* For license terms, see /license.txt */
  3. use Chamilo\CoreBundle\Entity\Course;
  4. use Chamilo\PluginBundle\Entity\ImsLti\ImsLtiTool;
  5. require_once __DIR__.'/../../main/inc/global.inc.php';
  6. api_protect_course_script(false);
  7. api_block_anonymous_users(false);
  8. if (empty($_POST['content_items']) || empty($_POST['data'])) {
  9. api_not_allowed(false);
  10. }
  11. $toolId = str_replace('tool:', '', $_POST['data']);
  12. $plugin = ImsLtiPlugin::create();
  13. $em = Database::getManager();
  14. /** @var Course $course */
  15. $course = $em->find('ChamiloCoreBundle:Course', api_get_course_int_id());
  16. /** @var ImsLtiTool|null $ltiTool */
  17. $ltiTool = $em->find('ChamiloPluginBundle:ImsLti\ImsLtiTool', $toolId);
  18. if (!$ltiTool) {
  19. api_not_allowed(false);
  20. }
  21. $contentItems = json_decode($_POST['content_items'], true);
  22. $contentItems = $contentItems['@graph'];
  23. foreach ($contentItems as $contentItem) {
  24. if ('LtiLinkItem' === $contentItem['@type']) {
  25. if ('application/vnd.ims.lti.v1.ltilink' === $contentItem['mediaType']) {
  26. $plugin->saveItemAsLtiLink($contentItem, $ltiTool, $course);
  27. Display::addFlash(
  28. Display::return_message($plugin->get_lang('ToolAdded'), 'success')
  29. );
  30. }
  31. }
  32. }
  33. $currentUrl = api_get_path(WEB_PLUGIN_PATH).'ims_lti/start.php?id='.$ltiTool->getId();
  34. ?>
  35. <!DOCTYPE html>
  36. <html>
  37. <head>
  38. <meta charset="UTF-8">
  39. <meta name="viewport"
  40. content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  41. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  42. <title>Document</title>
  43. </head>
  44. <body>
  45. <script>
  46. window.parent.location.href = '<?php echo $currentUrl ?>';
  47. </script>
  48. </body>
  49. </html>