See Release Notes
Long Term Support Release
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 recent accesses. 19 * 20 * @package core_course 21 * @copyright 2019 David MonllaĆ³ {@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\target; 26 27 defined('MOODLE_INTERNAL') || die(); 28 29 /** 30 * No recent accesses. 31 * 32 * @package core_course 33 * @copyright 2019 David MonllaĆ³ {@link http://www.davidmonllao.com} 34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 35 */ 36 class no_recent_accesses extends course_enrolments { 37 38 /** 39 * Machine learning backends are not required to predict. 40 * 41 * @return bool 42 */ 43 public static function based_on_assumptions() { 44 return true; 45 } 46 47 /** 48 * Returns the name. 49 * 50 * If there is a corresponding '_help' string this will be shown as well. 51 * 52 * @return \lang_string 53 */ 54 public static function get_name() : \lang_string { 55 return new \lang_string('target:norecentaccesses', 'course'); 56 } 57 58 /** 59 * Returns the body message for the insight. 60 * 61 * @param \context $context 62 * @param string $contextname 63 * @param \stdClass $user 64 * @param \moodle_url $insighturl 65 * @return array The plain text message and the HTML message 66 */ 67 public function get_insight_body(\context $context, string $contextname, \stdClass $user, \moodle_url $insighturl): array { 68 global $OUTPUT; 69 70 $a = (object)['coursename' => $contextname, 'userfirstname' => $user->firstname]; 71 $fullmessage = get_string('norecentaccessesinfomessage', 'course', $a) . PHP_EOL . PHP_EOL . $insighturl->out(false); 72 $fullmessagehtml = $OUTPUT->render_from_template('core_analytics/insight_info_message', 73 ['url' => $insighturl->out(false), 'insightinfomessage' => get_string('norecentaccessesinfomessage', 'course', $a)] 74 ); 75 76 return [$fullmessage, $fullmessagehtml]; 77 } 78 79 /** 80 * Only past stuff whose start matches the course start. 81 * 82 * @param \core_analytics\local\time_splitting\base $timesplitting 83 * @return bool 84 */ 85 public function can_use_timesplitting(\core_analytics\local\time_splitting\base $timesplitting): bool { 86 return ($timesplitting instanceof \core_analytics\local\time_splitting\past_periodic); 87 } 88 89 /** 90 * Discards courses that are not yet ready to be used for prediction. 91 * 92 * @param \core_analytics\analysable $course 93 * @param bool $fortraining 94 * @return true|string 95 */ 96 public function is_valid_analysable(\core_analytics\analysable $course, $fortraining = true) { 97 98 if (!$course->was_started()) { 99 return get_string('coursenotyetstarted', 'course'); 100 } 101 102 if (!$this->students = $course->get_students()) { 103 return get_string('nocoursestudents', 'course'); 104 } 105 106 if (!$fortraining && !$course->get_course_data()->visible) { 107 return get_string('hiddenfromstudents'); 108 } 109 110 if ($course->get_end() && $course->get_end() < $course->get_start()) { 111 return get_string('errorendbeforestart', 'course'); 112 } 113 114 // Finished courses can not be used to get predictions. 115 if (!$fortraining && $course->is_finished()) { 116 return get_string('coursealreadyfinished', 'course'); 117 } 118 119 return true; 120 } 121 122 /** 123 * Do the user has any read action in the course? 124 * 125 * @param int $sampleid 126 * @param \core_analytics\analysable $analysable 127 * @param int $starttime 128 * @param int $endtime 129 * @return float|null 0 -> accesses, 1 -> no accesses. 130 */ 131 protected function calculate_sample($sampleid, \core_analytics\analysable $analysable, $starttime = false, $endtime = false) { 132 133 if (!$this->enrolment_active_during_analysis_time($sampleid, $starttime, $endtime)) { 134 // We should not use this sample as the analysis results could be misleading. 135 return null; 136 } 137 138 $readactions = $this->retrieve('\core\analytics\indicator\any_course_access', $sampleid); 139 if ($readactions == \core\analytics\indicator\any_course_access::get_min_value()) { 140 return 1; 141 } 142 return 0; 143 } 144 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body