コード例 #1
0
 public static function updateGpa($semester_id)
 {
     $con = Connection::getConnectionObject()->getConnection();
     // Check connection
     if (mysqli_connect_errno()) {
         echo "Failed to connect to MySQL: " . mysqli_connect_error();
     }
     $students = Student::getAll();
     $results = Semester_results::getAllSemester($semester_id);
     //check student in semester_resultsr
     foreach ($students as $student) {
         $inResults = false;
         foreach ($results as $result) {
             if ($student->getId() == $result->stuId) {
                 $inResults = true;
                 break;
             }
         }
         if ($inResults == false) {
             $result = new Semester_results();
             $result->setStuId($student->getId());
             $result->setSemId($semester_id);
             array_push($results, $result);
         }
     }
     foreach ($results as $result) {
         //vars for calculate gpa
         $totalMark = 0.0;
         $totalCredits = 0.0;
         //die($result->stuId);
         //query to get the marks and credits
         $stmt = $con->prepare('SELECT module.credits,grade.mark FROM module,student_module_grade,grade,student WHERE module.code = student_module_grade.m_code AND student_module_grade.grade = grade.grade AND student_module_grade.s_id = student.index_no AND module.gpa = true AND student.id = ?');
         $stmt->bind_param("s", $result->stuId);
         $stmt->execute();
         $stmt->bind_result($credits, $mark);
         while ($stmt->fetch()) {
             $totalMark += $mark * $credits;
             $totalCredits += $credits;
         }
         //adding the gpa to the result object
         if ($totalCredits > 0) {
             $result->gPA = $totalMark / $totalCredits;
         }
     }
     return $results;
 }
コード例 #2
0
 /**
  * @Route("/semester/view/{id}", name="semester_view")
  */
 public function viewAction($id, Request $request)
 {
     $semester = Semester::getOne($id);
     $semResults = Semester_results::getAllSemester($id);
     return $this->render('semester/view.html.twig', array('semester' => $semester, 'results' => $semResults));
 }