Fixed sequence values when deleting an element
This commit is contained in:
parent
53cb267836
commit
e85807e298
7
edit.php
7
edit.php
|
@ -118,12 +118,7 @@ if ((!empty($moveup)) || (!empty($movedown))) {
|
||||||
}
|
}
|
||||||
} else if (!empty($deleteelement)) { // Check if we are deleting an element.
|
} else if (!empty($deleteelement)) { // Check if we are deleting an element.
|
||||||
if (!empty($confirm)) { // Check they have confirmed the deletion.
|
if (!empty($confirm)) { // Check they have confirmed the deletion.
|
||||||
// Ensure element exists and delete it.
|
customcert_delete_element($deleteelement);
|
||||||
$element = $DB->get_record('customcert_elements', array('id' => $deleteelement), '*', MUST_EXIST);
|
|
||||||
// Get an instance of the element class.
|
|
||||||
if ($e = customcert_get_element_instance($element)) {
|
|
||||||
$e->delete_element();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// Set deletion flag to true.
|
// Set deletion flag to true.
|
||||||
$deleting = true;
|
$deleting = true;
|
||||||
|
|
28
locallib.php
28
locallib.php
|
@ -274,6 +274,34 @@ function customcert_add_page($data) {
|
||||||
$DB->insert_record('customcert_pages', $page);
|
$DB->insert_record('customcert_pages', $page);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles deleting an element from the customcert.
|
||||||
|
*
|
||||||
|
* @param int $elementid the customcert page
|
||||||
|
*/
|
||||||
|
function customcert_delete_element($elementid) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
|
// Ensure element exists and delete it.
|
||||||
|
$element = $DB->get_record('customcert_elements', array('id' => $elementid), '*', MUST_EXIST);
|
||||||
|
|
||||||
|
// Get an instance of the element class.
|
||||||
|
if ($e = customcert_get_element_instance($element)) {
|
||||||
|
$e->delete_element();
|
||||||
|
} else {
|
||||||
|
// The plugin files are missing, so just remove the entry from the DB.
|
||||||
|
$DB->delete_records('customcert_elements', array('id' => $elementid));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now we want to decrease the sequence numbers of the elements
|
||||||
|
// that are greater than the element we deleted.
|
||||||
|
$sql = "UPDATE {customcert_elements}
|
||||||
|
SET sequence = sequence - 1
|
||||||
|
WHERE pageid = :pageid
|
||||||
|
AND sequence > :sequence";
|
||||||
|
$DB->execute($sql, array('pageid' => $element->pageid, 'sequence' => $element->sequence));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles deleting a page from the customcert.
|
* Handles deleting a page from the customcert.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue