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 * Model logs table class. 19 * 20 * @package tool_analytics 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 tool_analytics\output; 26 27 defined('MOODLE_INTERNAL') || die; 28 require_once($CFG->libdir . '/tablelib.php'); 29 30 /** 31 * Model logs table class. 32 * 33 * @package tool_analytics 34 * @copyright 2017 David Monllao {@link http://www.davidmonllao.com} 35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 36 */ 37 class model_logs extends \table_sql { 38 39 /** 40 * @var \core_analytics\model 41 */ 42 protected $model = null; 43 44 /** 45 * @var string|false 46 */ 47 protected $evaluationmode = false; 48 49 /** 50 * Sets up the table_log parameters. 51 * 52 * @param string $uniqueid unique id of form. 53 * @param \core_analytics\model $model 54 */ 55 public function __construct($uniqueid, $model) { 56 global $PAGE; 57 58 parent::__construct($uniqueid); 59 60 $this->model = $model; 61 62 $this->set_attribute('class', 'modellog generaltable generalbox'); 63 $this->set_attribute('aria-live', 'polite'); 64 65 $this->define_columns(array('time', 'version', 'evaluationmode', 'indicators', 'timesplitting', 66 'accuracy', 'info', 'usermodified')); 67 $this->define_headers(array( 68 get_string('time'), 69 get_string('version'), 70 get_string('evaluationmode', 'tool_analytics'), 71 get_string('indicators', 'tool_analytics'), 72 get_string('timesplittingmethod', 'analytics'), 73 get_string('accuracy', 'tool_analytics'), 74 get_string('info', 'tool_analytics'), 75 get_string('fullnameuser'), 76 )); 77 78 $evaluationmodehelp = new \help_icon('evaluationmode', 'tool_analytics'); 79 $this->define_help_for_headers([null, null, $evaluationmodehelp, null, null, null, null, null]); 80 81 $this->pageable(true); 82 $this->collapsible(false); 83 $this->sortable(false); 84 $this->is_downloadable(false); 85 86 $this->evaluationmode = optional_param('evaluationmode', false, PARAM_ALPHANUM); 87 if ($this->evaluationmode && $this->evaluationmode != 'configuration' && $this->evaluationmode != 'trainedmodel') { 88 $this->evaluationmode = ''; 89 } 90 91 $this->define_baseurl($PAGE->url); 92 } 93 94 /** 95 * Generate the version column. 96 * 97 * @param \stdClass $log log data. 98 * @return string HTML for the version column 99 */ 100 public function col_version($log) { 101 $recenttimestr = get_string('strftimerecent', 'core_langconfig'); 102 return userdate($log->version, $recenttimestr); 103 } 104 105 /** 106 * Generate the evaluation mode column. 107 * 108 * @param \stdClass $log log data. 109 * @return string HTML for the evaluationmode column 110 */ 111 public function col_evaluationmode($log) { 112 return get_string('evaluationmodecol' . $log->evaluationmode, 'tool_analytics'); 113 } 114 /** 115 * Generate the time column. 116 * 117 * @param \stdClass $log log data. 118 * @return string HTML for the time column 119 */ 120 public function col_time($log) { 121 $recenttimestr = get_string('strftimerecent', 'core_langconfig'); 122 return userdate($log->timecreated, $recenttimestr); 123 } 124 125 /** 126 * Generate the indicators column. 127 * 128 * @param \stdClass $log log data. 129 * @return string HTML for the indicators column 130 */ 131 public function col_indicators($log) { 132 $indicatorclasses = json_decode($log->indicators); 133 $indicators = array(); 134 foreach ($indicatorclasses as $indicatorclass) { 135 $indicator = \core_analytics\manager::get_indicator($indicatorclass); 136 if ($indicator) { 137 $indicators[] = $indicator->get_name(); 138 } else { 139 debugging('Can\'t load ' . $indicatorclass . ' indicator', DEBUG_DEVELOPER); 140 } 141 } 142 return '<ul><li>' . implode('</li><li>', $indicators) . '</li></ul>'; 143 } 144 145 /** 146 * Generate the context column. 147 * 148 * @param \stdClass $log log data. 149 * @return string HTML for the context column 150 */ 151 public function col_timesplitting($log) { 152 $timesplitting = \core_analytics\manager::get_time_splitting($log->timesplitting); 153 return $timesplitting->get_name(); 154 } 155 156 /** 157 * Generate the accuracy column. 158 * 159 * @param \stdClass $log log data. 160 * @return string HTML for the accuracy column 161 */ 162 public function col_accuracy($log) { 163 return strval(round($log->score * 100, 2)) . '%'; 164 } 165 166 /** 167 * Generate the info column. 168 * 169 * @param \stdClass $log log data. 170 * @return string HTML for the score column 171 */ 172 public function col_info($log) { 173 global $PAGE; 174 175 if (empty($log->info) && empty($log->dir)) { 176 return ''; 177 } 178 179 $info = array(); 180 if (!empty($log->info)) { 181 $info = json_decode($log->info); 182 } 183 if (!empty($log->dir)) { 184 $info[] = get_string('predictorresultsin', 'tool_analytics', $log->dir); 185 } 186 $PAGE->requires->js_call_amd('tool_analytics/log_info', 'loadInfo', array($log->id, $info)); 187 return \html_writer::link('#', get_string('view'), array('data-model-log-id' => $log->id)); 188 } 189 190 /** 191 * Generate the usermodified column. 192 * 193 * @param \stdClass $log log data. 194 * @return string HTML for the usermodified column 195 */ 196 public function col_usermodified($log) { 197 $user = \core_user::get_user($log->usermodified); 198 return fullname($user); 199 } 200 201 /** 202 * Query the logs table. Store results in the object for use by build_table. 203 * 204 * @param int $pagesize size of page for paginated displayed table. 205 * @param bool $useinitialsbar do you want to use the initials bar. 206 */ 207 public function query_db($pagesize, $useinitialsbar = true) { 208 $total = count($this->model->get_logs()); 209 $this->pagesize($pagesize, $total); 210 $this->rawdata = $this->model->get_logs($this->get_page_start(), $this->get_page_size()); 211 212 // Set initial bars. 213 if ($useinitialsbar) { 214 $this->initialbars($total > $pagesize); 215 } 216 } 217 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body