-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathview.php
More file actions
208 lines (159 loc) · 7.2 KB
/
view.php
File metadata and controls
208 lines (159 loc) · 7.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<?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/>.
/**
* Prints a particular instance of stopwatch
*
* You can have a rather longer description of the file as well,
* if you like, and it can span multiple lines.
*
* @package mod_stopwatch
* @copyright 2015 2015 Iñaki Villanueva <inakivillanueva@hotmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
// Replace stopwatch with the name of your module and remove this line.
require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
require_once(dirname(__FILE__).'/lib.php');
$id = optional_param('id', 0, PARAM_INT); // Course_module ID, or
$n = optional_param('n', 0, PARAM_INT); // ... stopwatch instance ID - it should be named as the first character of the module.
if ($id) {
$cm = get_coursemodule_from_id('stopwatch', $id, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$stopwatch = $DB->get_record('stopwatch', array('id' => $cm->instance), '*', MUST_EXIST);
} else if ($n) {
$stopwatch = $DB->get_record('stopwatch', array('id' => $n), '*', MUST_EXIST);
$course = $DB->get_record('course', array('id' => $stopwatch->course), '*', MUST_EXIST);
$cm = get_coursemodule_from_instance('stopwatch', $stopwatch->id, $course->id, false, MUST_EXIST);
} else {
error('Debe especificar un ID course_module o un ID de instancia');
}
require_login($course, true, $cm);
$event = \mod_stopwatch\event\course_module_viewed::create(array(
'objectid' => $PAGE->cm->instance,
'context' => $PAGE->context,
));
$event->add_record_snapshot('course', $PAGE->course);
$event->add_record_snapshot($PAGE->cm->modname, $stopwatch);
$event->trigger();
// Print the page header.
$PAGE->set_url('/mod/stopwatch/view.php', array('id' => $cm->id));
$PAGE->set_title(format_string($stopwatch->name));
$PAGE->set_heading(format_string($course->fullname));
/*
* Other things you may want to set - remove if not needed.
* $PAGE->set_cacheable(false);
* $PAGE->set_focuscontrol('some-html-id');
* $PAGE->add_body_class('stopwatch-'.$somevar);
*/
// Output starts here.
echo $OUTPUT->header();
if (isset($_POST["submitbutton"]) && !empty($_POST["submitbutton"])) {
$stopwatch->swactivityfromid = $cm->id;
$stopwatch->swuserid = $USER->id;
$stopwatch->swtimestart = $_POST['starttime'];
$stopwatch->swtimefinish = $_POST['endtime'];
$stopwatch->timecreated = time();
$stopwatch->timemodified = time();
$stopwatch->id = $DB->insert_record('stopwatch', $stopwatch);
stopwatch_grade_item_update($stopwatch);
if (!$PAGE->user_is_editing()) { // si no se está en modo edición del Curso
echo $OUTPUT->heading("El tiempo de lectura ha sido guardado y pasamos a la prueba");
$url = $CFG->httpswwwroot . "/mod/quiz/view.php?id=".$stopwatch->swactivitytoid;
echo $OUTPUT->heading('<div class="continuebutton">(<a href="'.$url.'">Continuar</a>)</div>');
}
else echo $OUTPUT->heading("Pasamos a la prueba de lectura eficaz si no se está en modo edición del curso! Por favor desactiva el modo edición");
}
else {
if ($stopwatch->intro) {
echo $OUTPUT->box(format_module_intro('stopwatch', $stopwatch, $cm->id), 'generalbox mod_introbox', 'stopwatchintro');
}
echo $OUTPUT->heading('
<script>
var timein=0;
var timeout=0; // tiempo en segundos
var endtime=0; //
function startStop(element) {
if(timeout==0) {
// empezar el cronometro
element.value="Detener";
// Obtenemos el time inicial
timein=new Date().getTime();
document.getElementById("swtimestart").value = timein;
// Guardamos el valor inicial en la base de datos del navegador
localStorage.setItem("timein",timein);
// iniciamos el proceso
cronometer();
}
else{
// obtener time final
endtime= new Date().getTime();
document.getElementById("swtimefinish").value = endtime;
//alert(starttime+" "+endtime+" "+timein+" = "+timeout+" segundos");
// detener el cronometro
element.value="Empezar";
clearTimeout(timeout);
// Eliminamos el valor inicial guardado
localStorage.removeItem("timein");
timeout=0;
document.getElementById("enviar").innerHTML = "<input name=\"submitbutton\" value=\"Pasar a la prueba\" id=\"id_submitbutton\" type=\"submit\">";
document.getElementById("boton").disabled = true;
}
}
function cronometer() {
// obtener la fecha actual
var now = new Date().getTime();
// obtenemos la diferencia entre la fecha actual y la de inicio
var diff=new Date(now-timein);
// mostramos la diferencia entre la fecha actual y la inicial
var result=LeadingZero(diff.getUTCHours())+":"+LeadingZero(diff.getUTCMinutes())+":"+LeadingZero(diff.getUTCSeconds());
document.getElementById("crono").innerHTML = result;
// Indicamos que se ejecute esta función nuevamente dentro de 1 segundo
timeout=setTimeout("cronometer()",1000);
}
/* Funcion que pone un 0 delante de un valor si es necesario */
function LeadingZero(Time) {
return (Time < 10) ? "0" + Time : + Time;
}
window.onload=function() {
if(localStorage.getItem("timein")!=null) {
// Si al iniciar el navegador, la variable timein que se guarda en la base de datos del navegador tiene valor, cargamos el valor // y iniciamos el proceso.
timein=localStorage.getItem("timein");
document.getElementById("boton").value="Detener";
cronometer();
}
}
</script>
<style>
.crono_wrapper {text-align:center;width:200px;}
</style>
<form id="cronoform" name="cronoform" method="post">
<input type="hidden" id="swtimestart" name="starttime" value="">
<input type="hidden" id="swtimefinish" name="endtime" value="">
<input type="hidden" type="text" id="id" name="id" value="'.$cm->id.'">
<input type="hidden" type="text" id="n" name="n" value="'.$stopwatch->id.'">
<div class="crono_wrapper">
<h2 id="crono">00:00:00</h2>
<input type="button" value="Empezar" id="boton" onclick="startStop(this);">
</div>
<div class="enviar_wrapper">
<h2 id="enviar"></h2>
</div>
</form>
');
// Replace the following lines with you own code.
//echo $OUTPUT->heading('Al terminar la lectura se accede a la prueba de lectura eficaz.');
}
// Finish the page.
echo $OUTPUT->footer();