1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- /* For license terms, see /license.txt */
- use Chamilo\PluginBundle\Entity\ImsLti\ImsLtiTool;
- $cidReset = true;
- require_once __DIR__.'/../../main/inc/global.inc.php';
- api_protect_admin_script();
- $plugin = ImsLtiPlugin::create();
- $em = Database::getManager();
- $form = new FrmAdd('ism_lti_create_tool');
- $form->build();
- if ($form->validate()) {
- $formValues = $form->exportValues();
- $externalTool = new ImsLtiTool();
- $externalTool
- ->setName($formValues['name'])
- ->setDescription(
- empty($formValues['description']) ? null : $formValues['description']
- )
- ->setCustomParams(
- empty($formValues['custom_params']) ? null : $formValues['custom_params']
- )
- ->setCourse(null)
- ->setActiveDeepLinking(
- isset($formValues['deep_linking'])
- )
- ->setPrivacy(
- isset($formValues['share_name']),
- isset($formValues['share_email']),
- isset($formValues['share_picture'])
- );
- if (empty($formValues['consumer_key']) && empty($formValues['shared_secret'])) {
- try {
- $launchUrl = $plugin->getLaunchUrlFromCartridge($formValues['launch_url']);
- } catch (Exception $e) {
- Display::addFlash(
- Display::return_message($e->getMessage(), 'error')
- );
- header('Location: '.api_get_path(WEB_PLUGIN_PATH).'ims_lti/admin.php');
- exit;
- }
- $externalTool->setLaunchUrl($launchUrl);
- } else {
- $externalTool
- ->setLaunchUrl($formValues['launch_url'])
- ->setConsumerKey(
- empty($formValues['consumer_key']) ? null : $formValues['consumer_key']
- )
- ->setSharedSecret(
- empty($formValues['shared_secret']) ? null : $formValues['shared_secret']
- );
- }
- $em->persist($externalTool);
- $em->flush();
- Display::addFlash(
- Display::return_message($plugin->get_lang('ToolAdded'), 'success')
- );
- header('Location: '.api_get_path(WEB_PLUGIN_PATH).'ims_lti/admin.php');
- exit;
- }
- $form->setDefaultValues();
- $interbreadcrumb[] = ['url' => api_get_path(WEB_CODE_PATH).'admin/index.php', 'name' => get_lang('PlatformAdmin')];
- $interbreadcrumb[] = ['url' => api_get_path(WEB_PLUGIN_PATH).'ims_lti/admin.php', 'name' => $plugin->get_title()];
- $pageTitle = $plugin->get_lang('AddExternalTool');
- $template = new Template($pageTitle);
- $template->assign('form', $form->returnForm());
- $content = $template->fetch('ims_lti/view/add.tpl');
- $template->assign('header', $pageTitle);
- $template->assign('content', $content);
- $template->display_one_col_template();
|