Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 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  /**
  19   * Course completion critieria aggregation
  20   *
  21   * @package core_completion
  22   * @category completion
  23   * @copyright 2009 Catalyst IT Ltd
  24   * @author Aaron Barnes <aaronb@catalyst.net.nz>
  25   * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  26   */
  27  
  28  defined('MOODLE_INTERNAL') || die();
  29  require_once($CFG->dirroot.'/completion/data_object.php');
  30  
  31  /**
  32   * Course completion critieria aggregation
  33   *
  34   * @package core_completion
  35   * @category completion
  36   * @copyright 2009 Catalyst IT Ltd
  37   * @author Aaron Barnes <aaronb@catalyst.net.nz>
  38   * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  39   */
  40  class completion_aggregation extends data_object {
  41  
  42      /* @var string Database table name that stores completion aggregation information */
  43      public $table = 'course_completion_aggr_methd';
  44  
  45      /**
  46       * Array of required table fields, must start with 'id'.
  47       * Defaults to id, course, criteriatype, method, value
  48       * @var array
  49       */
  50      public $required_fields = array('id', 'course', 'criteriatype', 'method', 'value');
  51  
  52      /* @var array Array of unique fields, used in where clauses */
  53      public $unique_fields = array('course', 'criteriatype');
  54  
  55      /* @var int Course id */
  56      public $course;
  57  
  58      /* @var int Criteria type this aggregation method applies to, or NULL for overall course aggregation */
  59      public $criteriatype;
  60  
  61      /* @var int Aggregation method (COMPLETION_AGGREGATION_* constant) */
  62      public $method;
  63  
  64      /* @var mixed Method value */
  65      public $value;
  66  
  67  
  68      /**
  69       * Finds and returns a data_object instance based on params.
  70       *
  71       * @param array $params associative arrays varname=>value
  72       * @return data_object instance of data_object or false if none found.
  73       */
  74      public static function fetch($params) {
  75          return self::fetch_helper('course_completion_aggr_methd', __CLASS__, $params);
  76      }
  77  
  78  
  79      /**
  80       * Finds and returns all data_object instances based on params.
  81       *
  82       * @param array $params associative arrays varname=>value
  83       * @return array array of data_object insatnces or false if none found.
  84       */
  85      public static function fetch_all($params) {}
  86  
  87      /**
  88       * Set the aggregation method
  89       *
  90       * @param int $method One of COMPLETION_AGGREGATION_ALL or COMPLETION_AGGREGATION_ANY
  91       */
  92      public function setMethod($method) {
  93          $methods = array(
  94              COMPLETION_AGGREGATION_ALL,
  95              COMPLETION_AGGREGATION_ANY,
  96          );
  97  
  98          if (in_array($method, $methods)) {
  99              $this->method = $method;
 100          } else {
 101              $this->method = COMPLETION_AGGREGATION_ALL;
 102          }
 103      }
 104  
 105  
 106      /**
 107       * Save aggregation method to database
 108       *
 109       * @access  public
 110       * @return  boolean
 111       */
 112      public function save() {
 113          if ($this->id) {
 114              return $this->update();
 115          } else {
 116              return $this->insert();
 117          }
 118      }
 119  }