Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 400] [Versions 310 and 401]

   1  <?php
   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/>.
  16  
  17  /**
  18   * assignment_base is the base class for assignment types
  19   *
  20   * This class provides all the functionality for an assignment
  21   *
  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
  25   */
  26  
  27  /**
  28   * Adds an assignment instance
  29   *
  30   * Only used by generators so we can create old assignments to test the upgrade.
  31   *
  32   * @param stdClass $assignment
  33   * @param mod_assignment_mod_form $mform
  34   * @return int intance id
  35   */
  36  function assignment_add_instance($assignment, $mform = null) {
  37      global $DB;
  38  
  39      $assignment->timemodified = time();
  40      $assignment->courseid = $assignment->course;
  41      $returnid = $DB->insert_record("assignment", $assignment);
  42      $assignment->id = $returnid;
  43      return $returnid;
  44  }
  45  
  46  /**
  47   * Deletes an assignment instance
  48   *
  49   * @param $id
  50   */
  51  function assignment_delete_instance($id){
  52      global $CFG, $DB;
  53  
  54      if (! $assignment = $DB->get_record('assignment', array('id'=>$id))) {
  55          return false;
  56      }
  57  
  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);
  64      }
  65  
  66      if (! $DB->delete_records('assignment_submissions', array('assignment'=>$assignment->id))) {
  67          $result = false;
  68      }
  69  
  70      if (! $DB->delete_records('event', array('modulename'=>'assignment', 'instance'=>$assignment->id))) {
  71          $result = false;
  72      }
  73  
  74      grade_update('mod/assignment', $assignment->course, 'mod', 'assignment', $assignment->id, 0, NULL, array('deleted'=>1));
  75  
  76      // We must delete the module record after we delete the grade item.
  77      if (! $DB->delete_records('assignment', array('id'=>$assignment->id))) {
  78          $result = false;
  79      }
  80  
  81      return $result;
  82  }
  83  
  84  /**
  85   * @param string $feature FEATURE_xx constant for requested feature
  86   * @return mixed True if module supports feature, null if doesn't know
  87   */
  88  function assignment_supports($feature) {
  89      switch($feature) {
  90          case FEATURE_BACKUP_MOODLE2:          return true;
  91  
  92          default: return null;
  93      }
  94  }