Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
 * redirect to the helper page
19
 *
20
 */
21
 
22
/**
23
 * redirect class
24
 *
25
 */
26
class training_redirector{
27
 
28
    /**
29
     * init function is directly called from events.php
30
     *
31
     * @param observers $eventdata
32
     */
33
    public static function init($eventdata) {
34
 
35
        global $CFG;
36
        global $USER;
37
 
38
        $userid = $USER->id;
39
 
40
        $conditions = [
41
            'userid' => $userid,
42
        ];
43
 
44
 
45
 
46
        if (isloggedin()) {
47
 
48
            if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
49
                $url = preg_replace("/^http:/i", "https:", $CFG->wwwroot);
50
 
51
                redirect($url.'/report/training/storage_helper_page.php');
52
 
53
            } else {
54
 
55
                redirect($CFG->wwwroot.'/report/training/storage_helper_page.php');
56
 
57
            }
58
        }
59
    }
60
 
61
 
62
    /**********************************************************************************************
63
     * @var string Block table name.
64
     */
65
    private static $table = 'report_training_activities';
66
    private static $table_last_access = 'report_training_lastaccess';
67
    /**
68
     *
69
     * @param \core\event\base $event
70
     */
71
    public static function store(\core\event\base $event) {
72
        global $DB;
73
 
74
        if (!isloggedin() or \core\session\manager::is_loggedinas() or isguestuser()) {
75
            // No access tracking.
76
            return;
77
        }
78
 
79
       //var_dump($event->get_data());
80
       //die('entro a store');
81
 
82
        $conditions = [
83
            'userid' => $event->userid
84
        ];
85
 
86
 
87
        $records = $DB->get_records(self::$table, $conditions, "timeaccess DESC");
88
 
89
        // if (!empty($records)){
90
 
91
            foreach ($records as $record) {
92
                if (($record->userid == $event->userid) && ($record->cmid == $event->contextinstanceid)) {
93
                    $conditions = [
94
                            'userid' => $event->userid,
95
                            'cmid' => $event->contextinstanceid
96
                    ];
97
                    $DB->set_field(self::$table, 'timeaccess', $event->timecreated, $conditions);
98
                    return;
99
                }
100
            }
101
        // }
102
 
103
 
104
        $modnom=['md'=>$event->component];
105
 
106
        $cadena = current($modnom);
107
 
108
        list($prefijo, $name) = explode("_", $cadena);
109
 
110
 
111
 
112
        $urls=[
113
             'viewurl' => (new moodle_url('/mod/'.$name.'/view.php', array('id' => $event->contextinstanceid)))->out(false),
114
             //'courseviewurl' => (new moodle_url('/course/view.php', array('id' => $eventdata->courseid)))->out(false),
115
        ];
116
 
117
 
118
 
119
        $eventdata = new \stdClass();
120
        $eventdata->cmid = $event->contextinstanceid;
121
        $eventdata->timeaccess = $event->timecreated;
122
        $eventdata->courseid = $event->courseid;
123
        $eventdata->userid = $event->userid;
124
        $eventdata->eventname = $event->eventname;
125
        $eventdata->component = $event->component;
126
        $eventdata->action = $event->action;
127
        $eventdata->target = $event->target;
128
        $eventdata->viewurl = $urls['viewurl'];
129
        //$eventdata->courseviewurl = $conditions['courseviewurl'];
130
        //var_dump($eventdata);
131
 
132
 
133
        $DB->insert_record(self::$table, $eventdata);
134
 
135
        $user_last_access = $DB->get_record(self::$table_last_access, ['userid' => $event->userid,]);
136
 
137
        if ($user_last_access) {
138
            $eventdata->id = $user_last_access->id;
139
            $DB->update_record(self::$table_last_access, $eventdata);
140
        } else {
141
            $DB->insert_record(self::$table_last_access, $eventdata);
142
        }
143
 
144
    }
145
 
146
    /**
147
     * Remove record when course module is deleted.
148
     *
149
     * @param \core\event\base $event
150
     */
151
    public static function remove(\core\event\base $eventdata) {
152
        global $DB;
153
 
154
        $DB->delete_records(self::$table, array('cmid' => $eventdata->contextinstanceid));
155
    }
156
 
157
    /**
158
     * completed course.
159
     *
160
     * @param \core\event\base $event
161
     */
162
    public static function completed(\core\event\base $eventdata) {
163
 
164
       var_dump($eventdata->get_data());
165
 
166
    }
167
 
168
 
169
}