예제 #1
0
/**
 * deletes an instance of a data
 *
 * @global object
 * @param int $id
 * @return bool
 */
function data_delete_instance($id)
{
    // takes the dataid
    global $DB, $CFG;
    if (!($data = $DB->get_record('data', array('id' => $id)))) {
        return false;
    }
    $cm = get_coursemodule_from_instance('data', $data->id);
    $context = context_module::instance($cm->id);
    /// Delete all the associated information
    // files
    $fs = get_file_storage();
    $fs->delete_area_files($context->id, 'mod_data');
    // get all the records in this data
    $sql = "SELECT r.id\n              FROM {data_records} r\n             WHERE r.dataid = ?";
    $DB->delete_records_select('data_content', "recordid IN ({$sql})", array($id));
    // delete all the records and fields
    $DB->delete_records('data_records', array('dataid' => $id));
    $DB->delete_records('data_fields', array('dataid' => $id));
    // Remove old calendar events.
    $events = $DB->get_records('event', array('modulename' => 'data', 'instance' => $id));
    foreach ($events as $event) {
        $event = calendar_event::load($event);
        $event->delete();
    }
    // Delete the instance itself
    $result = $DB->delete_records('data', array('id' => $id));
    // cleanup gradebook
    data_grade_item_delete($data);
    return $result;
}
예제 #2
0
파일: lib.php 프로젝트: nottmoo/moodle
/**
 * deletes an instance of a data
 *
 * @global object
 * @param int $id
 * @return bool
 */
function data_delete_instance($id) {    // takes the dataid
    global $DB, $CFG;

    if (!$data = $DB->get_record('data', array('id'=>$id))) {
        return false;
    }

    $cm = get_coursemodule_from_instance('data', $data->id);
    $context = get_context_instance(CONTEXT_MODULE, $cm->id);

/// Delete all the associated information

    // files
    $fs = get_file_storage();
    $fs->delete_area_files($context->id, 'mod_data');

    // get all the records in this data
    $sql = "SELECT r.id
              FROM {data_records} r
             WHERE r.dataid = ?";

    $DB->delete_records_select('data_content', "recordid IN ($sql)", array($id));

    // delete all the records and fields
    $DB->delete_records('data_records', array('dataid'=>$id));
    $DB->delete_records('data_fields', array('dataid'=>$id));

    // Delete the instance itself
    $result = $DB->delete_records('data', array('id'=>$id));

    // cleanup gradebook
    data_grade_item_delete($data);

    return $result;
}
예제 #3
0
function data_delete_instance($id)
{
    // takes the dataid
    global $CFG;
    if (!($data = get_record('data', 'id', $id))) {
        return false;
    }
    // Delete all the associated information
    // get all the records in this data
    $sql = 'SELECT c.* FROM ' . $CFG->prefix . 'data_records r LEFT JOIN ' . $CFG->prefix . 'data_content c ON c.recordid = r.id WHERE r.dataid = ' . $id;
    if ($contents = get_records_sql($sql)) {
        foreach ($contents as $content) {
            $field = get_record('data_fields', 'id', $content->fieldid);
            if ($g = data_get_field($field, $data)) {
                $g->delete_content_files($id, $content->recordid, $content->content);
            }
            //delete the content itself
            delete_records('data_content', 'id', $content->id);
        }
    }
    // delete all the records and fields
    delete_records('data_records', 'dataid', $id);
    delete_records('data_fields', 'dataid', $id);
    // Delete the instance itself
    $result = delete_records('data', 'id', $id);
    data_grade_item_delete($data);
    return $result;
}