/** * Given an ID of an instance of this module, * this function will permanently delete the instance * and any data that depends on it. * * @param int $id Id of the module instance * @return boolean Success/Failure */ function checklist_delete_instance($id) { global $DB; if (!($checklist = $DB->get_record('checklist', array('id' => $id)))) { return false; } // Remove all calendar events if ($checklist->duedatesoncalendar) { $checklist->duedatesoncalendar = false; $course = $DB->get_record('course', array('id' => $checklist->course)); $cm = get_coursemodule_from_instance('checklist', $checklist->id, $course->id); if ($cm) { // Should not be false, but check, just in case... $chk = new checklist_class($cm->id, 0, $checklist, $cm, $course); $chk->setallevents(); } } $result = true; $items = $DB->get_records('checklist_item', array('checklist' => $checklist->id), '', 'id'); if (!empty($items)) { $items = array_keys($items); $result = $DB->delete_records_list('checklist_check', 'item', $items); $result = $DB->delete_records_list('checklist_comment', 'itemid', $items); $result = $result && $DB->delete_records('checklist_item', array('checklist' => $checklist->id)); } $result = $result && $DB->delete_records('checklist', array('id' => $checklist->id)); checklist_grade_item_delete($checklist); return $result; }
/** * Given an ID of an instance of this module, * this function will permanently delete the instance * and any data that depends on it. * * @param int $id Id of the module instance * @return boolean Success/Failure */ function checklist_delete_instance($id) { if (!($checklist = get_record('checklist', 'id', $id))) { return false; } // Remove all calendar events if ($checklist->duedatesoncalendar) { $checklist->duedatesoncalendar = false; $course = get_record('course', 'id', $checklist->course); $cm = get_coursemodule_from_instance('checklist', $checklist->id, $course->id); if ($cm) { // Should not fail be false, but check, just in case... $chk = new checklist_class($cm->id, 0, $checklist, $cm, $course); $chk->setallevents(); } } $result = true; $items = get_records('checklist_item', 'checklist', $checklist->id, '', 'id'); if ($items) { $items = implode(',', array_keys($items)); $result = delete_records_select('checklist_check', 'item IN (' . $items . ')'); $result = $result && delete_records_select('checklist_comment', 'item IN (' . $items . ')'); if ($result) { $result = delete_records('checklist_item', 'checklist', $checklist->id); } } if ($result && !delete_records('checklist', 'id', $checklist->id)) { $result = false; } checklist_grade_item_delete($checklist); return $result; }