2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 * No teacher indicator.
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
25 namespace core_course\analytics\indicator;
27 defined('MOODLE_INTERNAL') || die();
30 * No teacher indicator.
32 * @package core_analytics
33 * @copyright 2016 David Monllao {@link http://www.davidmonllao.com}
34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36 class no_teacher extends \core_analytics\local\indicator\binary {
43 protected $teacherroleids = null;
50 public static function get_name() {
51 return get_string('indicator:noteacher', 'moodle');
55 * required_sample_data
59 public static function required_sample_data() {
60 // We require course because, although calculate_sample only reads context, we need the context to be course
62 return array('context', 'course');
68 * @param int $sampleid
69 * @param string $sampleorigin
70 * @param int|false $notusedstarttime
71 * @param int|false $notusedendtime
74 public function calculate_sample($sampleid, $sampleorigin, $notusedstarttime = false, $notusedendtime = false) {
76 $context = $this->retrieve('context', $sampleid);
78 if (is_null($this->teacherroleids)) {
79 $this->teacherroleids = array_keys(get_archetype_roles('editingteacher') + get_archetype_roles('teacher'));
82 foreach ($this->teacherroleids as $role) {
83 // We look for roles, not enrolments as a teacher assigned at category level is supposed to be a
85 $teachers = get_role_users($role, $context, false, 'u.id', 'u.id');
87 return self::get_max_value();
91 return self::get_min_value();