AutorÃa | Ultima modificación | Ver Log |
<?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/>.
/**
* redirect to the helper page
*
*/
/**
* redirect class
*
*/
class training_redirector{
/**
* init function is directly called from events.php
*
* @param observers $eventdata
*/
public static function init($eventdata) {
global $CFG;
global $USER;
$userid = $USER->id;
$conditions = [
'userid' => $userid,
];
if (isloggedin()) {
if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
$url = preg_replace("/^http:/i", "https:", $CFG->wwwroot);
redirect($url.'/report/training/storage_helper_page.php');
} else {
redirect($CFG->wwwroot.'/report/training/storage_helper_page.php');
}
}
}
/**********************************************************************************************
* @var string Block table name.
*/
private static $table = 'report_training_activities';
private static $table_last_access = 'report_training_lastaccess';
/**
*
* @param \core\event\base $event
*/
public static function store(\core\event\base $event) {
global $DB;
if (!isloggedin() or \core\session\manager::is_loggedinas() or isguestuser()) {
// No access tracking.
return;
}
//var_dump($event->get_data());
//die('entro a store');
$conditions = [
'userid' => $event->userid
];
$records = $DB->get_records(self::$table, $conditions, "timeaccess DESC");
// if (!empty($records)){
foreach ($records as $record) {
if (($record->userid == $event->userid) && ($record->cmid == $event->contextinstanceid)) {
$conditions = [
'userid' => $event->userid,
'cmid' => $event->contextinstanceid
];
$DB->set_field(self::$table, 'timeaccess', $event->timecreated, $conditions);
return;
}
}
// }
$modnom=['md'=>$event->component];
$cadena = current($modnom);
list($prefijo, $name) = explode("_", $cadena);
$urls=[
'viewurl' => (new moodle_url('/mod/'.$name.'/view.php', array('id' => $event->contextinstanceid)))->out(false),
//'courseviewurl' => (new moodle_url('/course/view.php', array('id' => $eventdata->courseid)))->out(false),
];
$eventdata = new \stdClass();
$eventdata->cmid = $event->contextinstanceid;
$eventdata->timeaccess = $event->timecreated;
$eventdata->courseid = $event->courseid;
$eventdata->userid = $event->userid;
$eventdata->eventname = $event->eventname;
$eventdata->component = $event->component;
$eventdata->action = $event->action;
$eventdata->target = $event->target;
$eventdata->viewurl = $urls['viewurl'];
//$eventdata->courseviewurl = $conditions['courseviewurl'];
//var_dump($eventdata);
$DB->insert_record(self::$table, $eventdata);
$user_last_access = $DB->get_record(self::$table_last_access, ['userid' => $event->userid,]);
if ($user_last_access) {
$eventdata->id = $user_last_access->id;
$DB->update_record(self::$table_last_access, $eventdata);
} else {
$DB->insert_record(self::$table_last_access, $eventdata);
}
}
/**
* Remove record when course module is deleted.
*
* @param \core\event\base $event
*/
public static function remove(\core\event\base $eventdata) {
global $DB;
$DB->delete_records(self::$table, array('cmid' => $eventdata->contextinstanceid));
}
/**
* completed course.
*
* @param \core\event\base $event
*/
public static function completed(\core\event\base $eventdata) {
var_dump($eventdata->get_data());
}
}