New Feature: Lesson Dependency

In a lesson's settings one can now set the current lesson to be dependent on another lesson in the same course.  Then, the user can set the conditions for the dependency.  Currently the conditions are time spent, grade better than X, and completed (yes/no).
This commit is contained in:
michaelpenne
2005-06-30 21:11:02 +00:00
parent 2ddb242f56
commit ee3f227560
10 changed files with 196 additions and 6 deletions
+2
View File
@@ -55,6 +55,8 @@
fwrite ($bf,full_tag("MODATTEMPTS",4,false,$lesson->modattempts));
fwrite ($bf,full_tag("PASSWORD",4,false,$lesson->password));
fwrite ($bf,full_tag("USEPASSWORD",4,false,$lesson->usepassword));
fwrite ($bf,full_tag("DEPENDENCY",4,false,$lesson->dependency));
fwrite ($bf,full_tag("CONDITIONS",4,false,$lesson->conditions));
fwrite ($bf,full_tag("GRADE",4,false,$lesson->grade));
fwrite ($bf,full_tag("CUSTOM",4,false,$lesson->custom));
fwrite ($bf,full_tag("ONGOING",4,false,$lesson->ongoing));
+5
View File
@@ -171,6 +171,11 @@ function lesson_upgrade($oldversion) {
if ($oldversion < 2005061500) {
table_column('lesson', '', 'mediafile', 'varchar', '255', '', '', 'not null', 'tree');
}
if ($oldversion < 2005063000) {
table_column('lesson', '', 'dependency', 'int', '10', 'unsigned', '0', 'not null', 'usepassword');
table_column('lesson', '', 'conditions', 'text', '', '', '', 'not null', 'dependency');
}
return true;
}
+2
View File
@@ -12,6 +12,8 @@ CREATE TABLE `prefix_lesson` (
`modattempts` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0',
`usepassword` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0',
`password` VARCHAR(32) NOT NULL default '',
`dependency` int(10) unsigned NOT NULL default '0',
`conditions` text NOT NULL default '',
`grade` tinyint(3) NOT NULL default '0',
`custom` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0',
`ongoing` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0',
+5
View File
@@ -219,6 +219,11 @@ function lesson_upgrade($oldversion) {
if ($oldversion < 2005061500) {
table_column('lesson', '', 'mediafile', 'varchar', '255', '', '', 'not null', 'tree');
}
if ($oldversion < 2005063000) {
table_column('lesson', '', 'dependency', 'INT', '8', 'unsigned', '0', 'not null', 'usepassword');
table_column('lesson', '', 'conditions', 'text', '', '', '', 'not null', 'dependency');
}
return true;
}
+2
View File
@@ -6,6 +6,8 @@ CREATE TABLE prefix_lesson (
modattempts INT4 NOT NULL DEFAULT '0',
usepassword INT NOT NULL DEFAULT '0',
password VARCHAR(32) NOT NULL default '',
dependency INT8 NOT NULL DEFAULT '0',
conditions text NOT NULL DEFAULT '',
grade INT NOT NULL default '0',
custom INT NOT NULL DEFAULT '0',
ongoing INT NOT NULL DEFAULT '0',
+43 -4
View File
@@ -28,13 +28,33 @@ function lesson_add_instance($lesson) {
$lesson->deadlinemonth, $lesson->deadlineday, $lesson->deadlinehour,
$lesson->deadlineminute);
/// CDC-FLAG ///
if(empty($lesson->timespent) or !is_numeric($lesson->timespent) or $lesson->timespent < 0) {
$lesson->timespent = 0;
}
if(!isset($lesson->completed)) {
$lesson->completed = 0;
}
if(empty($lesson->gradebetterthan) or !is_numeric($lesson->timespent) or $lesson->gradebetterthan < 0) {
$lesson->gradebetterthan = 0;
} else if ($lesson->gradebetterthan > 100) {
$lesson->gradebetterthan = 100;
}
// conditions for dependency
$conditions = new stdClass;
$conditions->timespent = $lesson->timespent;
$conditions->completed = $lesson->completed;
$conditions->gradebetterthan = $lesson->gradebetterthan;
$lesson->conditions = addslashes(serialize($conditions));
unset($lesson->timespent);
unset($lesson->completed);
unset($lesson->gradebetterthan);
if (!empty($lesson->password)) {
$lesson->password = md5($lesson->password);
} else {
unset($lesson->password);
}
/// CDC-FLAG ///
if (!$lesson->id = insert_record("lesson", $lesson)) {
return false; // bad
}
@@ -106,13 +126,32 @@ function lesson_update_instance($lesson) {
$lesson->deadlineminute);
$lesson->id = $lesson->instance;
/// CDC-FLAG ///
if(empty($lesson->timespent) or !is_numeric($lesson->timespent) or $lesson->timespent < 0) {
$lesson->timespent = 0;
}
if(!isset($lesson->completed)) {
$lesson->completed = 0;
}
if(empty($lesson->gradebetterthan) or !is_numeric($lesson->timespent) or $lesson->gradebetterthan < 0) {
$lesson->gradebetterthan = 0;
} else if ($lesson->gradebetterthan > 100) {
$lesson->gradebetterthan = 100;
}
// conditions for dependency
$conditions = new stdClass;
$conditions->timespent = $lesson->timespent;
$conditions->completed = $lesson->completed;
$conditions->gradebetterthan = $lesson->gradebetterthan;
$lesson->conditions = addslashes(serialize($conditions));
unset($lesson->timespent);
unset($lesson->completed);
unset($lesson->gradebetterthan);
if (!empty($lesson->password)) {
$lesson->password = md5($lesson->password);
} else {
unset($lesson->password);
}
/// CDC-FLAG ///
if ($lesson->lessondefault) {
$lessondefault = $lesson;
+64 -1
View File
@@ -99,10 +99,22 @@ if ($form->mode == "add") {
if (!isset($form->modattempts)) {
$form->modattempts = 0;
}
if (!isset($form->mediafile)) {
$form->mediafile = '';
}
if (!isset($form->dependency)) {
$form->dependency = 0;
}
if (!isset($form->conditions)) {
$form->timespent = 0;
$form->completed = 0;
$form->gradebetterthan = 0;
} else {
$conditions = unserialize($form->conditions);
$form->timespent = $conditions->timespent;
$form->completed = $conditions->completed;
$form->gradebetterthan = $conditions->gradebetterthan;
}
$form->deleteattempts = "";
@@ -404,6 +416,57 @@ if ($form->mode == "add") {
</td>
</tr>
<tr>
<td align="right"><b><?php print_string("dependencyon", "lesson"); ?>:</b></td>
<td>
<?php
$options = array();
$options[0] = get_string("none");
if (empty($form->instance)) {
$select = "course = $course->id";
} else {
$select = "course = $course->id AND id != $form->instance";
}
if ($lessons = get_records_select('lesson', $select, 'name ASC')) {
foreach($lessons as $lesson) {
$options[$lesson->id] = $lesson->name;
}
}
choose_from_menu($options, "dependency", $form->dependency, "");
?>
<?php helpbutton("password", get_string("dependency", "lesson"), "lesson"); ?>
</td>
</tr>
<tr>
<td align="right"><b><?php print_string("conditionsfordependency", "lesson"); ?>:</b></td>
<td>
<table cellpadding="5px">
<tr align="center">
<td><?php print_string("timespentminutes", "lesson"); ?></td>
<td><?php print_string("completed", "lesson"); ?></td>
<td><?php print_string("gradebetterthan", "lesson"); ?></td>
</tr>
<tr align="center">
<td><input type="text" name="timespent" maxlength="7" size="7" value="<?php p($form->timespent) ?>" /></td>
<td>
<?php
if ($form->completed) {
$checked = 'checked="checked"';
} else {
$checked = '';
}
?>
<input type="checkbox" name="completed" value="1" <?php echo $checked; ?> />
</td>
<td><input type="text" name="gradebetterthan" maxlength="7" size="7" value="<?php p($form->gradebetterthan) ?>" /></td>
</tr>
</table>
</td>
</tr>
<tr valign="top">
<td align="right"><b><?php print_string("available", "lesson") ?>:</b></td>
<td><?php
+2
View File
@@ -58,6 +58,8 @@
$lesson->modattempts = backup_todb($info['MOD']['#']['MODATTEMPTS']['0']['#']);
$lesson->password = backup_todb($info['MOD']['#']['PASSWORD']['0']['#']);
$lesson->usepassword = backup_todb($info['MOD']['#']['USEPASSWORD']['0']['#']);
$lesson->dependency = backup_todb($info['MOD']['#']['DEPENDENCY']['0']['#']);
$lesson->conditions = backup_todb($info['MOD']['#']['CONDITIONS']['0']['#']);
$lesson->grade = backup_todb($info['MOD']['#']['GRADE']['0']['#']);
$lesson->custom = backup_todb($info['MOD']['#']['CUSTOM']['0']['#']);
$lesson->ongoing = backup_todb($info['MOD']['#']['ONGOING']['0']['#']);
+1 -1
View File
@@ -5,7 +5,7 @@
/// This fragment is called by moodle_needs_upgrading() and /admin/index.php
/////////////////////////////////////////////////////////////////////////////////
$module->version = 2005061500; // The current module version (Date: YYYYMMDDXX)
$module->version = 2005063000; // The current module version (Date: YYYYMMDDXX)
$module->requires = 2005021600; // Requires this Moodle version
$module->cron = 0; // Period for cron to check this module (secs)
+70
View File
@@ -145,6 +145,76 @@
$timedflag = false;
$attemptflag = false;
if (empty($pageid)) {
// check for dependencies first
if ($lesson->dependency and !isteacher($course->id)) {
if ($dependentlesson = get_record('lesson', 'id', $lesson->dependency)) {
// lesson exists, so we can proceed
$conditions = unserialize($lesson->conditions);
// assume false for all
$timespent = false;
$completed = false;
$gradebetterthan = false;
// check for the timespent condition
if ($conditions->timespent) {
if ($attempttimes = get_records_select('lesson_timer', "userid = $USER->id AND lessonid = $dependentlesson->id")) {
// go through all the times and test to see if any of them satisfy the condition
foreach($attempttimes as $attempttime) {
$duration = $attempttime->lessontime - $attempttime->starttime;
if ($conditions->timespent < $duration/60) {
$timespent = true;
}
}
}
} else {
$timespent = true; // there isn't one set
}
// check for the gradebetterthan condition
if($conditions->gradebetterthan) {
if ($studentgrades = get_records_select('lesson_grades', "userid = $USER->id AND lessonid = $dependentlesson->id")) {
// go through all the grades and test to see if any of them satisfy the condition
foreach($studentgrades as $studentgrade) {
if ($studentgrade->grade >= $conditions->gradebetterthan) {
$gradebetterthan = true;
}
}
}
} else {
$gradebetterthan = true; // there isn't one set
}
// check for the completed condition
if ($conditions->completed) {
if (count_records('lesson_grades', 'userid', $USER->id, 'lessonid', $dependentlesson->id)) {
$completed = true;
}
} else {
$completed = true; // not set
}
$errors = array();
// collect all of our error statements
if (!$timespent) {
$errors[] = get_string('timespenterror', 'lesson', $conditions->timespent);
}
if (!$completed) {
$errors[] = get_string('completederror', 'lesson');
}
if (!$gradebetterthan) {
$errors[] = get_string('gradebetterthanerror', 'lesson', $conditions->gradebetterthan);
}
if (!empty($errors)) { // print out the errors if any
echo '<p>';
print_simple_box_start('center');
print_string('completethefollowingconditions', 'lesson', $dependentlesson->name);
echo '<p align="center">'.implode('<br />'.get_string('and', 'lesson').'<br />', $errors).'</p>';
print_simple_box_end();
echo '</p>';
print_footer($course);
exit();
}
}
}
add_to_log($course->id, 'lesson', 'start', 'view.php?id='. $cm->id, $lesson->id, $cm->id);
// if no pageid given see if the lesson has been started
if ($grades = get_records_select('lesson_grades', 'lessonid = '. $lesson->id .' AND userid = '. $USER->id,