Exemplo n.º 1
0
 /**
  * @param $testObjects Test[]
  * @return array
  */
 function testRecords($testObjects)
 {
     $return = array();
     if (is_array($testObjects)) {
         $return['total'] = 0;
         $return['obtained'] = 0;
         $return['percentage'] = "0";
         foreach ($testObjects as $key => $test) {
             $test_ids[] = $test->id->val;
             if ($this->hasToTakeTest($test)) {
                 //pEcho("Student ".$this->title()." has to take test: ".$test->title());
                 $return['total'] += $test->max_marks->val;
             }
             //else{ pEcho("Student ".$this->title()." does NOT have to take test: ".$test->title()); }
             // $this->pr('student'); $test->pr('test');
         }
         $cond = "student_id =" . $this->id->val . " AND test_id in (" . join(",", $test_ids) . ")";
         $records = Test_record::findByCondition($cond);
         $return['tests'] = array_flip($test_ids);
         if ($records) {
             foreach ($records as $key => $testRec) {
                 $return['tests'][$testRec->test_id->val] = $testRec;
                 $return['obtained'] += $testRec->obtained_marks->val;
             }
         }
         if ($return['total'] > 0) {
             $return['percentage'] = round($return['obtained'] / $return['total'] * 100, 2);
         }
     }
     return $return;
 }
Exemplo n.º 2
0
Arquivo: Test.php Projeto: nveeed/ems
 public function autoInsertTest_record()
 {
     $students = $this->relStudents();
     foreach ($students as $stdnt) {
         // dont insert a test rec if it already exists:
         $condition = "test_id='" . $this->id->val . "' AND student_id='{$stdnt->id}->val'";
         if (!Test_record::findByCondition($condition)) {
             // pr("Entering a new rec");
             // insert a new test rec
             $testRec = new Test_record();
             $testRec->test_id->val = $this->id->val;
             $testRec->student_id->val = $stdnt->id->val;
             if (!$testRec->dbSave()) {
                 return false;
             }
         }
         // pr("Outside the if");
     }
     return true;
 }