MDL-49629 mod_lti: Add icon fields

Icon fields added to input form when defining an external tool at the
admin level.  The icon for a tool derived from a tool proxy can be
overridden.  Course cache is cleared if current icon value is changed.

Add text boxes to edit form for entering icon URLs.
This commit is contained in:
spvickers
2015-07-28 12:04:35 +01:00
committed by Dan Poltawski
parent 6edb0474e3
commit 6504c740b6
6 changed files with 85 additions and 17 deletions
+13
View File
@@ -120,6 +120,19 @@ class mod_lti_edit_types_form extends moodleform{
$mform->addHelpButton('lti_launchcontainer', 'default_launch_container', 'lti');
$mform->setType('lti_launchcontainer', PARAM_INT);
$mform->addElement('hidden', 'oldicon');
$mform->setType('oldicon', PARAM_URL);
$mform->addElement('text', 'lti_icon', get_string('icon_url', 'lti'), array('size' => '64'));
$mform->setType('lti_icon', PARAM_URL);
$mform->setAdvanced('lti_icon');
$mform->addHelpButton('lti_icon', 'icon_url', 'lti');
$mform->addElement('text', 'lti_secureicon', get_string('secure_icon_url', 'lti'), array('size' => '64'));
$mform->setType('lti_secureicon', PARAM_URL);
$mform->setAdvanced('lti_secureicon');
$mform->addHelpButton('lti_secureicon', 'secure_icon_url', 'lti');
if (!$istool) {
// Add privacy preferences fieldset where users choose whether to send their data.
$mform->addElement('header', 'privacy', get_string('privacy', 'lti'));
+21 -12
View File
@@ -252,32 +252,41 @@ function lti_get_coursemodule_info($coursemodule) {
require_once($CFG->dirroot.'/mod/lti/locallib.php');
if (!$lti = $DB->get_record('lti', array('id' => $coursemodule->instance),
'icon, secureicon, intro, introformat, name, toolurl, launchcontainer')) {
'icon, secureicon, intro, introformat, name, typeid, toolurl, launchcontainer')) {
return null;
}
$info = new cached_cm_info();
// We want to use the right icon based on whether the
// current page is being requested over http or https.
if (lti_request_is_using_ssl() && !empty($lti->secureicon)) {
$info->iconurl = new moodle_url($lti->secureicon);
} else if (!empty($lti->icon)) {
$info->iconurl = new moodle_url($lti->icon);
}
if ($coursemodule->showdescription) {
// Convert intro to html. Do not filter cached version, filters run at display time.
$info->content = format_module_intro('lti', $lti, $coursemodule->id, false);
}
// Does the link open in a new window?
$tool = lti_get_tool_by_url_match($lti->toolurl);
if ($tool) {
if (!empty($lti->typeid)) {
$toolconfig = lti_get_type_config($lti->typeid);
} else if ($tool = lti_get_tool_by_url_match($lti->toolurl)) {
$toolconfig = lti_get_type_config($tool->id);
} else {
$toolconfig = array();
}
// We want to use the right icon based on whether the
// current page is being requested over http or https.
if (lti_request_is_using_ssl() &&
(!empty($lti->secureicon) || (isset($toolconfig['secureicon']) && !empty($toolconfig['secureicon'])))) {
if (!empty($lti->secureicon)) {
$info->iconurl = new moodle_url($lti->secureicon);
} else {
$info->iconurl = new moodle_url($toolconfig['secureicon']);
}
} else if (!empty($lti->icon)) {
$info->iconurl = new moodle_url($lti->icon);
} else if (isset($toolconfig['icon']) && !empty($toolconfig['icon'])) {
$info->iconurl = new moodle_url($toolconfig['icon']);
}
// Does the link open in a new window?
$launchcontainer = lti_get_launch_container($lti, $toolconfig);
if ($launchcontainer == LTI_LAUNCH_CONTAINER_WINDOW) {
$launchurl = new moodle_url('/mod/lti/launch.php', array('id' => $coursemodule->id));
+37 -3
View File
@@ -952,10 +952,19 @@ function lti_get_type_config($typeid) {
UNION ALL
SELECT 'toolurl' AS name, " . $DB->sql_compare_text('baseurl', 1333) . " AS value
FROM {lti_types}
WHERE id = :typeid2";
WHERE id = :typeid2
UNION ALL
SELECT 'icon' AS name, " . $DB->sql_compare_text('icon', 1333) . " AS value
FROM {lti_types}
WHERE id = :typeid3
UNION ALL
SELECT 'secureicon' AS name, " . $DB->sql_compare_text('secureicon', 1333) . " AS value
FROM {lti_types}
WHERE id = :typeid4";
$typeconfig = array();
$configs = $DB->get_records_sql($query, array('typeid1' => $typeid, 'typeid2' => $typeid));
$configs = $DB->get_records_sql($query,
array('typeid1' => $typeid, 'typeid2' => $typeid, 'typeid3' => $typeid, 'typeid4' => $typeid));
if (!empty($configs)) {
foreach ($configs as $config) {
@@ -1283,6 +1292,10 @@ function lti_get_type_type_config($id) {
$type->lti_parameters = $basicltitype->parameter;
$type->lti_icon = $basicltitype->icon;
$type->lti_secureicon = $basicltitype->secureicon;
if (isset($config['resourcekey'])) {
$type->lti_resourcekey = $config['resourcekey'];
}
@@ -1362,6 +1375,13 @@ function lti_prepare_type_for_save($type, $config) {
$type->coursevisible = !empty($config->lti_coursevisible) ? $config->lti_coursevisible : 0;
$config->lti_coursevisible = $type->coursevisible;
if (isset($config->lti_icon)) {
$type->icon = $config->lti_icon;
}
if (isset($config->lti_secureicon)) {
$type->secureicon = $config->lti_secureicon;
}
if (isset($config->lti_forcessl)) {
$type->forcessl = !empty($config->lti_forcessl) ? $config->lti_forcessl : 0;
$config->lti_forcessl = $type->forcessl;
@@ -1371,13 +1391,23 @@ function lti_prepare_type_for_save($type, $config) {
unset ($config->lti_typename);
unset ($config->lti_toolurl);
unset ($config->lti_icon);
unset ($config->lti_secureicon);
}
function lti_update_type($type, $config) {
global $DB;
global $DB, $CFG;
lti_prepare_type_for_save($type, $config);
$clearcache = false;
if (lti_request_is_using_ssl() && !empty($type->secureicon)) {
$clearcache = !isset($config->oldicon) || ($config->oldicon !== $type->secureicon);
} else {
$clearcache = isset($type->icon) && (!isset($config->oldicon) || ($config->oldicon !== $type->icon));
}
unset($config->oldicon);
if ($DB->update_record('lti_types', $type)) {
foreach ($config as $key => $value) {
if (substr($key, 0, 4) == 'lti_' && !is_null($value)) {
@@ -1388,6 +1418,10 @@ function lti_update_type($type, $config) {
lti_update_config($record);
}
}
require_once($CFG->libdir.'/modinfolib.php');
if ($clearcache) {
rebuild_course_cache();
}
}
}
+2 -2
View File
@@ -166,13 +166,13 @@ class mod_lti_mod_form extends moodleform_mod {
$mform->addHelpButton('instructorcustomparameters', 'custom', 'lti');
$mform->addElement('text', 'icon', get_string('icon_url', 'lti'), array('size' => '64'));
$mform->setType('icon', PARAM_TEXT);
$mform->setType('icon', PARAM_URL);
$mform->setAdvanced('icon');
$mform->addHelpButton('icon', 'icon_url', 'lti');
$mform->disabledIf('icon', 'typeid', 'neq', '0');
$mform->addElement('text', 'secureicon', get_string('secure_icon_url', 'lti'), array('size' => '64'));
$mform->setType('secureicon', PARAM_TEXT);
$mform->setType('secureicon', PARAM_URL);
$mform->setAdvanced('secureicon');
$mform->addHelpButton('secureicon', 'secure_icon_url', 'lti');
$mform->disabledIf('secureicon', 'typeid', 'neq', '0');
+6
View File
@@ -70,6 +70,12 @@ if ($action == 'accept') {
redirect($redirect);
}
if (lti_request_is_using_ssl() && !empty($type->lti_secureicon)) {
$type->oldicon = $type->lti_secureicon;
} else {
$type->oldicon = $type->lti_icon;
}
$form = new mod_lti_edit_types_form($pageurl, (object)array('isadmin' => true, 'istool' => true));
if ($data = $form->get_data()) {
+6
View File
@@ -96,6 +96,12 @@ if ($action == 'accept') {
redirect($redirect);
}
if (lti_request_is_using_ssl() && !empty($type->lti_secureicon)) {
$type->oldicon = $type->lti_secureicon;
} else {
$type->oldicon = $type->lti_icon;
}
$form = new mod_lti_edit_types_form($pageurl, (object)array('isadmin' => true, 'istool' => false));
if ($data = $form->get_data()) {