create.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /* For license terms, see /license.txt */
  3. use Chamilo\PluginBundle\Entity\ImsLti\ImsLtiTool;
  4. $cidReset = true;
  5. require_once __DIR__.'/../../main/inc/global.inc.php';
  6. api_protect_admin_script();
  7. $plugin = ImsLtiPlugin::create();
  8. $em = Database::getManager();
  9. $form = new FrmAdd('ism_lti_create_tool');
  10. $form->build();
  11. if ($form->validate()) {
  12. $formValues = $form->exportValues();
  13. $externalTool = new ImsLtiTool();
  14. $externalTool
  15. ->setName($formValues['name'])
  16. ->setDescription(
  17. empty($formValues['description']) ? null : $formValues['description']
  18. )
  19. ->setCustomParams(
  20. empty($formValues['custom_params']) ? null : $formValues['custom_params']
  21. )
  22. ->setCourse(null)
  23. ->setActiveDeepLinking(
  24. isset($formValues['deep_linking'])
  25. )
  26. ->setPrivacy(
  27. isset($formValues['share_name']),
  28. isset($formValues['share_email']),
  29. isset($formValues['share_picture'])
  30. );
  31. if (empty($formValues['consumer_key']) && empty($formValues['shared_secret'])) {
  32. try {
  33. $launchUrl = $plugin->getLaunchUrlFromCartridge($formValues['launch_url']);
  34. } catch (Exception $e) {
  35. Display::addFlash(
  36. Display::return_message($e->getMessage(), 'error')
  37. );
  38. header('Location: '.api_get_path(WEB_PLUGIN_PATH).'ims_lti/admin.php');
  39. exit;
  40. }
  41. $externalTool->setLaunchUrl($launchUrl);
  42. } else {
  43. $externalTool
  44. ->setLaunchUrl($formValues['launch_url'])
  45. ->setConsumerKey(
  46. empty($formValues['consumer_key']) ? null : $formValues['consumer_key']
  47. )
  48. ->setSharedSecret(
  49. empty($formValues['shared_secret']) ? null : $formValues['shared_secret']
  50. );
  51. }
  52. $em->persist($externalTool);
  53. $em->flush();
  54. Display::addFlash(
  55. Display::return_message($plugin->get_lang('ToolAdded'), 'success')
  56. );
  57. header('Location: '.api_get_path(WEB_PLUGIN_PATH).'ims_lti/admin.php');
  58. exit;
  59. }
  60. $form->setDefaultValues();
  61. $interbreadcrumb[] = ['url' => api_get_path(WEB_CODE_PATH).'admin/index.php', 'name' => get_lang('PlatformAdmin')];
  62. $interbreadcrumb[] = ['url' => api_get_path(WEB_PLUGIN_PATH).'ims_lti/admin.php', 'name' => $plugin->get_title()];
  63. $pageTitle = $plugin->get_lang('AddExternalTool');
  64. $template = new Template($pageTitle);
  65. $template->assign('form', $form->returnForm());
  66. $content = $template->fetch('ims_lti/view/add.tpl');
  67. $template->assign('header', $pageTitle);
  68. $template->assign('content', $content);
  69. $template->display_one_col_template();