LTI: Fix forms to add/edit tool

pull/3065/head
Angel Fernando Quiroz Campos 6 years ago
parent 4659f8feb0
commit 6004db18e2
  1. 48
      plugin/ims_lti/configure.php
  2. 1
      plugin/ims_lti/create.php
  3. 41
      plugin/ims_lti/edit.php
  4. 1
      plugin/ims_lti/lang/english.php
  5. 46
      plugin/ims_lti/src/Form/FrmEdit.php

@ -68,24 +68,40 @@ switch ($action) {
);
if (!$baseTool) {
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_self().'?'.api_get_cidreq());
exit;
}
$tool->setLaunchUrl($launchUrl);
} else {
if (ImsLti::V_1P3 === $formValues['version']) {
$tool
->setVersion(ImsLti::V_1P3)
->setLaunchUrl($formValues['launch_url'])
->setConsumerKey($formValues['consumer_key'])
->setSharedSecret($formValues['shared_secret']);
->setClientId(
ImsLti::generateClientId()
)
->setLoginUrl($formValues['login_url'])
->setRedirectUrl($formValues['redirect_url'])
->setAdvantageServices(
[
'ags' => $formValues['1p3_ags'],
]
);
} elseif (ImsLti::V_1P1 === $formValues['version']) {
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_self().'?'.api_get_cidreq());
exit;
}
$tool->setLaunchUrl($launchUrl);
} else {
$tool
->setLaunchUrl($formValues['launch_url'])
->setConsumerKey($formValues['consumer_key'])
->setSharedSecret($formValues['shared_secret']);
}
}
}

@ -39,6 +39,7 @@ if ($form->validate()) {
if (ImsLti::V_1P3 === $formValues['version']) {
$externalTool
->setVersion(ImsLti::V_1P3)
->setLaunchUrl($formValues['launch_url'])
->setClientId(
ImsLti::generateClientId()

@ -50,14 +50,22 @@ if ($form->validate()) {
);
if (null === $tool->getParent()) {
$tool
->setLaunchUrl($formValues['launch_url'])
->setConsumerKey(
empty($formValues['consumer_key']) ? null : $formValues['consumer_key']
)
->setSharedSecret(
empty($formValues['shared_secret']) ? null : $formValues['shared_secret']
);
$tool->setLaunchUrl($formValues['launch_url']);
if ($tool->getVersion() === ImsLti::V_1P1) {
$tool
->setConsumerKey(
empty($formValues['consumer_key']) ? null : $formValues['consumer_key']
)
->setSharedSecret(
empty($formValues['shared_secret']) ? null : $formValues['shared_secret']
);
} elseif ($tool->getVersion() === ImsLti::V_1P3) {
$tool
->setLoginUrl($formValues['login_url'])
->setRedirectUrl($formValues['redirect_url'])
->publicKey = $formValues['public_key'];
}
}
if (null === $tool->getParent() ||
@ -66,6 +74,19 @@ if ($form->validate()) {
$tool->setActiveDeepLinking(!empty($formValues['deep_linking']));
}
if (null == $tool->getParent()) {
/** @var ImsLtiTool $child */
foreach ($tool->getChildren() as $child) {
$child
->setLaunchUrl($tool->getLaunchUrl())
->setLoginUrl($tool->getLoginUrl())
->setRedirectUrl($tool->getRedirectUrl())
->publicKey = $tool->publicKey;
$em->persist($child);
}
}
$em->persist($tool);
$em->flush();
@ -75,10 +96,10 @@ if ($form->validate()) {
header('Location: '.api_get_path(WEB_PLUGIN_PATH).'ims_lti/admin.php');
exit;
} else {
$form->setDefaultValues();
}
$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()];

@ -42,6 +42,7 @@ $strings['NoAccessToUrl'] = 'No access to URL';
$strings['LaunchUrlNotFound'] = 'Launch URL not found';
$strings['GenerateKeyPairInfo'] = 'A new private and public key pair will be created when enabling.';
$strings['PlatformKeys'] = 'Platform keys';
$strings['ClientId'] = 'Client ID';
$strings['Keys'] = 'Keys';
$strings['KeyId'] = 'Key ID';
$strings['PublicKey'] = 'Public key';

@ -57,11 +57,33 @@ class FrmEdit extends FormValidator
$this->addText('name', get_lang('Name'));
$this->addTextarea('description', get_lang('Description'));
$this->addRadio(
'version',
$plugin->get_lang('LtiVersion'),
[
ImsLti::V_1P1 => 'LTI 1.0 / 1.1',
ImsLti::V_1P3 => 'LTI 1.3.0',
]
);
$this->freeze(['version']);
if (null === $parent) {
$this->addUrl('launch_url', $plugin->get_lang('LaunchUrl'), true);
$this->addText('consumer_key', $plugin->get_lang('ConsumerKey'), false);
$this->addText('shared_secret', $plugin->get_lang('SharedSecret'), false);
if ($this->tool->getVersion() === ImsLti::V_1P1) {
$this->addText('consumer_key', $plugin->get_lang('ConsumerKey'), false);
$this->addText('shared_secret', $plugin->get_lang('SharedSecret'), false);
} elseif ($this->tool->getVersion() === ImsLti::V_1P3) {
$this->addText('client_id', $plugin->get_lang('ClientId'), true);
$this->freeze(['client_id']);
$this->addTextarea(
'public_key',
$plugin->get_lang('PublicKey'),
['style' => 'font-family: monospace;', 'rows' => 5],
true
);
$this->addUrl('login_url', $plugin->get_lang('LoginUrl'));
$this->addUrl('redirect_url', $plugin->get_lang('RedirectUrl'));
}
}
$this->addButtonAdvancedSettings('lti_adv');
@ -81,6 +103,18 @@ class FrmEdit extends FormValidator
);
}
if (null === $parent && $this->tool->getVersion() === ImsLti::V_1P3) {
$this->addRadio(
'1p3_ags',
$plugin->get_lang('AssigmentAndGradesService'),
[
LtiAssignmentGradesService::AGS_NONE => $plugin->get_lang('DontUseService'),
LtiAssignmentGradesService::AGS_SIMPLE => $plugin->get_lang('AGServiceSimple'),
LtiAssignmentGradesService::AGS_FULL => $plugin->get_lang('AGServiceFull'),
]
);
}
$this->addHtml('</div>');
$this->addButtonAdvancedSettings('lti_privacy', get_lang('Privacy'));
$this->addHtml('<div id="lti_privacy_options" style="display:none;">');
@ -96,6 +130,8 @@ class FrmEdit extends FormValidator
public function setDefaultValues()
{
$advServices = $this->tool->getAdvantageServices();
$this->setDefaults(
[
'name' => $this->tool->getName(),
@ -108,6 +144,12 @@ class FrmEdit extends FormValidator
'share_name' => $this->tool->isSharingName(),
'share_email' => $this->tool->isSharingEmail(),
'share_picture' => $this->tool->isSharingPicture(),
'version' => $this->tool->getVersion(),
'client_id' => $this->tool->getClientId(),
'public_key' => $this->tool->publicKey,
'login_url' => $this->tool->getLoginUrl(),
'redirect_url' => $this->tool->getRedirectUrl(),
'1p3_ags' => $advServices['ags']
]
);
}

Loading…
Cancel
Save