MDL-57791 analytics: Remove reference to removed config var
[moodle.git] / course / classes / analytics / indicator / no_teacher.php
CommitLineData
357507b4
DM
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 teacher 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
25namespace core_course\analytics\indicator;
26
27defined('MOODLE_INTERNAL') || die();
28
29/**
30 * No teacher indicator.
31 *
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
35 */
36class no_teacher extends \core_analytics\local\indicator\binary {
37
950b1d78
DM
38 /**
39 * Teacher role ids.
40 *
41 * @var array|null
42 */
43 protected $teacherroleids = null;
44
413f19bc
DM
45 /**
46 * get_name
47 *
48 * @return string
49 */
357507b4
DM
50 public static function get_name() {
51 return get_string('indicator:noteacher', 'moodle');
52 }
53
413f19bc
DM
54 /**
55 * required_sample_data
56 *
57 * @return string[]
58 */
357507b4
DM
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
61 // or below.
62 return array('context', 'course');
63 }
64
1a846139
DM
65 /**
66 * calculate_sample
67 *
68 * @param int $sampleid
69 * @param string $sampleorigin
1cc2b4ba
DM
70 * @param int|false $notusedstarttime
71 * @param int|false $notusedendtime
1a846139
DM
72 * @return float
73 */
357507b4
DM
74 public function calculate_sample($sampleid, $sampleorigin, $notusedstarttime = false, $notusedendtime = false) {
75
76 $context = $this->retrieve('context', $sampleid);
77
950b1d78
DM
78 if (is_null($this->teacherroleids)) {
79 $this->teacherroleids = array_keys(get_archetype_roles('editingteacher') + get_archetype_roles('teacher'));
80 }
81
82 foreach ($this->teacherroleids as $role) {
1a846139
DM
83 // We look for roles, not enrolments as a teacher assigned at category level is supposed to be a
84 // course teacher.
85 $teachers = get_role_users($role, $context, false, 'u.id', 'u.id');
86 if ($teachers) {
357507b4
DM
87 return self::get_max_value();
88 }
89 }
90
91 return self::get_min_value();
92 }
93}