Пример #1
0
 public function autoInsertStudent_attendance_record()
 {
     $class = new Clas($this->class_id);
     $students = $class->students();
     foreach ($students as $stdnt) {
         // dont insert a test rec if it already exists:
         $condition = "class_attendance_record_id='" . $this->id->val . "' AND student_id='{$stdnt->id}->val'";
         if (!Student_attendance_record::findByCondition($condition)) {
             // pr("Entering a new rec");
             // insert a new test rec
             $atRec = new Student_attendance_record();
             $atRec->class_attendance_record_id->val = $this->id->val;
             $atRec->student_id->val = $stdnt->id->val;
             $atRec->lectures_attended->val = $class->total_lectures_per_day->val;
             if (!$atRec->dbSave()) {
                 // $atRec->pr();
                 // pr($atRec->getErrors());
                 return false;
             }
         }
         // pr("Outside the if");
     }
     return true;
 }
Пример #2
0
 function attendanceRecords($classAttendanceRecs)
 {
     $return = array();
     if (is_array($classAttendanceRecs)) {
         $return['total'] = 0;
         $return['attended'] = 0;
         $return['percentage'] = 0;
         foreach ($classAttendanceRecs as $key => $atRec) {
             $atRec_ids[] = $atRec->id->val;
             $return['total'] += $atRec->total_lectures->val;
         }
         $cond = "student_id =" . $this->id->val . " AND class_attendance_record_id in (" . join(",", $atRec_ids) . ")";
         $records = Student_attendance_record::findByCondition($cond);
         $return['atRecs'] = array_flip($atRec_ids);
         if ($records) {
             foreach ($records as $key => $stAtRec) {
                 $return['atRecs'][$stAtRec->class_attendance_record_id->val] = $stAtRec;
                 $return['attended'] += $stAtRec->lectures_attended->val;
             }
         }
         if ($return['total'] > 0) {
             $return['percentage'] = round($return['attended'] / $return['total'] * 100, 2);
         }
     }
     return $return;
 }