Fixed issue where elements for the customcert page with the id 1 were being displayed (if it existed) for newly created customcerts

This commit is contained in:
Mark Nelson 2013-04-09 13:27:55 +08:00
parent d6428b89d1
commit 08c4f03ee7
2 changed files with 25 additions and 22 deletions

View file

@ -238,6 +238,8 @@ class mod_customcert_edit_form extends moodleform {
$mform->addElement('html', html_writer::end_tag('div')); $mform->addElement('html', html_writer::end_tag('div'));
} }
// Check that this page is not a newly created one with no data in the database.
if (!is_null($page)) {
// Check if there are elements to add. // Check if there are elements to add.
if ($elements = $DB->get_records('customcert_elements', array('pageid' => $pageid), 'id ASC')) { if ($elements = $DB->get_records('customcert_elements', array('pageid' => $pageid), 'id ASC')) {
// Loop through and add the ones present. // Loop through and add the ones present.
@ -263,4 +265,5 @@ class mod_customcert_edit_form extends moodleform {
} }
} }
} }
}
} }

View file

@ -442,7 +442,7 @@ function customcert_save_page_data($data) {
// Get the total number of pages that exist for this customcert. // Get the total number of pages that exist for this customcert.
$totalpages = $DB->count_records('customcert_pages', array('customcertid' => $data->id)); $totalpages = $DB->count_records('customcert_pages', array('customcertid' => $data->id));
// Check if this file has any pages yet, if not we are inserting. // Check if this customcert has any pages yet, if not we are inserting.
if ($totalpages == 0) { if ($totalpages == 0) {
// Create the page to insert. // Create the page to insert.
$page = new stdClass(); $page = new stdClass();