Esempio n. 1
0
 public static function getOneAveUnitsDepartment($studentid, $departmentid)
 {
     $programids = Assessment::getDeptPrograms($departmentid);
     $semesters = Assessment::select('total_units', 'aysem')->where('studentid', $studentid)->get();
     $totalUnits = 0;
     $totalSemesters = 0;
     $aysemGet = Studentterm::select('aysem')->where('studentid', $studentid)->whereIn('programid', $programids)->get();
     $aysems = [];
     foreach ($aysemGet as $aysem) {
         array_push($aysems, $aysem->aysem);
     }
     foreach ($semesters as $semester) {
         $semesterAysem = $semester->aysem;
         if (in_array($semesterAysem, $aysems) && (substr($semesterAysem, -1) === '1' || substr($semesterAysem, -1) === '2')) {
             $units = $semester->total_units;
             if ($units > 0 && $units <= 21) {
                 $totalUnits = $totalUnits + $units;
                 $totalSemesters = $totalSemesters + 1;
             }
         }
     }
     if ($totalSemesters > 0) {
         return $totalUnits / $totalSemesters;
     } else {
         return -1;
     }
 }