/************************************************************************ * deletes an instance of a data * ************************************************************************/ function data_delete_instance($id) { // takes the dataid global $CFG; if (! $data = get_record('data', 'id', $id)) { return false; } /// Print the page header $strdata = get_string('modulenameplural','data'); print_header_simple($data->name); print_heading(format_string($data->name)); // This operation could take time to complete... @set_time_limit(0); // Delete all the associated information // Get all the records in this data $sql = 'SELECT id FROM '.$CFG->prefix.'data_records WHERE dataid = '.$id; if ($records = get_records_sql($sql)) { foreach($records as $record) { // get all the fields in this record $sql = 'SELECT id,fieldid,recordid FROM '.$CFG->prefix.'data_content WHERE recordid = '.$record->id; $fields = get_records_sql($sql); foreach($fields as $field) { // get the field type $fieldType = get_record('data_fields','id',$field->fieldid); // create a new object to get delete_content_files overridden if needed by the subtype if ($g = data_get_field($fieldType, $data)) { // trash out everything $g->delete_content_files($field->recordid); } //delete the content itself delete_records('data_content','id', $field->id); } print get_string('deleted', 'moodle') . ". " . get_string('entry', 'data') . " (ID".$record->id.")
\n"; flush(); } } // delete all the records delete_records('data_records', 'dataid', $id); // delete all the fields definitions delete_records('data_fields','dataid',$id); // Delete the instance itself $result = delete_records('data', 'id', $id); // delete the grades for this db data_grade_item_delete($data); return $result; }