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.
   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   * Course completion critieria - completion on unenrolment
  19   *
  20   * @package core_completion
  21   * @category completion
  22   * @copyright 2009 Catalyst IT Ltd
  23   * @author Aaron Barnes <aaronb@catalyst.net.nz>
  24   * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  25   */
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  /**
  30   * Course completion critieria - completion on unenrolment
  31   *
  32   * @package core_completion
  33   * @category completion
  34   * @copyright 2009 Catalyst IT Ltd
  35   * @author Aaron Barnes <aaronb@catalyst.net.nz>
  36   * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  37   */
  38  class completion_criteria_unenrol extends completion_criteria {
  39  
  40      /* @var int Criteria type constant [COMPLETION_CRITERIA_TYPE_UNENROL] */
  41      public $criteriatype = COMPLETION_CRITERIA_TYPE_UNENROL;
  42  
  43      /**
  44       * Finds and returns a data_object instance based on params.
  45       *
  46       * @param array $params associative arrays varname=>value
  47       * @return data_object data_object instance or false if none found.
  48       */
  49      public static function fetch($params) {
  50          $params['criteriatype'] = COMPLETION_CRITERIA_TYPE_UNENROL;
  51          return self::fetch_helper('course_completion_criteria', __CLASS__, $params);
  52      }
  53  
  54      /**
  55       * Add appropriate form elements to the critieria form
  56       *
  57       * @param moodleform $mform Moodle forms object
  58       * @param stdClass $data Form data
  59       */
  60      public function config_form_display(&$mform, $data = null) {
  61          $mform->addElement('checkbox', 'criteria_unenrol', get_string('enable'));
  62  
  63          if ($this->id) {
  64              $mform->setDefault('criteria_unenrol', 1);
  65          }
  66      }
  67  
  68      /**
  69       * Update the criteria information stored in the database
  70       *
  71       * @param stdClass $data Form data
  72       */
  73      public function update_config(&$data) {
  74          if (!empty($data->criteria_unenrol)) {
  75              $this->course = $data->id;
  76              $this->insert();
  77          }
  78      }
  79  
  80      /**
  81       * Review this criteria and decide if the user has completed
  82       *
  83       * @param completion_completion $completion The user's completion record
  84       * @param bool $mark Optionally set false to not save changes to database
  85       * @return bool
  86       */
  87      public function review($completion, $mark = true) {
  88          // Check enrolment
  89          return false;
  90      }
  91  
  92      /**
  93       * Return criteria title for display in reports
  94       *
  95       * @return string
  96       */
  97      public function get_title() {
  98          return get_string('unenrol', 'enrol');
  99      }
 100  
 101      /**
 102       * Return a more detailed criteria title for display in reports
 103       *
 104       * @return string
 105       */
 106      public function get_title_detailed() {
 107          return $this->get_title();
 108      }
 109  
 110      /**
 111       * Return criteria type title for display in reports
 112       *
 113       * @return string
 114       */
 115      public function get_type_title() {
 116          return get_string('unenrol', 'enrol');
 117      }
 118  
 119      /**
 120       * Return criteria progress details for display in reports
 121       *
 122       * @param completion_completion $completion The user's completion record
 123       * @return array An array with the following keys:
 124       *     type, criteria, requirement, status
 125       */
 126      public function get_details($completion) {
 127          $details = array();
 128          $details['type'] = get_string('unenrolment', 'completion');
 129          $details['criteria'] = get_string('unenrolment', 'completion');
 130          $details['requirement'] = get_string('unenrolingfromcourse', 'completion');
 131          $details['status'] = '';
 132          return $details;
 133      }
 134  
 135      /**
 136       * Return pix_icon for display in reports.
 137       *
 138       * @param string $alt The alt text to use for the icon
 139       * @param array $attributes html attributes
 140       * @return pix_icon
 141       */
 142      public function get_icon($alt, array $attributes = null) {
 143          return new pix_icon('i/user', $alt, 'moodle', $attributes);
 144      }
 145  }