Skip to content

Commit c02a44d

Browse files
committed
New grade and ratings plus code cleanup.
1 parent 64e2e6e commit c02a44d

23 files changed

+1314
-1115
lines changed

attrem.php

+13-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*
2020
* This sub-module is called from gview.php, (View All Grades),
2121
* or from owngrades.php, (View my grades).
22-
* Currently it does NOT include an Are you sure check before it removes.
22+
* Currently it does include a, Confirm... check before it removes.
2323
*
2424
* @package mod_mootyper
2525
* @copyright 2011 Jaka Luthar ([email protected])
@@ -32,8 +32,6 @@
3232

3333
require(__DIR__ . '/../../config.php');
3434

35-
require_login($course, true, $cm);
36-
3735
global $DB;
3836

3937
$mid = optional_param('m_id', 0, PARAM_INT); // MooTyper id (mdl_mootyper).
@@ -47,12 +45,23 @@
4745
$cm = get_coursemodule_from_instance('mootyper', $mootyper->id, $course->id, false, MUST_EXIST);
4846

4947
$context = context_module::instance($cm->id);
48+
require_login($course, true, $cm);
5049

5150
if (isset($gradeid)) {
5251
$dbgrade = $DB->get_record('mootyper_grades', array('id' => $gradeid));
53-
// Changed from attempt_id to attemptid 01/29/18.
52+
// Changed from attempt_id to attemptid 20180129.
5453
$DB->delete_records('mootyper_attempts', array('id' => $dbgrade->attemptid));
5554
$DB->delete_records('mootyper_grades', array('id' => $dbgrade->id));
55+
56+
// 20200808 Delete ratings too.
57+
require_once($CFG->dirroot.'/rating/lib.php');
58+
$delopt = new stdClass;
59+
$delopt->contextid = $context->id;
60+
$delopt->component = 'mod_mootyper';
61+
$delopt->ratingarea = 'exercises';
62+
$delopt->itemid = $dbgrade->id;
63+
$rm = new rating_manager();
64+
$rm->delete_ratings($delopt);
5665
}
5766

5867
// Return to the View my grades or View all grades page.

backup/moodle2/backup_mootyper_stepslib.php

+5
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ protected function define_structure() {
5151
'timemodified',
5252
'timeopen',
5353
'timeclose',
54+
'assessed',
55+
'assesstimestart',
56+
'assesstimefinished',
57+
'scale',
58+
'grade_mootyper',
5459
'usepassword',
5560
'password',
5661
'exercise',

db/install.xml

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
2-
<XMLDB PATH="mod/mootyper/db" VERSION="20191229" COMMENT="XMLDB file for Moodle mod/mootyper"
2+
<XMLDB PATH="mod/mootyper/db" VERSION="20200731" COMMENT="XMLDB file for Moodle mod/mootyper"
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
55
>
@@ -15,6 +15,11 @@
1515
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="false" DEFAULT="0" SEQUENCE="false"/>
1616
<FIELD NAME="timeopen" TYPE="int" LENGTH="10" NOTNULL="false" DEFAULT="0" SEQUENCE="false"/>
1717
<FIELD NAME="timeclose" TYPE="int" LENGTH="10" NOTNULL="false" DEFAULT="0" SEQUENCE="false"/>
18+
<FIELD NAME="assessed" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
19+
<FIELD NAME="assesstimestart" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
20+
<FIELD NAME="assesstimefinish" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
21+
<FIELD NAME="scale" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
22+
<FIELD NAME="grade_mootyper" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
1823
<FIELD NAME="usepassword" TYPE="int" LENGTH="3" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
1924
<FIELD NAME="password" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false"/>
2025
<FIELD NAME="exercise" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>

db/upgrade.php

+53
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,59 @@ function xmldb_mootyper_upgrade($oldversion) {
304304
if (!$dbman->field_exists($table, $field)) {
305305
$dbman->add_field($table, $field);
306306
}
307+
// Mootyper savepoint reached.
308+
upgrade_mod_savepoint(true, 2019123100, 'mootyper');
309+
}
310+
// Four new fields added for version 3.9.1.
311+
if ($oldversion < 2020073100) {
312+
313+
// Define field assessed to be added to mootyper.
314+
$table = new xmldb_table('mootyper');
315+
$field = new xmldb_field('assessed', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'timeclose');
316+
317+
// Conditionally launch add field assessed.
318+
if (!$dbman->field_exists($table, $field)) {
319+
$dbman->add_field($table, $field);
320+
}
321+
322+
// Define field assesstimestart to be added to mootyper.
323+
$table = new xmldb_table('mootyper');
324+
$field = new xmldb_field('assesstimestart', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'assessed');
325+
326+
// Conditionally launch add field assesstimestart.
327+
if (!$dbman->field_exists($table, $field)) {
328+
$dbman->add_field($table, $field);
329+
}
330+
331+
// Define field assesstimefinish to be added to mootyper.
332+
$table = new xmldb_table('mootyper');
333+
$field = new xmldb_field('assesstimefinish', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'assesstimestart');
334+
335+
// Conditionally launch add field assesstimefinish.
336+
if (!$dbman->field_exists($table, $field)) {
337+
$dbman->add_field($table, $field);
338+
}
339+
340+
// Define field scale to be added to mootyper.
341+
$table = new xmldb_table('mootyper');
342+
$field = new xmldb_field('scale', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'assesstimefinish');
343+
344+
// Conditionally launch add field scale.
345+
if (!$dbman->field_exists($table, $field)) {
346+
$dbman->add_field($table, $field);
347+
}
348+
349+
// Define field grade_mootyper to be added to mootyper.
350+
$table = new xmldb_table('mootyper');
351+
$field = new xmldb_field('grade_mootyper', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'scale');
352+
353+
// Conditionally launch add field grade_mootyper.
354+
if (!$dbman->field_exists($table, $field)) {
355+
$dbman->add_field($table, $field);
356+
}
357+
358+
// Mootyper savepoint reached.
359+
upgrade_mod_savepoint(true, 2020073100, 'mootyper');
307360
}
308361
return true;
309362
}

eedit.php

+51-15
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
*/
2525

2626
use \mod_mootyper\event\exercise_edited;
27+
use \mod_mootyper\event\invalid_access_attempt;
2728

2829
// Changed to this newer format 20190301.
2930
require(__DIR__ . '/../../config.php');
@@ -54,10 +55,25 @@
5455

5556
// This context->id will be used for the path to file storage.
5657
$context = context_module::instance($cm->id);
57-
//$context = context_course::instance($id);
58+
$mootyper = $DB->get_record('mootyper', array('id' => $cm->instance) , '*', MUST_EXIST);
5859

5960
require_login($course, true, $cm);
6061

62+
// 20200706 Added to prevent student direct URL access attempts.
63+
if (!(has_capability('mod/mootyper:aftersetup', $context))) {
64+
// Trigger invalid_access_attempt with redirect to course page.
65+
$params = array(
66+
'objectid' => $id,
67+
'context' => $context,
68+
'other' => array(
69+
'file' => 'eedit.php'
70+
)
71+
);
72+
$event = invalid_access_attempt::create($params);
73+
$event->trigger();
74+
redirect('../../course/view.php?id='.$course->id, get_string('invalidaccessexp', 'mootyper'));
75+
}
76+
6177
// Check to see if Confirm button is clicked and returning 'Confirm' to trigger update record.
6278
$param1 = optional_param('button', '', PARAM_TEXT);
6379

@@ -106,15 +122,15 @@
106122
$align = $editalign;
107123
}
108124

109-
//$PAGE->set_url('/mod/mootyper/eedit.php', array('id' => $course->id, 'ex' => $exerciseid));
110125
$PAGE->set_url('/mod/mootyper/eedit.php', array('id' => $course->id, 'ex' => $ex));
111126
$PAGE->set_title(get_string('etitle', 'mootyper'));
112127
$PAGE->set_heading(get_string('eheading', 'mootyper'));
113128
$PAGE->set_cacheable(false);
114129
echo $OUTPUT->header();
115-
$exercisetoedit = $DB->get_record('mootyper_exercises', array('id' => $ex), 'id, texttotype, exercisename, lesson, snumber', MUST_EXIST);
130+
$exercisetoedit = $DB->get_record('mootyper_exercises',
131+
array('id' => $ex), 'id, texttotype, exercisename, lesson, snumber', MUST_EXIST);
116132

117-
?>
133+
?>
118134

119135
<script type="text/javascript">
120136
function isLetter(str) {
@@ -169,7 +185,8 @@ function clClick() {
169185

170186
</script>
171187
<?php
172-
$color3 = $moocfg->keyboardbgc;
188+
// 20200625 Get the current MooTyper keyboard background default color for our page background here.
189+
$color3 = $mootyper->keybdbgc;
173190
echo '<div align="center" style="font-size:1em;
174191
font-weight:bold;background: '.$color3.';
175192
border:2px solid black;
@@ -204,18 +221,37 @@ function clClick() {
204221
$url = $CFG->wwwroot . '/mod/mootyper/exercises.php?id='.$id.'&lesson='.$rcrd->lesson;
205222

206223
// Add a text area for editing the text of the exercise.
207-
echo '<span id="text_holder_span" class=""></span><br>'.get_string('fexercise', 'mootyper').':<br>'.
208-
'<textarea name="texttotype" id="texttotype" rows="3" cols="60" style="text-align:'.$align.'">'.
209-
str_replace('\n', "&#10;", $exercisetoedit->texttotype).
210-
'</textarea>';
211-
212-
$editor = editors_get_preferred_editor(FORMAT_HTML);
213-
$attobuttons = 'files = recordrtc'. PHP_EOL .'list = unorderedlist, orderedlist'. PHP_EOL .'other = html, htmlplus';
214-
215-
$editor->use_editor('exercisetoedit', ['context' => $context, 'enable_filemanagement' => true, 'autosave' => true, 'atto:toolbar' => $attobuttons], ['return_types' => FILE_EXTERNAL]);
224+
echo '<span id="text_holder_span" class=""></span><br>'
225+
.get_string('fexercise', 'mootyper')
226+
.':<br>'
227+
.'<textarea name="texttotype" id="texttotype" rows="3" cols="60" style="text-align:'
228+
.$align.'">'
229+
.str_replace('\n', "&#10;", $exercisetoedit->texttotype)
230+
.'</textarea>';
231+
232+
$editor = editors_get_preferred_editor(FORMAT_HTML);
233+
$attobuttons = 'files = recordrtc'. PHP_EOL .'list = unorderedlist, orderedlist'. PHP_EOL .'other = html, htmlplus';
234+
235+
$editor->use_editor('exercisetoedit',
236+
['context' => $context,
237+
'enable_filemanagement' => true,
238+
'autosave' => true,
239+
'atto:toolbar' => $attobuttons],
240+
['return_types' => "FILE_EXTERNAL"]
241+
);
216242

217243
// Add a confirm and cancel button.
218-
echo '<br><br><input class="btn btn-primary" style="border-radius: 8px" name="button" onClick="return clClick()" type="submit" value="'.get_string('fconfirm', 'mootyper').'"> <a href="'.$url.'" class="btn btn-secondary" style="border-radius: 8px">'.get_string('cancel', 'mootyper').'</a>'.'</form>';
244+
echo '<br><br><input class="btn btn-primary"
245+
style="border-radius: 8px"
246+
name="button"
247+
onClick="return clClick()"
248+
type="submit" value="'
249+
.get_string('fconfirm', 'mootyper')
250+
.'"> <a href="'
251+
.$url
252+
.'" class="btn btn-secondary" style="border-radius: 8px">'
253+
.get_string('cancel', 'mootyper')
254+
.'</a>'.'</form>';
219255

220256
echo '</div>';
221257

eins.php

+26-7
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
**/
2727

2828
use \mod_mootyper\event\exercise_added;
29+
use \mod_mootyper\event\invalid_access_attempt;
2930
use \mod_mootyper\local\lessons;
3031

3132
// Changed to this newer format 03/01/2019.
@@ -55,6 +56,23 @@
5556

5657
$context = context_module::instance($cm->id);
5758

59+
$mootyper = $DB->get_record('mootyper', array('id' => $cm->instance) , '*', MUST_EXIST);
60+
61+
// 20200706 Added to prevent student direct URL access attempts.
62+
if (!(has_capability('mod/mootyper:aftersetup', $context))) {
63+
// Trigger invalid_access_attempt with redirect to course page.
64+
$params = array(
65+
'objectid' => $id,
66+
'context' => $context,
67+
'other' => array(
68+
'file' => 'eins.php'
69+
)
70+
);
71+
$event = invalid_access_attempt::create($params);
72+
$event->trigger();
73+
redirect('../../course/view.php?id='.$course->id, get_string('invalidaccessexp', 'mootyper'));
74+
}
75+
5876
// Check to see if Confirm button is clicked and returning 'Confirm' to trigger insert record.
5977
$param1 = optional_param('button', '', PARAM_TEXT);
6078

@@ -150,8 +168,8 @@
150168
}
151169
}
152170

153-
// Get the site keyboard background default color for our page background here.
154-
$color3 = $moocfg->keyboardbgc;
171+
// 20200625 Get the current MooTyper keyboard background default color for our page background here.
172+
$color3 = $mootyper->keybdbgc;
155173
// Add colored background with border.
156174
echo '<div align="center" style="font-size:1em;
157175
font-weight:bold;background: '.$color3.';
@@ -182,7 +200,7 @@
182200
if ($lessonpo == -1) {
183201

184202
// Set up place to enter new lesson name.
185-
echo '<br><br>...'.get_string('lsnname', 'mootyper').': <input type="text" name="lessonname" id="lessonname">
203+
echo '<br><br>'.get_string('lsnname', 'mootyper').': <input type="text" name="lessonname" id="lessonname">
186204
<span style="color:red;" id="namemsg"></span>';
187205

188206
// Set up visibility selector options for this new lesson.
@@ -274,7 +292,6 @@ function clClick() {
274292
</script>
275293

276294
<?php
277-
278295
// Create a link back to where we came from in case we want to cancel.
279296
if ($lessonpo == -1) {
280297
// 20200414 On cancel, go back to the MT activity if invoked from there.
@@ -289,10 +306,12 @@ function clClick() {
289306
.'<textarea rows="4" cols="60" name="texttotype" id="texttotype" style="text-align:'.$align.'"></textarea>';
290307

291308
// Add a confirm and cancel button.
292-
echo '<br><br><input class="btn btn-primary" style="border-radius: 8px" name="button" onClick="return clClick()" type="submit" value="'
293-
.get_string('fconfirm', 'mootyper').'"> <a href="'.$url.'" class="btn btn-secondary" style="border-radius: 8px">'
309+
echo '<br><br><input class="btn btn-primary" style="border-radius: 8px"
310+
name="button" onClick="return clClick()" type="submit" value="'
311+
.get_string('fconfirm', 'mootyper').'"> <a href="'
312+
.$url.'" class="btn btn-secondary" style="border-radius: 8px">'
294313
.get_string('cancel', 'mootyper').'</a>'.'</form>';
295314

296-
echo '<br></div>';
315+
echo '</div>';
297316

298317
echo $OUTPUT->footer();

erem.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
// if l is set we remove a lesson and all its exercises.
5353
$exerciseid = optional_param('r', '', PARAM_TEXT);
5454
$lessonid = optional_param('l', '', PARAM_TEXT);
55-
//Added cmid so can exit back to MooTyper activity we came from.
55+
// Added cmid so can exit back to MooTyper activity we came from.
5656
$cmid = optional_param('cmid', '0', PARAM_INT); // Course Module ID.
5757

5858
if ($exerciseid) {

0 commit comments

Comments
 (0)