2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * assignment_base is the base class for assignment types
20 * This class provides all the functionality for an assignment
22 * @package mod_assignment
23 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 * Adds an assignment instance
30 * Only used by generators so we can create old assignments to test the upgrade.
32 * @param stdClass $assignment
33 * @param mod_assignment_mod_form $mform
34 * @return int intance id
36 function assignment_add_instance($assignment, $mform = null) {
39 $assignment->timemodified
= time();
40 $assignment->courseid
= $assignment->course
;
41 $returnid = $DB->insert_record("assignment", $assignment);
42 $assignment->id
= $returnid;
47 * Deletes an assignment instance
51 function assignment_delete_instance($id){
54 if (! $assignment = $DB->get_record('assignment', array('id'=>$id))) {
59 // Now get rid of all files
60 $fs = get_file_storage();
61 if ($cm = get_coursemodule_from_instance('assignment', $assignment->id
)) {
62 $context = context_module
::instance($cm->id
);
63 $fs->delete_area_files($context->id
);
66 if (! $DB->delete_records('assignment_submissions', array('assignment'=>$assignment->id
))) {
70 if (! $DB->delete_records('event', array('modulename'=>'assignment', 'instance'=>$assignment->id
))) {
74 grade_update('mod/assignment', $assignment->course
, 'mod', 'assignment', $assignment->id
, 0, NULL, array('deleted'=>1));
76 // We must delete the module record after we delete the grade item.
77 if (! $DB->delete_records('assignment', array('id'=>$assignment->id
))) {
85 * @param string $feature FEATURE_xx constant for requested feature
86 * @return mixed True if module supports feature, false if not, null if doesn't know or string for the module purpose.
88 function assignment_supports($feature) {
90 case FEATURE_BACKUP_MOODLE2
: return true;
91 case FEATURE_MOD_PURPOSE
: return MOD_PURPOSE_ASSESSMENT
;