Permalink
Browse files

Added grading support for attendance - including settings and database

fields.

Cleaned up some function names in lib to proper naming conventions.
  • Loading branch information...
jungwirr
jungwirr committed Sep 25, 2003
1 parent 7b6d108 commit 29bd1e46c511cec3229c27228e1364256ce3c3cb
View
@@ -57,8 +57,14 @@
$string['downloadtextfull'] = "Download Full Text Report";
$string['downloadtexttotals'] = "Download Summary Text Report";
$string['autoattend'] = "Automatically take attendance based on user activity logs";
$string['defaultautoattend'] = "Whether to take attendance based on user activity logs by default";
$string['autoattendmulti'] = "Automatically take attendance for all rolls based on user activity logs";
$string['auto'] = "auto";
$string['gradevalue'] = "Make this roll gradeable";
$string['defaultgrade'] = " Whether to make attendance rolls gradeable by default";
$string['gradevaluemulti'] = "Make these rolls gradeable";
$string['maxgradevalue'] = "Maximum grade value for full attendance";
$string['defaultmaxgrade'] = "What the default maximum grade value for full attendance should be";
?>
View
@@ -142,60 +142,6 @@
unset($SESSION->modform); // Clear any old ones that may be hanging around.
/* optional_variable($id); // Course Module ID, or
optional_variable($a); // attendance ID
/// populate the appropriate objects
if ($id) {
if (! $course = get_record("course", "id", $id)) {
error("Course is misconfigured");
}
if (! $attendance = get_record("attendance", "course", $id)) {
error("Course module is incorrect");
}
if (! $cm = get_coursemodule_from_instance("attendance", $attendance->id, $id)) {
error("Course Module ID was incorrect");
}
if (! $attendances = get_records("attendance", "course", $cm->course)) {
error("Course module is incorrect");
}
} else {
if (! $attendance = get_record("attendance", "id", $a)) {
error("Course module is incorrect");
}
if (! $course = get_record("course", "id", $attendance->course)) {
error("Course is misconfigured");
}
if (! $cm = get_coursemodule_from_instance("attendance", $attendance->id, $course->id)) {
error("Course Module ID was incorrect");
}
if (! $attendances = get_records("attendance", "course", $cm->course)) {
error("Course module is incorrect");
}
}
require_login($course->id);
add_to_log($course->id, "attendance", "add", "add.php?id=$course->id");
/// Print the page header
if ($course->category) {
$navigation = "<A HREF=\"../../course/view.php?id=$course->id\">$course->shortname</A> ->";
}
$strattendances = get_string("modulenameplural", "attendance");
$strattendance = get_string("modulename", "attendance");
$straddmultiple = get_string("addmultiple", "attendance");
print_header("$course->shortname: $straddmultiple", "$course->fullname",
"$navigation <A HREF=index.php?id=$course->id>$strattendances</A> -> $straddmultiple",
"", "", true, "&nbsp;",
navmenu($course));
*/
/// Print the main part of the page
@@ -204,6 +150,13 @@
//require_once("lib.php")
// determine the end date for the course based on the number of sections and the start date
$course->enddate = $course->startdate + $course->numsections * 604800;
if (isset($CFG->attendance_dynsection) && ($CFG->attendance_dynsection == "1")) { $form->dynsection = 1; }
if (isset($CFG->attendance_autoattend) && ($CFG->attendance_autoattend == "1")) { $form->autoattend = 1; }
if (isset($CFG->attendance_grade) && ($CFG->attendance_grade == "1")) { $form->grade = 1; }
$form->maxgrade = isset($CFG->attendance_maxgrade)?$CFG->attendance_maxgrade:0;
$form->hours = isset($CFG->attendance_default_hours)?$CFG->attendance_default_hours:1;
?>
<FORM name="form" method="post" action="<?=$ME ?>">
<CENTER>
@@ -246,12 +199,33 @@
<input type="checkbox" name="dynsection" <?php echo !empty($form->dynsection) ? 'checked' : '' ?> >
</TD>
</tr>
<tr valign=top>
<TD align="right"><P><B><?php print_string("autoattendmulti", "attendance") ?>:</B></P></TD>
<TD align="left">
<input type="checkbox" name="autoattend" <?php echo !empty($form->autoattend) ? 'checked' : '' ?> >
</TD>
</tr>
<?php // starting with 2 to allow for the nothing value in choose_from_menu to be the default of 1
for ($i=2;$i<=24;$i++){ $opt[$i] = $i; } ?>
<TR valign=top>
<TD align=right><P><B><?php print_string("hoursineachclass", "attendance") ?>:</B></P></TD>
<TD colspan="3" align="left"><?php choose_from_menu($opt, "hours", $CFG->attendance_default_hours, "1","","1") ?></td>
<TD colspan="3" align="left"><?php choose_from_menu($opt, "hours", $form->hours, "1","","1") ?></td>
</tr>
<tr valign=top>
<TD align="right"><P><B><?php print_string("gradevaluemulti", "attendance") ?>:</B></P></TD>
<TD align="left">
<input type="checkbox" name="grade" <?php echo !empty($form->grade) ? 'checked' : '' ?> >
</TD>
</tr>
<?php // starting with 2 to allow for the nothing value in choose_from_menu to be the default of 1
for ($i=0;$i<=100;$i++){ $opt2[$i] = $i; } ?>
<TR valign=top>
<TD align=right><P><B><?php print_string("maxgradevalue", "attendance") ?>:</B></P></TD>
<TD colspan="3" align="left"><?php choose_from_menu($opt2, "maxgrade", $form->maxgrade, "0","","0") ?></td>
</tr>
</TABLE>
<!-- These hidden variables are always the same -->
<INPUT type="hidden" name=course value="<?php p($form->course) ?>">
View
@@ -4,8 +4,9 @@
<tr valign=top>
<td align=right><p>attendance_dynsection:</td>
<td>
<input type="checkbox" name="attendance_dynsection" value="1" <? echo !empty($CFG->attendance_dynsection) ? 'checked' : '' ?> >
</td>
<? $optds[0] = "No";$optds[1] = "Yes";
choose_from_menu($optds, "attendance_dynsection", $CFG->attendance_dynsection, ""); ?>
</td>
<td>
<? p(get_string("defaultdynamicsection","attendance")) ?>
</td>
@@ -72,6 +73,40 @@
</td>
</tr>
<tr valign=top>
<td align=right><p>attendance_autoattend:</td>
<td>
<? $optaa[0] = "No";$optaa[1] = "Yes";
choose_from_menu($optaa, "attendance_autoattend", $CFG->attendance_autoattend, ""); ?>
</td>
<td>
<? p(get_string("defaultautoattend","attendance")) ?>
</td>
</tr>
<tr valign=top>
<td align=right><p>attendance_grade:</td>
<td>
<? $optgr[0] = "No";$optgr[1] = "Yes";
choose_from_menu($optgr, "attendance_grade", $CFG->attendance_grade, ""); ?>
</td>
<td>
<? p(get_string("defaultgrade","attendance")) ?>
</td>
</tr>
<tr valign=top>
<td align=right><p>attendance_maxgrade:</td>
<td>
<? for ($i=0;$i<=100;$i++){ $opt4[$i] = $i; }
choose_from_menu($opt4, "attendance_maxgrade", $CFG->attendance_maxgrade, ""); ?>
</td>
<td>
<?php p(get_string("defaultmaxgrade","attendance")) ?>
</td>
</tr>
<tr>
<td colspan=3 align=center>
<input type="submit" value="<?php print_string("savechanges") ?>"></td>
View
@@ -35,6 +35,7 @@ function attendance_add_instance($attendance) {
$attendance->timemodified = time();
$attendance->dynsection = !empty($attendance->dynsection) ? 1 : 0;
$attendance->autoattend = !empty($attendance->autoattend) ? 1 : 0;
$attendance->grade = !empty($attendance->grade) ? 1 : 0;
if (empty($attendance->day)) {
$attendance->day = make_timestamp($attendance->theyear,
$attendance->themonth, $attendance->theday);
@@ -73,6 +74,7 @@ function attendance_update_instance($attendance) {
$attendance->id = $attendance->instance;
$attendance->dynsection = !empty($attendance->dynsection) ? 1 : 0;
$attendance->autoattend = !empty($attendance->autoattend) ? 1 : 0;
$attendance->grade = !empty($attendance->grade) ? 1 : 0;
$attendance->day = make_timestamp($attendance->theyear,
$attendance->themonth, $attendance->theday);
@@ -260,12 +262,15 @@ function attendance_cron () {
/// This function searches for things that need to be done, such
/// as sending out mail, toggling flags etc ...
global $CFG;
echo "Attendance: Performing automatic attendance logging\n";
// look for all attendance instances set to autoattend
$attendances = get_records("attendance", "autoattend", 1, "course ASC");
$td = attendance_find_today(time());
$tm = attendance_find_tomorrow(time());
foreach($attendances as $attendance) {
if (($attendance->day >=$td ) && ($attendance->day < $tm)) {
echo "Attendance: Taking attendance for $attendance->name\n";
if(!isset($courses[$attendance->course]->students)) {
$courses[$attendance->course]->students =
attendance_get_course_students($attendance->course, "u.lastname ASC");
@@ -298,10 +303,29 @@ function attendance_cron () {
function attendance_grades($attendanceid) {
/// Must return an array of grades for a given instance of this module,
/// indexed by user. It also returns a maximum allowed grade.
/// NOT IMPLEMENTED AT THIS TIME - WILL DO GRADING BY ATTENDANCE STUFF IN A LATER VERSION
$return->grades = NULL;
$return->maxgrade = NULL;
$attendance = get_record("attendance", "id", $attendanceid);
if ($attendance->grade == "1") {
$students = get_course_students($attendance->course);
foreach ($students as $student) {
$rolls = attendance_get_records("attendance_roll",
"dayid",$attendance->id,
"userid",$student->id);
$abs=$tar=0;
if ($rolls) {
foreach ($rolls as $roll) {
if ($roll->status == 1) {$tar++;}
elseif ($roll->status == 2) {$abs++;}
}
$total = $attendance->hours - attendance_tally_overall_absences_decimal($abs, $tar);
$percent = ($total != 0)?$total/$attendance->hours:0;
$return->grades[$student->id] = ($percent == 0)?0.0:$attendance->maxgrade * $percent;
} else { $return->grades[$student->id] = $attendance->maxgrade; }
} // foreach student
$return->maxgrade = $attendance->maxgrade;
} else { // if attendance->grade == "1"
$return->grades = NULL;
$return->maxgrade = NULL;
}// else for if attendance->grade == "1"
return $return;
}
@@ -345,7 +369,7 @@ function attendance_get_course_students($courseid, $sort="u.lastaccess DESC") {
* @param int $tardies the total number of tardies for a span of time
* @return float the number of absences it adds up to - may be a decimal!
*/
function tally_overall_absences_decimal($absences, $tardies) {
function attendance_tally_overall_absences_decimal($absences, $tardies) {
global $CFG;
if (isset($CFG->attendance_tardies_per_absence) && ($CFG->attendance_tardies_per_absence>0)) {
return $absences + ($tardies/$CFG->attendance_tardies_per_absence);
@@ -363,7 +387,7 @@ function tally_overall_absences_decimal($absences, $tardies) {
* @param int $tardies the total number of tardies for a span of time
* @return string the number of absences it adds up to - may have a fractional component!
*/
function tally_overall_absences_fraction($absences, $tardies) {
function attendance_tally_overall_absences_fraction($absences, $tardies) {
global $CFG;
if (isset($CFG->attendance_tardies_per_absence) && ($CFG->attendance_tardies_per_absence>0)) {
$whole = floor($tardies/$CFG->attendance_tardies_per_absence);
View
@@ -3,8 +3,20 @@
<!-- RJJ I'm using inline CSS styles for some stuff in this page because I want to centralize -->
<!-- the logic and styles in a single directory -->
<?php @include_once("$CFG->dirroot/mod/attendance/lib.php")
<?php @include_once("$CFG->dirroot/mod/attendance/lib.php");
//require_once("lib.php")
// error_reporting(E_ALL);
// if we're adding a new instance
if (empty($form->id)) {
if (isset($CFG->attendance_dynsection) && ($CFG->attendance_dynsection == "1")) { $form->dynsection = 1; }
if (isset($CFG->attendance_autoattend) && ($CFG->attendance_autoattend == "1")) { $form->autoattend = 1; }
if (isset($CFG->attendance_grade) && ($CFG->attendance_grade == "1")) { $form->grade = 1; }
$form->maxgrade = isset($CFG->attendance_maxgrade)?$CFG->attendance_maxgrade:0;
$form->hours = isset($CFG->attendance_default_hours)?$CFG->attendance_default_hours:1;
$form->day = time();
$form->notes = "";
}
?>
<FORM name="form" method="post" action="<?=$ME ?>">
<CENTER>
@@ -28,24 +40,43 @@
<input type="checkbox" name="dynsection" <?php echo !empty($form->dynsection) ? 'checked' : '' ?> >
</TD>
</tr>
<tr valign=top>
<TD align="right"><P><B><?php print_string("autoattend", "attendance") ?>:</B></P></TD>
<TD align="left">
<input type="checkbox" name="autoattend" <?php echo !empty($form->autoattend) ? 'checked' : '' ?> >
</TD>
</tr>
<?php // starting with 2 to allow for the nothing value in choose_from_menu to be the default of 1
for ($i=2;$i<=24;$i++){ $opt[$i] = $i; } ?>
<TR valign=top>
<TD align=right><P><B><?php print_string("hoursinclass", "attendance") ?>:</B></P></TD>
<TD colspan="3" align="left"><?php choose_from_menu($opt, "hours", $form->hours, "1","","1") ?></td>
</tr>
<tr valign=top>
<TD align="right"><P><B><?php print_string("gradevalue", "attendance") ?>:</B></P></TD>
<TD align="left">
<input type="checkbox" name="grade" <?php echo !empty($form->grade) ? 'checked' : '' ?> >
</TD>
</tr>
<?php // starting with 2 to allow for the nothing value in choose_from_menu to be the default of 1
for ($i=0;$i<=100;$i++){ $opt2[$i] = $i; } ?>
<TR valign=top>
<TD align=right><P><B><?php print_string("maxgradevalue", "attendance") ?>:</B></P></TD>
<TD colspan="3" align="left"><?php choose_from_menu($opt2, "maxgrade", $form->maxgrade, "0","","0") ?></td>
</tr>
<tr valign=top>
<td align=right><p><b><?php print_string("notes", "attendance") ?>:</b></p></td>
<td colspan="3">
<input type="text" name="notes" size=60 value="<?php p($form->notes) ?>">
<input type="text" name="notes" size=60 value="<?php p($form->notes)?>">
</td>
</tr>
</TABLE>
<?php // if we're modifying an existing instance of attendance instead
// of creating a new one
if ($form->id) {
if (isset($form->id)) {
// get the list of attendance records for all hours of the given day and
// put it in the array for use in the attendance table
$rolls = get_records("attendance_roll", "dayid", $form->id);
@@ -106,7 +137,8 @@
for($j=1;$j<=$form->hours;$j++) {
// set the attendance defaults for each student
$r1c=$r2c=$r3c=" ";
$rollstatus = (($form->edited==0)?$CFG->attendance_default_student_status:$sroll[$student->id][$j]->status);
$rollstatus = (($form->edited==0)?$CFG->attendance_default_student_status:
((isset($sroll[$student->id][$j]->status)?$sroll[$student->id][$j]->status:0)));
if ($rollstatus==1) {$r2c="checked";}
elseif ($rollstatus==2) {$r3c="checked";}
else {$r1c="checked";}
View
@@ -136,7 +136,7 @@
echo "<td align=\"left\" nowrap class=\"generaltablecell\" style=\"border-left: 1px dotted; border-top: 1px solid;\">".$status."</td>\n";
} /// for loop
if ($form->hours > 1) {
$tot=tally_overall_absences_fraction($abs,$tar);
$tot=attendance_tally_overall_absences_fraction($abs,$tar);
echo "<td align=\"left\" nowrap class=\"generaltablecell\" style=\"border-left: 1px dotted; border-top: 1px solid;\">".$tot."</td></tr>\n";
}
}
@@ -148,7 +148,7 @@
elseif ($atts[$k]->sroll[$student->id][$j]->status == 2) {;$abs++;}
} /// for loop
} // outer for for each day of attendance
$tot=tally_overall_absences_decimal($abs,$tar);
$tot=attendance_tally_overall_absences_decimal($abs,$tar);
$myxls->write_number($row,$pos,$tot);
$row++;
}
@@ -212,7 +212,7 @@
elseif ($atts[$k]->sroll[$student->id][$j]->status == 2) {;$abs++;}
} /// for loop
} // outer for for each day of attendance
$tot=tally_overall_absences_decimal($abs,$tar);
$tot=attendance_tally_overall_absences_decimal($abs,$tar);
echo "\t".$tot."\n";
$row++;
}
@@ -422,7 +422,7 @@
elseif ($atts[$k]->sroll[$student->id][$j]->status == 2) {;$abs++;}
} /// for loop
} // outer for for each day of attendance
$tot=tally_overall_absences_fraction($abs,$tar);
$tot=attendance_tally_overall_absences_fraction($abs,$tar);
echo "<td align=\"left\" nowrap class=\"generaltablecell\" style=\"border-left: 1px dotted; border-top: 1px solid;\">".$tot."</td></tr>\n";
}
} // foreach
Oops, something went wrong.

0 comments on commit 29bd1e4

Please sign in to comment.