MDL-50015 mod_imscp: New WS mod_imscp_view_imscp
[moodle.git] / mod / assignment / lib.php
CommitLineData
a084ac0d 1<?php
256578f6 2// This file is part of Moodle - http://moodle.org/
3//
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.
8//
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.
13//
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/>.
19002f9f 16
b0f2597e 17/**
18 * assignment_base is the base class for assignment types
19 *
20 * This class provides all the functionality for an assignment
256578f6 21 *
ca3aff3d 22 * @package mod_assignment
256578f6 23 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
b0f2597e 25 */
04eba58f 26
7af1e882 27/**
40cb4879 28 * Adds an assignment instance
48c6ebeb 29 *
40cb4879 30 * Only used by generators so we can create old assignments to test the upgrade.
7af1e882 31 *
40cb4879
DW
32 * @param stdClass $assignment
33 * @param mod_assignment_mod_form $mform
34 * @return int intance id
7af1e882 35 */
40cb4879
DW
36function assignment_add_instance($assignment, $mform = null) {
37 global $DB;
45fa3412 38
40cb4879
DW
39 $assignment->timemodified = time();
40 $assignment->courseid = $assignment->course;
41 $returnid = $DB->insert_record("assignment", $assignment);
42 $assignment->id = $returnid;
43 return $returnid;
73097f07 44}
45
09ba8e56 46/**
40cb4879 47 * Deletes an assignment instance
206ab184 48 *
40cb4879 49 * @param $id
09ba8e56 50 */
40cb4879 51function assignment_delete_instance($id){
74d7d735 52 global $CFG, $DB;
09ba8e56 53
40cb4879 54 if (! $assignment = $DB->get_record('assignment', array('id'=>$id))) {
f36cbf1d 55 return false;
56 }
0b5a80a1 57
40cb4879
DW
58 $result = true;
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);
74d7d735 64 }
0b5a80a1 65
40cb4879
DW
66 if (! $DB->delete_records('assignment_submissions', array('assignment'=>$assignment->id))) {
67 $result = false;
0b5a80a1 68 }
0b5a80a1 69
40cb4879
DW
70 if (! $DB->delete_records('event', array('modulename'=>'assignment', 'instance'=>$assignment->id))) {
71 $result = false;
0b5a80a1 72 }
73
40cb4879
DW
74 if (! $DB->delete_records('assignment', array('id'=>$assignment->id))) {
75 $result = false;
e63515ba
RT
76 }
77
40cb4879 78 grade_update('mod/assignment', $assignment->course, 'mod', 'assignment', $assignment->id, 0, NULL, array('deleted'=>1));
0b5a80a1 79
40cb4879 80 return $result;
f432bebf 81}
82
18a2a0cb 83/**
84 * @param string $feature FEATURE_xx constant for requested feature
85 * @return mixed True if module supports feature, null if doesn't know
86 */
87function assignment_supports($feature) {
88 switch($feature) {
8bf1e529 89 case FEATURE_BACKUP_MOODLE2: return true;
42f103be 90
18a2a0cb 91 default: return null;
92 }
93}