No me funciona el bloque en la versión 2.7. SOS
Buenas noches desde Caracas, les escribo para solicitar de su ayuda para resolver el problema que estoy adjuntando en el siguiente reporte. Donde no me funciona el bloque de dedicación al curso. Lo instalamos sin problemas, todo nos apareció "ok" en color verde y no realiza los cálculos respectivos
Adjunto la captura de pantalla
Gracias de antemano!
Carlos
Comments (8)
-
-
reporter Buenas noches Aday, ya intenté verificar los items que me envió, De todas formas me he dado cuenta que la nueva versión tiene la siguiente tabla mdl_logstore_standard_log que es la que esta almacenando los logs de la anterior moodle_logs. ¿Dónde puedo configurar ese cambio de tabla? Saludos y gracias!
-
Si la estructura de la tabla es la misma, debería funcionar con los siguientes cambios:
En dedication_lib.php cambia 'log' por 'logstore_standard_log' en las líneas 55 y 138.
No obstante probablemente sean necesarios más cambios. Parece que Moodle 2.7 tiene bastantes cambios de este tipo que requieren una revisión profunda de los plugins.
-
Hola Aday,
He probado a editar esas dos lineas con los cambios que propones y Moodle (2.7.3) me ha dado un DMLException, así que parece que sí que serán necesarios más cambios para hacerlo funcionar en >Moodle 2.7.
He entrado a la BD y he visto que la nueva tabla tiene algunas columnas distintas a las que utiliza la query (course --> courseid, time --> timecreated), así que las he sustituido en la construcción de la query (where y order by) y he conseguido que funcione:
--- dedication_lib.php 2014-03-05 17:16:20.000000000 +0100 +++ dedication_lib_27.php 2014-12-02 12:14:02.000000000 +0100 @@ -39,7 +39,7 @@ $rows = array(); - $where = 'course = :courseid AND userid = :userid AND time >= :mintime AND time <= :maxtime'; + $where = 'courseid = :courseid AND userid = :userid AND timecreated >= :mintime AND timecreated <= :maxtime'; $params = array( 'courseid' => $this->course->id, 'userid' => 0, @@ -52,7 +52,7 @@ foreach ($students as $user) { $daysconnected = array(); $params['userid'] = $user->id; - $logs = $DB->get_records_select('log', $where, $params, 'time ASC', 'id,time'); + $logs = $DB->get_records_select('logstore_standard_log', $where, $params, 'timecreated ASC', 'id,timecreated'); if ($logs) { $previouslog = array_shift($logs); $previouslogtime = $previouslog->time; @@ -128,14 +128,14 @@ function get_user_dedication($user, $simple = false) { global $DB; - $where = 'course = :courseid AND userid = :userid AND time >= :mintime AND time <= :maxtime'; + $where = 'courseid = :courseid AND userid = :userid AND timecreated >= :mintime AND timecreated <= :maxtime'; $params = array( 'courseid' => $this->course->id, 'userid' => $user->id, 'mintime' => $this->mintime, 'maxtime' => $this->maxtime ); - $logs = $DB->get_records_select('log', $where, $params, 'time ASC', 'id,time,ip'); + $logs = $DB->get_records_select('logstore_standard_log', $where, $params, 'timecreated ASC', 'id,timecreated,ip'); if ($simple) { // Return total dedication time in seconds
Con este cambio se pueden consultar los datos del nuevo sistema de logs, pero creo que lo ideal sería añadir la posibilidad de consultar el nuevo sistema de logs manteniendo la posibilidad de consultar también el "legacy log", ¿no?
Edito para añadir: en las pruebas que he hecho no consigo que en el detalle de dedicación de cada usuario aparezcan los datos, quizás ahí haya que hacer algún cambio más.
-
<?php // This file is part of Moodle - http://moodle.org/ // // Moodle is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // Moodle is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see http://www.gnu.org/licenses/.
// Default session time limit in seconds define('BLOCK_DEDICATION_DEFAULT_SESSION_LIMIT', 60 * 60); // Ignore sessions with a duration less than defined value in seconds define('BLOCK_DEDICATION_IGNORE_SESSION_TIME', 59); // Default regeneration time in seconds define('BLOCK_DEDICATION_DEFAULT_REGEN_TIME', 60 * 15);
class block_dedication_manager { protected $course; protected $mintime; protected $maxtime; protected $limit;
function __construct($course, $mintime, $maxtime, $limit) { $this->course = $course; $this->mintime = $mintime; $this->maxtime = $maxtime; $this->limit = $limit; } function get_students_dedication($students) { global $DB; $rows = array(); $where = 'courseid = :courseid AND userid = :userid AND timecreated >= :mintime AND timecreated <= :maxtime'; $params = array( 'courseid' => $this->course->id, 'userid' => 0, 'mintime' => $this->mintime, 'maxtime' => $this->maxtime ); $perioddays = ($this->maxtime - $this->mintime) / DAYSECS; foreach ($students as $user) { $daysconnected = array(); $params['userid'] = $user->id; $logs = $DB->get_records_select('logstore_standard_log', $where, $params, 'timecreated ASC', 'id,timecreated'); if ($logs) { $previouslog = array_shift($logs); $previouslogtime = $previouslog->timecreated; $sessionstart = $previouslog->timecreated; $dedication = 0; $daysconnected[date('Y-m-d', $previouslog->timecreated)] = 1; foreach ($logs as $log) { if (($log->timecreated - $previouslogtime) > $this->limit) { $dedication += $previouslogtime - $sessionstart; $sessionstart = $log->timecreated; } $previouslogtime = $log->timecreated; $daysconnected[date('Y-m-d', $log->timecreated)] = 1; } $dedication += $previouslogtime - $sessionstart; } else { $dedication = 0; } $daysconnected = count($daysconnected); $groups = groups_get_user_groups($this->course->id, $user->id); $group = !empty($groups) && !empty($groups[0]) ? $groups[0][0] : 0; $rows[] = (object) array( 'user' => $user, 'groupid' => $group, 'dedicationtime' => $dedication, 'connectionratio' => round($daysconnected / $perioddays, 2), ); } return $rows; } function download_students_dedication($rows) { $groups = groups_get_all_groups($this->course->id); $headers = array( array( get_string('sincerow', 'block_dedication'), userdate($this->mintime), get_string('torow', 'block_dedication'), userdate($this->maxtime), get_string('perioddiffrow', 'block_dedication'), format_time($this->maxtime - $this->mintime), ), array(''), array( get_string('firstname'), get_string('lastname'), get_string('group'), get_string('dedicationrow', 'block_dedication') . ' (' . get_string('mins') . ')', get_string('dedicationrow', 'block_dedication'), get_string('connectionratiorow', 'block_dedication'), ), ); foreach ($rows as $index => $row) { $rows[$index] = array( $row->user->firstname, $row->user->lastname, isset($groups[$row->groupid]) ? $groups[$row->groupid]->name : '', round($row->dedicationtime / MINSECS), block_dedication_manager::format_dedication($row->dedicationtime), $row->connectionratio, ); } $rows = array_merge($headers, $rows); return block_dedication_manager::generate_download("{$this->course->shortname}_dedication", $rows); } function get_user_dedication($user, $simple = false) { global $DB; $where = 'courseid = :courseid AND userid = :userid AND timecreated >= :mintime AND timecreated <= :maxtime'; $params = array( 'courseid' => $this->course->id, 'userid' => $user->id, 'mintime' => $this->mintime, 'maxtime' => $this->maxtime ); $logs = $DB->get_records_select('logstore_standard_log', $where, $params, 'timecreated ASC', 'id,timecreated,ip'); if ($simple) { // Return total dedication time in seconds $total = 0; if ($logs) { $previouslog = array_shift($logs); $previouslogtime = $previouslog->timecreated; $sessionstart = $previouslogtime; foreach ($logs as $log) { if (($log->timecreated - $previouslogtime) > $this->limit) { $dedication = $previouslogtime - $sessionstart; $total += $dedication; $sessionstart = $log->timecreated; } $previouslogtime = $log->timecreated; } $dedication = $previouslogtime - $sessionstart; $total += $dedication; } return $total; } else { // Return user sessions with details $rows = array(); if ($logs) { $previouslog = array_shift($logs); $previouslogtime = $previouslog->timecreated; $sessionstart = $previouslogtime; $ips = array($previouslog->ip => true); foreach ($logs as $log) { if (($log->timecreated - $previouslogtime) > $this->limit) { $dedication = $previouslogtime - $sessionstart; // Ignore sessions with a really short duration if ($dedication > BLOCK_DEDICATION_IGNORE_SESSION_TIME) { $rows[] = (object) array('start_date' => $sessionstart, 'dedicationtime' => $dedication, 'ips' => array_keys($ips)); $ips = array(); } $sessionstart = $log->timecreated; } $previouslogtime = $log->timecreated; $ips[$log->ip] = true; } $dedication = $previouslogtime - $sessionstart; // Ignore sessions with a really short duration if ($dedication > BLOCK_DEDICATION_IGNORE_SESSION_TIME) { $rows[] = (object) array('start_date' => $sessionstart, 'dedicationtime' => $dedication, 'ips' => array_keys($ips)); } } return $rows; } } function download_user_dedication($user, $rows) { $headers = array( array( get_string('sincerow', 'block_dedication'), userdate($this->mintime), get_string('torow', 'block_dedication'), userdate($this->maxtime), get_string('perioddiffrow', 'block_dedication'), format_time($this->maxtime - $this->mintime), ), array(''), array( get_string('firstname'), get_string('lastname'), get_string('sessionstart', 'block_dedication'), get_string('dedicationrow', 'block_dedication') . ' ' . get_string('secs'), get_string('sessionduration', 'block_dedication'), 'IP', ) ); foreach ($rows as $index => $row) { $rows[$index] = array( $user->firstname, $user->lastname, userdate($row->start_date), $row->dedicationtime, block_dedication_manager::format_dedication($row->dedicationtime), implode(', ', $row->ips), ); } $rows = array_merge($headers, $rows); return block_dedication_manager::generate_download("{$this->course->shortname}_dedication", $rows); } // Formats time based in Moodle function format_time($totalsecs) static function format_dedication($totalsecs) { $totalsecs = abs($totalsecs); $str = new stdClass(); $str->hour = get_string('hour'); $str->hours = get_string('hours'); $str->min = get_string('min'); $str->mins = get_string('mins'); $str->sec = get_string('sec'); $str->secs = get_string('secs'); $hours = floor($totalsecs / HOURSECS); $remainder = $totalsecs - ($hours * HOURSECS); $mins = floor($remainder / MINSECS); $secs = $remainder - ($mins * MINSECS); $ss = ($secs == 1) ? $str->sec : $str->secs; $sm = ($mins == 1) ? $str->min : $str->mins; $sh = ($hours == 1) ? $str->hour : $str->hours; $ohours = ''; $omins = ''; $osecs = ''; if ($hours) $ohours = $hours . ' ' . $sh; if ($mins) $omins = $mins . ' ' . $sm; if ($secs) $osecs = $secs . ' ' . $ss; if ($hours) return trim($ohours . ' ' . $omins); if ($mins) return trim($omins . ' ' . $osecs); if ($secs) return $osecs; return get_string('now'); } // Formats ips static function format_ips($ips) { return implode(', ', array_map('block_dedication_manager::link_ip', $ips)); } // Generates an linkable ip static function link_ip($ip) { return html_writer::link("http://en.utrace.de/?query=$ip", $ip, array('target' => '_blank')); } // Table styles static function get_table_styles() { global $PAGE; // Twitter Bootstrap styling if (in_array('bootstrapbase', $PAGE->theme->parents)) { $styles = array( 'table_class' => 'table table-striped table-bordered table-hover table-condensed table-dedication', 'header_style' => 'background-color: #333; color: #fff;' ); } else { $styles = array( 'table_class' => 'table-dedication', 'header_style' => '' ); } return $styles; } // Generate generic Excel file for download static function generate_download($download_name, $rows) { global $CFG; require_once($CFG->libdir. '/excellib.class.php'); $workbook = new MoodleExcelWorkbook('-', 'excel5'); $workbook->send(clean_filename($download_name)); $myxls = $workbook->add_worksheet(get_string('pluginname', 'block_dedication')); $row_count = 0; foreach ($rows as $row) { foreach ($row as $index => $content) { $myxls->write($row_count, $index, $content); } $row_count++; } $workbook->close(); return $workbook; }
}
?>
Gracias por tu ayuda, Así quedo mi archivo después de actualizarlo a la nueva versión de moodle 2.7 y así si muestra el detalle de la dedicación de cada usuario
-
Gracias por las modificaciones enviadas, no obstante no utilizan correctamente el nuevo sistema de log de Moodle y he realizado una nueva versión que si que lo hace.
Pueden descargar la versión actualizada a Moodle 2.7 / 2.8 desde este enlace https://bitbucket.org/ciceidev/moodle_block_dedication/get/MOODLE_27_STABLE.zip
Aún no ha sido publicada oficialmente en el sitio de Moodle.
-
- changed status to resolved
Falta publicar la versión en el sitio de Moodle
-
- removed version
Removing version: Moodle 2+ (automated comment)
- Log in to comment
Hola Carlos,
En la tabla marca en el número de conexiones 0, lo que puede indicar que en el intervalo de tiempo que has seleccionado no hay ninguna entrada en los logs de moodle. Esto puede deberse a que han sido desactivados, a que hayan sido borrados por mantenimiento o incluso a que la fecha y hora del servidor no estuviera bien configurada y se hayan grabado con otra fecha (este caso sería muy raro)
El funcionamiento del plugin se basa totalmente en estos logs, y si no encuentra ninguna no puede hacer ningún cálculo. Para verificar si hay logs o no, pueden mirar en la tabla mdl_logs.
Por último, es posible también que sea una incidencia con la nueva versión de Moodle 2.7 la cual no hemos podido probar aún debido a sus requisitos.