Actualización
This commit is contained in:
239
plugin/ims_lti/src/Form/FrmAdd.php
Normal file
239
plugin/ims_lti/src/Form/FrmAdd.php
Normal file
@@ -0,0 +1,239 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
namespace Chamilo\PluginBundle\ImsLti\Form;
|
||||
|
||||
use Category;
|
||||
use Chamilo\PluginBundle\Entity\ImsLti\ImsLtiTool;
|
||||
use Display;
|
||||
use FormValidator;
|
||||
use ImsLti;
|
||||
use ImsLtiPlugin;
|
||||
use LtiAssignmentGradesService;
|
||||
use LtiNamesRoleProvisioningService;
|
||||
|
||||
/**
|
||||
* Class FrmAdd.
|
||||
*/
|
||||
class FrmAdd extends FormValidator
|
||||
{
|
||||
/**
|
||||
* @var ImsLtiTool|null
|
||||
*/
|
||||
private $baseTool;
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $toolIsV1p3;
|
||||
|
||||
/**
|
||||
* FrmAdd constructor.
|
||||
*
|
||||
* @param string $name
|
||||
* @param array $attributes
|
||||
*/
|
||||
public function __construct(
|
||||
$name,
|
||||
$attributes = [],
|
||||
ImsLtiTool $tool = null
|
||||
) {
|
||||
parent::__construct($name, 'POST', '', '', $attributes, self::LAYOUT_HORIZONTAL, true);
|
||||
|
||||
$this->baseTool = $tool;
|
||||
$this->toolIsV1p3 = $this->baseTool
|
||||
&& !empty($this->baseTool->publicKey)
|
||||
&& !empty($this->baseTool->getClientId())
|
||||
&& !empty($this->baseTool->getLoginUrl())
|
||||
&& !empty($this->baseTool->getRedirectUrl());
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form.
|
||||
*/
|
||||
public function build()
|
||||
{
|
||||
$plugin = ImsLtiPlugin::create();
|
||||
|
||||
$this->addHeader($plugin->get_lang('ToolSettings'));
|
||||
$this->addText('name', get_lang('Name'));
|
||||
$this->addTextarea('description', get_lang('Description'));
|
||||
|
||||
if (null === $this->baseTool) {
|
||||
$this->addUrl('launch_url', $plugin->get_lang('LaunchUrl'), true);
|
||||
$this->addRadio(
|
||||
'version',
|
||||
$plugin->get_lang('LtiVersion'),
|
||||
[
|
||||
ImsLti::V_1P1 => 'LTI 1.0 / 1.1',
|
||||
ImsLti::V_1P3 => 'LTI 1.3.0',
|
||||
]
|
||||
);
|
||||
$this->addHtml('<div class="'.ImsLti::V_1P1.'" style="display: none;">');
|
||||
$this->addText('consumer_key', $plugin->get_lang('ConsumerKey'), false);
|
||||
$this->addText('shared_secret', $plugin->get_lang('SharedSecret'), false);
|
||||
$this->addHtml('</div>');
|
||||
$this->addHtml('<div class="'.ImsLti::V_1P3.'" style="display: block;">');
|
||||
$this->addRadio(
|
||||
'public_key_type',
|
||||
$plugin->get_lang('PublicKeyType'),
|
||||
[
|
||||
ImsLti::LTI_JWK_KEYSET => $plugin->get_lang('KeySetUrl'),
|
||||
ImsLti::LTI_RSA_KEY => $plugin->get_lang('RsaKey'),
|
||||
]
|
||||
);
|
||||
$this->addHtml('<div class="'.ImsLti::LTI_JWK_KEYSET.'" style="display: block;">');
|
||||
$this->addUrl('jwks_url', $plugin->get_lang('PublicKeyset'), false);
|
||||
$this->addHtml('</div>');
|
||||
$this->addHtml('<div class="'.ImsLti::LTI_RSA_KEY.'" style="display: none;">');
|
||||
$this->addTextarea(
|
||||
'public_key',
|
||||
$plugin->get_lang('PublicKey'),
|
||||
['style' => 'font-family: monospace;', 'rows' => 5]
|
||||
);
|
||||
$this->addHtml('</div>');
|
||||
$this->addUrl('login_url', $plugin->get_lang('LoginUrl'), false);
|
||||
$this->addUrl('redirect_url', $plugin->get_lang('RedirectUrl'), false);
|
||||
$this->addHtml('</div>');
|
||||
}
|
||||
|
||||
$this->addButtonAdvancedSettings('lti_adv');
|
||||
$this->addHtml('<div id="lti_adv_options" style="display:none;">');
|
||||
$this->addTextarea(
|
||||
'custom_params',
|
||||
[$plugin->get_lang('CustomParams'), $plugin->get_lang('CustomParamsHelp')]
|
||||
);
|
||||
$this->addSelect(
|
||||
'document_target',
|
||||
get_lang('LinkTarget'),
|
||||
['iframe' => 'iframe', 'window' => 'window']
|
||||
);
|
||||
|
||||
if (null === $this->baseTool
|
||||
|| ($this->baseTool && !$this->baseTool->isActiveDeepLinking())
|
||||
) {
|
||||
$this->addCheckBox(
|
||||
'deep_linking',
|
||||
[null, $plugin->get_lang('SupportDeppLinkingHelp'), null],
|
||||
$plugin->get_lang('SupportDeepLinking')
|
||||
);
|
||||
}
|
||||
|
||||
$showAGS = false;
|
||||
|
||||
if (api_get_course_int_id()) {
|
||||
$caterories = Category::load(null, null, api_get_course_id());
|
||||
|
||||
if (!empty($caterories)) {
|
||||
$showAGS = true;
|
||||
}
|
||||
} else {
|
||||
$showAGS = true;
|
||||
}
|
||||
|
||||
$this->addHtml('<div class="'.ImsLti::V_1P3.'" style="display: none;">');
|
||||
|
||||
if ($showAGS) {
|
||||
$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'),
|
||||
]
|
||||
);
|
||||
} else {
|
||||
$gradebookUrl = api_get_path(WEB_CODE_PATH).'gradebook/index.php?'.api_get_cidreq();
|
||||
|
||||
$this->addLabel(
|
||||
$plugin->get_lang('AssigmentAndGradesService'),
|
||||
sprintf(
|
||||
$plugin->get_lang('YouNeedCreateTheGradebokInCourseFirst'),
|
||||
Display::url($gradebookUrl, $gradebookUrl)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$this->addRadio(
|
||||
'1p3_nrps',
|
||||
$plugin->get_lang('NamesAndRoleProvisioningService'),
|
||||
[
|
||||
LtiNamesRoleProvisioningService::NRPS_NONE => $plugin->get_lang('DontUseService'),
|
||||
LtiNamesRoleProvisioningService::NRPS_CONTEXT_MEMBERSHIP => $plugin->get_lang('UseService'),
|
||||
]
|
||||
);
|
||||
$this->addHtml('</div>');
|
||||
|
||||
if (!$this->baseTool) {
|
||||
$this->addText(
|
||||
'replacement_user_id',
|
||||
[
|
||||
$plugin->get_lang('ReplacementUserId'),
|
||||
$plugin->get_lang('ReplacementUserIdHelp'),
|
||||
],
|
||||
false
|
||||
);
|
||||
$this->applyFilter('replacement_user_id', 'trim');
|
||||
}
|
||||
|
||||
$this->addHtml('</div>');
|
||||
$this->addButtonAdvancedSettings('lti_privacy', get_lang('Privacy'));
|
||||
$this->addHtml('<div id="lti_privacy_options" style="display:none;">');
|
||||
$this->addCheckBox('share_name', null, $plugin->get_lang('ShareLauncherName'));
|
||||
$this->addCheckBox('share_email', null, $plugin->get_lang('ShareLauncherEmail'));
|
||||
$this->addCheckBox('share_picture', null, $plugin->get_lang('ShareLauncherPicture'));
|
||||
$this->addHtml('</div>');
|
||||
$this->addButtonCreate($plugin->get_lang('AddExternalTool'));
|
||||
$this->applyFilter('__ALL__', 'trim');
|
||||
}
|
||||
|
||||
public function setDefaultValues()
|
||||
{
|
||||
$defaults = [];
|
||||
$defaults['version'] = ImsLti::V_1P3;
|
||||
$defaults['public_key_type'] = ImsLti::LTI_JWK_KEYSET;
|
||||
|
||||
if ($this->baseTool) {
|
||||
$defaults['name'] = $this->baseTool->getName();
|
||||
$defaults['description'] = $this->baseTool->getDescription();
|
||||
$defaults['custom_params'] = $this->baseTool->getCustomParams();
|
||||
$defaults['document_target'] = $this->baseTool->getDocumentTarget();
|
||||
$defaults['share_name'] = $this->baseTool->isSharingName();
|
||||
$defaults['share_email'] = $this->baseTool->isSharingEmail();
|
||||
$defaults['share_picture'] = $this->baseTool->isSharingPicture();
|
||||
$defaults['public_key'] = $this->baseTool->publicKey;
|
||||
$defaults['login_url'] = $this->baseTool->getLoginUrl();
|
||||
$defaults['redirect_url'] = $this->baseTool->getRedirectUrl();
|
||||
|
||||
if ($this->toolIsV1p3) {
|
||||
$advServices = $this->baseTool->getAdvantageServices();
|
||||
|
||||
$defaults['1p3_ags'] = $advServices['ags'];
|
||||
$defaults['1p3_nrps'] = $advServices['nrps'];
|
||||
}
|
||||
}
|
||||
|
||||
$this->setDefaults($defaults);
|
||||
}
|
||||
|
||||
public function returnForm(): string
|
||||
{
|
||||
$js = "<script>
|
||||
\$(function () {
|
||||
\$('[name=\"version\"]').on('change', function () {
|
||||
$('.".ImsLti::V_1P1.", .".ImsLti::V_1P3."').hide();
|
||||
|
||||
$('.' + this.value).show();
|
||||
})
|
||||
\$('[name=\"public_key_type\"]').on('change', function () {
|
||||
$('.".ImsLti::LTI_JWK_KEYSET.", .".ImsLti::LTI_RSA_KEY."').hide();
|
||||
$('[name=\"public_key\"], [name=\"jwks_url\"]').val('');
|
||||
|
||||
$('.' + this.value).show();
|
||||
})
|
||||
});
|
||||
</script>";
|
||||
|
||||
return $js.parent::returnForm(); // TODO: Change the autogenerated stub
|
||||
}
|
||||
}
|
||||
224
plugin/ims_lti/src/Form/FrmEdit.php
Normal file
224
plugin/ims_lti/src/Form/FrmEdit.php
Normal file
@@ -0,0 +1,224 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
namespace Chamilo\PluginBundle\Form;
|
||||
|
||||
use Category;
|
||||
use Chamilo\PluginBundle\Entity\ImsLti\ImsLtiTool;
|
||||
use Display;
|
||||
use Exception;
|
||||
use FormValidator;
|
||||
use ImsLti;
|
||||
use ImsLtiPlugin;
|
||||
use LtiAssignmentGradesService;
|
||||
use LtiNamesRoleProvisioningService;
|
||||
|
||||
/**
|
||||
* Class FrmAdd.
|
||||
*/
|
||||
class FrmEdit extends FormValidator
|
||||
{
|
||||
/**
|
||||
* @var ImsLtiTool|null
|
||||
*/
|
||||
private $tool;
|
||||
|
||||
/**
|
||||
* FrmAdd constructor.
|
||||
*
|
||||
* @param string $name
|
||||
* @param array $attributes
|
||||
*/
|
||||
public function __construct(
|
||||
$name,
|
||||
$attributes = [],
|
||||
ImsLtiTool $tool = null
|
||||
) {
|
||||
parent::__construct($name, 'POST', '', '', $attributes, self::LAYOUT_HORIZONTAL, true);
|
||||
|
||||
$this->tool = $tool;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form.
|
||||
*
|
||||
* @param bool $globalMode
|
||||
*/
|
||||
public function build($globalMode = true)
|
||||
{
|
||||
$plugin = ImsLtiPlugin::create();
|
||||
$course = $this->tool->getCourse();
|
||||
$parent = $this->tool->getParent();
|
||||
|
||||
$this->addHeader($plugin->get_lang('ToolSettings'));
|
||||
|
||||
if (null !== $course && $globalMode) {
|
||||
$this->addHtml(
|
||||
Display::return_message(
|
||||
sprintf($plugin->get_lang('ToolAddedOnCourseX'), $course->getTitle()),
|
||||
'normal',
|
||||
false
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$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);
|
||||
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']);
|
||||
if (!empty($this->tool->getJwksUrl())) {
|
||||
$this->addUrl('jwks_url', $plugin->get_lang('PublicKeyset'));
|
||||
} else {
|
||||
$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');
|
||||
$this->addHtml('<div id="lti_adv_options" style="display:none;">');
|
||||
$this->addTextarea(
|
||||
'custom_params',
|
||||
[$plugin->get_lang('CustomParams'), $plugin->get_lang('CustomParamsHelp')]
|
||||
);
|
||||
$this->addSelect(
|
||||
'document_target',
|
||||
get_lang('LinkTarget'),
|
||||
['iframe' => 'iframe', 'window' => 'window']
|
||||
);
|
||||
|
||||
if (null === $parent
|
||||
|| (null !== $parent && !$parent->isActiveDeepLinking())
|
||||
) {
|
||||
$this->addCheckBox(
|
||||
'deep_linking',
|
||||
[null, $plugin->get_lang('SupportDeppLinkingHelp'), null],
|
||||
$plugin->get_lang('SupportDeepLinking')
|
||||
);
|
||||
}
|
||||
|
||||
if (null === $parent && $this->tool->getVersion() === ImsLti::V_1P3) {
|
||||
$showAGS = false;
|
||||
|
||||
if (api_get_course_int_id()) {
|
||||
$caterories = Category::load(null, null, api_get_course_id());
|
||||
|
||||
if (!empty($caterories)) {
|
||||
$showAGS = true;
|
||||
}
|
||||
} else {
|
||||
$showAGS = true;
|
||||
}
|
||||
|
||||
if ($showAGS) {
|
||||
$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'),
|
||||
]
|
||||
);
|
||||
} else {
|
||||
$gradebookUrl = api_get_path(WEB_CODE_PATH).'gradebook/index.php?'.api_get_cidreq();
|
||||
|
||||
$this->addLabel(
|
||||
$plugin->get_lang('AssigmentAndGradesService'),
|
||||
sprintf(
|
||||
$plugin->get_lang('YouNeedCreateTheGradebokInCourseFirst'),
|
||||
Display::url($gradebookUrl, $gradebookUrl)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$this->addRadio(
|
||||
'1p3_nrps',
|
||||
$plugin->get_lang('NamesAndRoleProvisioningService'),
|
||||
[
|
||||
LtiNamesRoleProvisioningService::NRPS_NONE => $plugin->get_lang('DontUseService'),
|
||||
LtiNamesRoleProvisioningService::NRPS_CONTEXT_MEMBERSHIP => $plugin->get_lang('UseService'),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
if (!$parent) {
|
||||
$this->addText(
|
||||
'replacement_user_id',
|
||||
[
|
||||
$plugin->get_lang('ReplacementUserId'),
|
||||
$plugin->get_lang('ReplacementUserIdHelp'),
|
||||
],
|
||||
false
|
||||
);
|
||||
$this->applyFilter('replacement_user_id', 'trim');
|
||||
}
|
||||
|
||||
$this->addHtml('</div>');
|
||||
$this->addButtonAdvancedSettings('lti_privacy', get_lang('Privacy'));
|
||||
$this->addHtml('<div id="lti_privacy_options" style="display:none;">');
|
||||
$this->addCheckBox('share_name', null, $plugin->get_lang('ShareLauncherName'));
|
||||
$this->addCheckBox('share_email', null, $plugin->get_lang('ShareLauncherEmail'));
|
||||
$this->addCheckBox('share_picture', null, $plugin->get_lang('ShareLauncherPicture'));
|
||||
$this->addHtml('</div>');
|
||||
$this->addButtonUpdate($plugin->get_lang('EditExternalTool'));
|
||||
$this->addHidden('id', $this->tool->getId());
|
||||
$this->addHidden('action', 'edit');
|
||||
$this->applyFilter('__ALL__', 'trim');
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function setDefaultValues()
|
||||
{
|
||||
$advServices = $this->tool->getAdvantageServices();
|
||||
|
||||
$this->setDefaults(
|
||||
[
|
||||
'name' => $this->tool->getName(),
|
||||
'description' => $this->tool->getDescription(),
|
||||
'launch_url' => $this->tool->getLaunchUrl(),
|
||||
'consumer_key' => $this->tool->getConsumerKey(),
|
||||
'shared_secret' => $this->tool->getSharedSecret(),
|
||||
'custom_params' => $this->tool->getCustomParams(),
|
||||
'deep_linking' => $this->tool->isActiveDeepLinking(),
|
||||
'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,
|
||||
'jwks_url' => $this->tool->getJwksUrl(),
|
||||
'login_url' => $this->tool->getLoginUrl(),
|
||||
'redirect_url' => $this->tool->getRedirectUrl(),
|
||||
'1p3_ags' => $advServices['ags'],
|
||||
'1p3_nrps' => $advServices['nrps'],
|
||||
'document_target' => $this->tool->getDocumentTarget(),
|
||||
'replacement_user_id' => $this->tool->getReplacementForUserId(),
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user