edit.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. if (!isset($_REQUEST['id'])) {
  8. api_not_allowed(true);
  9. }
  10. $toolId = intval($_REQUEST['id']);
  11. $plugin = ImsLtiPlugin::create();
  12. $em = Database::getManager();
  13. /** @var ImsLtiTool $tool */
  14. $tool = $em->find('ChamiloPluginBundle:ImsLti\ImsLtiTool', $toolId);
  15. if (!$tool) {
  16. Display::addFlash(
  17. Display::return_message($plugin->get_lang('NoTool'), 'error')
  18. );
  19. header('Location: '.api_get_path(WEB_PLUGIN_PATH).'ims_lti/admin.php');
  20. exit;
  21. }
  22. $form = new FrmEdit('ims_lti_edit_tool', [], $tool);
  23. $form->build();
  24. if ($form->validate()) {
  25. $formValues = $form->exportValues();
  26. $tool
  27. ->setName($formValues['name'])
  28. ->setDescription(
  29. empty($formValues['description']) ? null : $formValues['description']
  30. )
  31. ->setCustomParams(
  32. empty($formValues['custom_params']) ? null : $formValues['custom_params']
  33. )
  34. ->setPrivacy(
  35. !empty($formValues['share_name']),
  36. !empty($formValues['share_email']),
  37. !empty($formValues['share_picture'])
  38. );
  39. if (null === $tool->getParent()) {
  40. $tool
  41. ->setLaunchUrl($formValues['launch_url'])
  42. ->setConsumerKey(
  43. empty($formValues['consumer_key']) ? null : $formValues['consumer_key']
  44. )
  45. ->setSharedSecret(
  46. empty($formValues['shared_secret']) ? null : $formValues['shared_secret']
  47. );
  48. }
  49. if (null === $tool->getParent() ||
  50. (null !== $tool->getParent() && !$tool->getParent()->isActiveDeepLinking())
  51. ) {
  52. $tool->setActiveDeepLinking(!empty($formValues['deep_linking']));
  53. }
  54. $em->persist($tool);
  55. $em->flush();
  56. Display::addFlash(
  57. Display::return_message($plugin->get_lang('ToolEdited'), 'success')
  58. );
  59. header('Location: '.api_get_path(WEB_PLUGIN_PATH).'ims_lti/admin.php');
  60. exit;
  61. }
  62. $form->setDefaultValues();
  63. $interbreadcrumb[] = ['url' => api_get_path(WEB_CODE_PATH).'admin/index.php', 'name' => get_lang('PlatformAdmin')];
  64. $interbreadcrumb[] = ['url' => api_get_path(WEB_PLUGIN_PATH).'ims_lti/admin.php', 'name' => $plugin->get_title()];
  65. $template = new Template($plugin->get_lang('EditExternalTool'));
  66. $template->assign('form', $form->returnForm());
  67. $content = $template->fetch('ims_lti/view/add.tpl');
  68. $template->assign('header', $plugin->get_title());
  69. $template->assign('content', $content);
  70. $template->display_one_col_template();