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,27 +238,30 @@ class mod_customcert_edit_form extends moodleform {
$mform->addElement('html', html_writer::end_tag('div'));
}
// Check if there are elements to add.
if ($elements = $DB->get_records('customcert_elements', array('pageid' => $pageid), 'id ASC')) {
// Loop through and add the ones present.
foreach ($elements as $element) {
$classfile = "{$CFG->dirroot}/mod/customcert/elements/{$element->element}/lib.php";
// It's possible this element was added to the database then the folder was deleted, if
// this is the case we do not want to render these elements as an error will occur.
if (file_exists($classfile)) {
// Add element header.
$mform->addElement('header', 'headerelement_' . $element->id, get_string('page', 'customcert', $pagenum) . " - " .
get_string('pluginname', 'customcertelement_' . $element->element));
// Add the page number to the element so we can use within the element.
$element->pagenum = $pagenum;
// Get the classname.
$classname = "customcert_element_{$element->element}";
$e = new $classname($element);
$e->render_form_elements($mform);
// Add this to the objects array.
$this->elementobjects[] = $e;
// Add submit button to delete this.
$mform->addElement('submit', 'deleteelement_' . $element->id, get_string('delete', 'customcert'));
// 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.
if ($elements = $DB->get_records('customcert_elements', array('pageid' => $pageid), 'id ASC')) {
// Loop through and add the ones present.
foreach ($elements as $element) {
$classfile = "{$CFG->dirroot}/mod/customcert/elements/{$element->element}/lib.php";
// It's possible this element was added to the database then the folder was deleted, if
// this is the case we do not want to render these elements as an error will occur.
if (file_exists($classfile)) {
// Add element header.
$mform->addElement('header', 'headerelement_' . $element->id, get_string('page', 'customcert', $pagenum) . " - " .
get_string('pluginname', 'customcertelement_' . $element->element));
// Add the page number to the element so we can use within the element.
$element->pagenum = $pagenum;
// Get the classname.
$classname = "customcert_element_{$element->element}";
$e = new $classname($element);
$e->render_form_elements($mform);
// Add this to the objects array.
$this->elementobjects[] = $e;
// Add submit button to delete this.
$mform->addElement('submit', 'deleteelement_' . $element->id, get_string('delete', 'customcert'));
}
}
}
}

View file

@ -442,7 +442,7 @@ function customcert_save_page_data($data) {
// Get the total number of pages that exist for this customcert.
$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) {
// Create the page to insert.
$page = new stdClass();