Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is 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   * No student indicator.
  19   *
  20   * @package   core_course
  21   * @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace core_course\analytics\indicator;
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  /**
  30   * No student indicator.
  31   *
  32   * @package   core_course
  33   * @copyright 2016 David Monllao {@link http://www.davidmonllao.com}
  34   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  35   */
  36  class no_student extends \core_analytics\local\indicator\binary {
  37  
  38      /**
  39       * Student role ids.
  40       *
  41       * @var array|null
  42       */
  43      protected $studentroleids = null;
  44  
  45      /**
  46       * Returns the name.
  47       *
  48       * If there is a corresponding '_help' string this will be shown as well.
  49       *
  50       * @return \lang_string
  51       */
  52      public static function get_name() : \lang_string {
  53          return new \lang_string('indicator:nostudent', 'moodle');
  54      }
  55  
  56      /**
  57       * required_sample_data
  58       *
  59       * @return string[]
  60       */
  61      public static function required_sample_data() {
  62          // We require course because, although calculate_sample only reads context, we need the context to be course
  63          // or below.
  64          return array('context', 'course');
  65      }
  66  
  67      /**
  68       * calculate_sample
  69       *
  70       * @param int $sampleid
  71       * @param string $sampleorigin
  72       * @param int|false $notusedstarttime
  73       * @param int|false $notusedendtime
  74       * @return float
  75       */
  76      public function calculate_sample($sampleid, $sampleorigin, $notusedstarttime = false, $notusedendtime = false) {
  77  
  78          $context = $this->retrieve('context', $sampleid);
  79  
  80          if (is_null($this->studentroleids)) {
  81              $this->studentroleids = array_keys(get_archetype_roles('student'));
  82          }
  83  
  84          foreach ($this->studentroleids as $role) {
  85              // We look for roles, not enrolments as a student assigned at category level is supposed to be a
  86              // course student.
  87              $students = get_role_users($role, $context, false, 'u.id', 'u.id');
  88              if ($students) {
  89                  return self::get_max_value();
  90              }
  91          }
  92  
  93          return self::get_min_value();
  94      }
  95  }