[Removed] the Delete user attempts option in the Lesson settings (changes to mod and lib)

[Added] new functionality to report.php to delete individual student attempts
[Fixed] High scores text in view.php when no high scores were recorded needed to be centered
This commit is contained in:
mark-nielsen
2006-04-29 01:37:50 +00:00
parent 062a84a62a
commit 31eb5b5335
4 changed files with 67 additions and 64 deletions
-43
View File
@@ -207,49 +207,6 @@ function lesson_update_instance($lesson) {
}
add_event($event);
if (!empty($lesson->deleteattempts)) {
$subject = "Delete User Attempts";
$message = "";
if ($userid = get_field("user", "id", "username", $lesson->deleteattempts)) {
if (delete_records("lesson_attempts", "lessonid", $lesson->id, "userid", $userid)) {
// email good
$message .= "Successfully deleted attempts from \"".format_string($lesson->name)."\" lesson!<br />";
} else {
// email couldnt delete
$message .= "Failed to delete attempts from \"".format_string($lesson->name)."\" lesson!<br />";
}
if (delete_records("lesson_grades", "lessonid", $lesson->id, "userid", $userid)) {
// email good
$message .= "Successfully deleted grades from \"".format_string($lesson->name)."\" lesson!<br />";
} else {
// email couldnt delete
$message .= "Failed to delete grades from \"".format_string($lesson->name)."\" lesson!<br />";
}
if (delete_records("lesson_timer", "lessonid", $lesson->id, "userid", $userid)) {
// email good
$message .= "Successfully deleted time records from \"".format_string($lesson->name)."\" lesson!<br />";
} else {
// email couldnt delete
$message .= "Failed to delete time records from \"".format_string($lesson->name)."\" lesson!<br />";
}
} else {
// email couldnt find user
$message .= "Could not find user in database.<br />";
}
$message .= "<br /> User ID used: $lesson->deleteattempts <br />";
$txt = format_text_email($message, FORMAT_HTML);
if ($currentuser = get_record("user", "id", $lesson->deleteattemptsid)) {
email_to_user($currentuser, $currentuser, $subject, $txt, $message);
}
// unset lessondefault
}
unset($lesson->deleteattempts);
unset($lesson->deleteattemptsid);
return update_record("lesson", $lesson);
}
-14
View File
@@ -626,20 +626,6 @@ if ($form->mode == "add") {
?>
</td>
</tr>
<?php
if ($form->mode != "add") {
?>
<tr>
<td align="right"><b><?php print_string("deleteattempts", "lesson"); ?>:</b></td>
<td>
<input type="text" name="deleteattempts" size="7" value="" />
<?php helpbutton("deleteattempts", get_string("deleteattempts", "lesson"), "lesson"); ?>
<input type="hidden" name="deleteattemptsid" value="<?php echo $USER->id; ?>" />
</td>
</tr>
<?php
} // end if statement if ($form->mode != "add") {
?>
<?php print_visible_setting($form); ?>
</table>
<!-- These hidden variables are always the same -->
+66 -6
View File
@@ -24,10 +24,6 @@
error('Course module is incorrect');
}
if (! $attempts = get_records('lesson_attempts', 'lessonid', $lesson->id, 'timeseen')) {
$nothingtodisplay = true;
}
if (! $students = get_records_sql("SELECT DISTINCT u.*
FROM {$CFG->prefix}user u,
{$CFG->prefix}lesson_attempts a
@@ -37,6 +33,54 @@
$nothingtodisplay = true;
}
/// Process any form data before fetching attempts, grades and times
if ($form = data_submitted()) {
confirm_sesskey();
/// Cycle through array of userids with nested arrays of tries
foreach ($form->attempts as $userid => $tries) {
// Modifier IS VERY IMPORTANT! What does it do?
// Well, it is for when you delete multiple attempts for the same user.
// If you delete try 1 and 3 for a user, then after deleting try 1, try 3 then
// becomes try 2 (because try 1 is gone and all tries after try 1 get decremented).
// So, the modifier makes sure that the submitted try refers to the current try in the
// database - hope this all makes sense :)
$modifier = 0;
foreach ($tries as $try => $junk) {
$try -= $modifier;
/// Clean up the timer table
$timeid = get_field_sql("SELECT id FROM {$CFG->prefix}lesson_timer
WHERE userid = $userid AND lessonid = $lesson->id
ORDER BY starttime ".sql_paging_limit($try, 1));
delete_records('lesson_timer', 'id', $timeid);
/// Remove the grade from the grades and high_scores tables
$gradeid = get_field_sql("SELECT id FROM {$CFG->prefix}lesson_grades
WHERE userid = $userid AND lessonid = $lesson->id
ORDER BY completed ".sql_paging_limit($try, 1));
delete_records('lesson_grades', 'id', $gradeid);
delete_records('lesson_high_scores', 'gradeid', $gradeid, 'lessonid', $lesson->id, 'userid', $userid);
/// Remove attempts and update the retry number
delete_records('lesson_attempts', 'userid', $userid, 'lessonid', $lesson->id, 'retry', $try);
execute_sql("UPDATE {$CFG->prefix}lesson_attempts SET retry = retry - 1 WHERE userid = $userid AND lessonid = $lesson->id AND retry > $try", false);
/// Remove seen branches and update the retry number
delete_records('lesson_branch', 'userid', $userid, 'lessonid', $lesson->id, 'retry', $try);
execute_sql("UPDATE {$CFG->prefix}lesson_branch SET retry = retry - 1 WHERE userid = $userid AND lessonid = $lesson->id AND retry > $try", false);
$modifier++;
}
}
}
if (! $attempts = get_records('lesson_attempts', 'lessonid', $lesson->id, 'timeseen')) {
$nothingtodisplay = true;
}
if (! $grades = get_records('lesson_grades', 'lessonid', $lesson->id, 'completed')) {
$grades = array();
@@ -177,8 +221,9 @@
$tries = $studentdata[$student->id];
$studentname = "{$student->lastname},&nbsp;$student->firstname";
foreach ($tries as $try) {
// start to build up the link
$temp = "<a href=\"report.php?id=$cm->id&amp;action=detail&amp;userid=".$try["userid"]."&amp;try=".$try["try"]."\">";
// start to build up the checkbox and link
$temp = '<input type="checkbox" id="attempts" name="attempts['.$try['userid'].']['.$try['try'].']" /> '.
"<a href=\"report.php?id=$cm->id&amp;action=detail&amp;userid=".$try['userid'].'&amp;try='.$try['try'].'">';
if ($try["grade"] !== NULL) { // if NULL then not done yet
// this is what the link does when the user has completed the try
$timetotake = $try["timeend"] - $try["timestart"];
@@ -225,7 +270,22 @@
}
}
// print it all out !
echo "<form id=\"theform\" name=\"theform\" method=\"post\" action=\"report.php\">\n
<input type=\"hidden\" name=\"sesskey\" value=\"".sesskey()."\" />\n
<input type=\"hidden\" name=\"id\" value=\"$cm->id\" />\n
<input type=\"hidden\" name=\"id\" value=\"$cm->id\" />\n";
print_table($table);
echo '<br /><table width="90%" align="center"><tr><td>'.
'<a href="javascript: checkall();">'.get_string('selectall').'</a> / '.
'<a href="javascript: checknone();">'.get_string('deselectall').'</a> ';
$options = array();
$options['delete'] = get_string('deleteselected');
choose_from_menu($options, 'attemptaction', 0, 'choose', 'submitFormById(\'theform\')');
echo '</td></tr></table></form>';
// some stat calculations
if ($numofattempts == 0) {
+1 -1
View File
@@ -1927,7 +1927,7 @@
print_heading(get_string("topscorestitle", "lesson", $lesson->maxhighscores), 'center', 4);
if (!$highscores = get_records_select("lesson_high_scores", "lessonid = $lesson->id")) {
echo get_string("nohighscores", "lesson")."<br>";
print_heading(get_string("nohighscores", "lesson"), 'center', 3);
} else {
foreach ($highscores as $highscore) {
$grade = $grades[$highscore->gradeid]->grade;