public function seedStbracket($batches, $allStudents, $departmentid) { foreach ($batches as $batch) { $students = $allStudents[$batch]; $totalPoor = 0; foreach ($students as $student) { $results = Studentterm::getOneStbracketDepartment($student->studentid, $departmentid); $poor = 0; foreach ($results as $result) { if (strpos($result->stfapbracket, 'A') !== false || strpos($result->stfapbracket, 'B') !== false || strpos($result->stfapbracket, '8') !== false || strpos($result->stfapbracket, '9') !== false) { $poor = 1; } } $totalPoor = $totalPoor + $poor; } $newCorrelation = new Correlation(); $newCorrelation->factorid = 3; $newCorrelation->batch = $batch; $countStudents = count($students); if ($countStudents > 0) { $newCorrelation->ratio = $totalPoor / $countStudents; } else { $newCorrelation->ratio = 0; } $newCorrelation->unittype = 'department'; $newCorrelation->departmentid = $departmentid; $newCorrelation->save(); } }