Added ability to modify templates and save them with same name.

An option named "replace" has been added to the same
template form so user can choose to overwrite an existing
template (i.e. modify and save an existing template).
This commit is contained in:
Shamim Rezaie 2015-07-29 11:21:01 +10:00 committed by Mark Nelson
parent d9e8c24a6b
commit 3774a6323c
4 changed files with 27 additions and 8 deletions

View file

@ -86,6 +86,7 @@ $string['posx_help'] = 'This is the position in mm from the top left corner you
$string['posy'] = 'Postion Y';
$string['posy_help'] = 'This is the position in mm from the top left corner you wish the element to display in the y direction.';
$string['receiveddate'] = 'Received date';
$string['replacetemplate'] = 'Replace';
$string['report'] = 'Report';
$string['save'] = 'Save';
$string['savechangespreview'] = 'Save changes and preview';

View file

@ -41,12 +41,23 @@ require_capability('mod/customcert:manage', $context);
// Store the current time in a variable.
$time = time();
// Create the template.
$template = new stdClass();
$template->name = $name;
$template->timecreated = $time;
if (!$template = $DB->get_record('customcert_template', array('name' => $name))) {
// Create the template.
$template = new stdClass();
$template->name = $name;
$template->timecreated = $time;
}
$template->timemodified = $time;
$template->id = $DB->insert_record('customcert_template', $template);
if (empty($template->id)) {
$template->id = $DB->insert_record('customcert_template', $template);
} else {
$DB->update_record('customcert_template', $template);
$templatepages = $DB->get_records_menu('customcert_template_pages', array('templateid' => $template->id));
$DB->delete_records_list('customcert_template_elements', 'templatepageid', array_keys($templatepages));
$DB->delete_records('customcert_template_pages', array('templateid' => $template->id));
}
// Get the pages of the customcert we are copying.
if ($pages = $DB->get_records('customcert_pages', array('customcertid' => $customcert->id))) {

View file

@ -38,6 +38,7 @@ class mod_customcert_save_template_form extends moodleform {
$group = array();
$group[] = $mform->createElement('text', 'name');
$group[] = $mform->createElement('submit', 'savetemplatesubmit', get_string('save', 'customcert'));
$group[] = $mform->createElement('checkbox', 'replace', null, get_string('replacetemplate', 'customcert'));
$mform->addElement('group', 'savetemplategroup', get_string('templatename', 'customcert'), $group, '', false);
@ -66,9 +67,11 @@ class mod_customcert_save_template_form extends moodleform {
$errors = parent::validation($data, $files);
// Ensure the name does not already exist.
if ($DB->record_exists('customcert_template', array('name' => $data['name']))) {
$errors['savetemplategroup'] = get_string('templatenameexists', 'customcert');
if (empty($data['replace'])) {
// Ensure the name does not already exist.
if ($DB->record_exists('customcert_template', array('name' => $data['name']))) {
$errors['savetemplategroup'] = get_string('templatenameexists', 'customcert');
}
}
return $errors;

View file

@ -2,6 +2,10 @@
text-align:right;
}
#page-mod-customcert-edit #id_replace {
margin-left: 10px;
}
#page-mod-customcert-report .centre {
margin-left: auto;
margin-right: auto;