Пример #1
0
/**
 * Processes the request from a user to delete a part from an activity
 *
 * @param object $cm The moodle course module object for this instance
 * @param object $turnitintool The turnitintool object is for this activity
 * @param var $partid The ID of the assignment part stored in turnitintool_parts
 * @return array A notice array contains error details for display on page load in the case of an error nothing returned if no errors occur
 */
function turnitintool_delete_part($cm, $turnitintool, $partid)
{
    global $CFG, $USER, $DB;
    $notice['message'] = '';
    if ($turnitintool->numparts == 1) {
        $error = true;
        turnitintool_print_error('onepartdeleteerror', 'turnitintool', NULL, NULL, __FILE__, __LINE__);
    } else {
        if (has_capability('mod/turnitintool:grade', turnitintool_get_context('MODULE', $cm->id))) {
            if (turnitintool_is_owner($turnitintool->course)) {
                $owner = $USER;
            } else {
                $owner = turnitintool_get_owner($turnitintool->course);
            }
            if (!($submissions = turnitintool_delete_records('turnitintool_submissions', 'turnitintoolid', $turnitintool->id, 'submission_part', $partid))) {
                turnitintool_print_error('submissiondeleteerror', 'turnitintool', NULL, NULL, __FILE__, __LINE__);
                exit;
            }
            $result = true;
            // ]]]]
            # Delete any dependent records here #
            $part = new stdClass();
            $part->id = $partid;
            $part->deleted = 1;
            if (!turnitintool_update_record("turnitintool_parts", $part, false)) {
                turnitintool_print_error('partdeleteerror', 'turnitintool', NULL, NULL, __FILE__, __LINE__);
            }
            // Delete events for this assignment / part
            $name = $turnitintool->name . ' - ' . turnitintool_partnamefromnum($partid);
            // $DB is not available for Moodle 1.9
            if (is_callable(array($DB, 'sql_compare_text'))) {
                $deletewhere = 'modulename = :modulename
            AND ' . $DB->sql_compare_text('instance') . ' = :id
            AND ' . $DB->sql_compare_text('name') . ' = :name';
            } else {
                $deletewhere = 'modulename = \'turnitintool\'
            AND instance = \'' . $turnitintool->id . '\'
            AND name = \'' . $name . '\'';
            }
            turnitintool_delete_records_select('event', $deletewhere, array('modulename' => 'turnitintool', 'id' => $turnitintool->id, 'name' => $name));
            $update = new stdClass();
            $update->id = $turnitintool->id;
            $update->numparts = $turnitintool->numparts - 1;
            $update->needs_updating = 1;
            if (!turnitintool_update_record("turnitintool", $update)) {
                turnitintool_print_error('turnitintooldeleteerror', 'turnitintool', NULL, NULL, __FILE__, __LINE__);
            }
            turnitintool_redirect($CFG->wwwroot . '/mod/turnitintool/view.php' . '?id=' . $cm->id . '&do=intro');
            exit;
        } else {
            turnitintool_print_error('permissiondeniederror', 'turnitintool', NULL, NULL, __FILE__, __LINE__);
            exit;
        }
    }
    return $notice;
}
Пример #2
0
/**
 * Processes the request from a user to delete a part from an activity
 *
 * @param object $cm The moodle course module object for this instance
 * @param object $turnitintool The turnitintool object is for this activity
 * @param var $partid The ID of the assignment part stored in turnitintool_parts
 * @return array A notice array contains error details for display on page load in the case of an error nothing returned if no errors occur
 */
function turnitintool_delete_part($cm, $turnitintool, $partid)
{
    global $CFG, $USER;
    $notice['message'] = '';
    if ($turnitintool->numparts == 1) {
        $error = true;
        turnitintool_print_error('onepartdeleteerror', 'turnitintool', NULL, NULL, __FILE__, __LINE__);
    } else {
        if (has_capability('mod/turnitintool:grade', get_context_instance(CONTEXT_MODULE, $cm->id))) {
            if (turnitintool_is_owner($turnitintool->course)) {
                $owner = $USER;
            } else {
                $owner = turnitintool_get_owner($turnitintool->course);
            }
            if (!($submissions = turnitintool_delete_records('turnitintool_submissions', 'turnitintoolid', $turnitintool->id, 'submission_part', $partid))) {
                turnitintool_print_error('submissiondeleteerror', 'turnitintool', NULL, NULL, __FILE__, __LINE__);
                exit;
            }
            $result = true;
            // ]]]]
            # Delete any dependent records here #
            $part->id = $partid;
            $part->deleted = 1;
            if (!turnitintool_update_record("turnitintool_parts", $part, false)) {
                turnitintool_print_error('partdeleteerror', 'turnitintool', NULL, NULL, __FILE__, __LINE__);
            }
            // Delete events for this assignment / part
            turnitintool_delete_records('event', 'modulename', 'turnitintool', 'instance', $turnitintool->id, 'name', $turnitintool->name . ' - ' . turnitintool_partnamefromnum($partid));
            $update->id = $turnitintool->id;
            $update->numparts = $turnitintool->numparts - 1;
            if (!turnitintool_update_record("turnitintool", $update)) {
                turnitintool_print_error('turnitintooldeleteerror', 'turnitintool', NULL, NULL, __FILE__, __LINE__);
            }
            turnitintool_redirect($CFG->wwwroot . '/mod/turnitintool/view.php' . '?id=' . $cm->id . '&do=intro');
            exit;
        } else {
            turnitintool_print_error('permissiondeniederror', 'turnitintool', NULL, NULL, __FILE__, __LINE__);
            exit;
        }
    }
    return $notice;
}