public function seedUnemployment($batches, $allStudents, $programid) { foreach ($batches as $batch) { $students = $allStudents[$batch]; $totalUnemployed = 0; foreach ($students as $student) { $results = Studentterm::getOneEmploymentProgram($student->studentid, $programid); $unemployed = 0; foreach ($results as $result) { if ($result->employment === 'N') { $unemployed = 1; } } $totalUnemployed = $totalUnemployed + $unemployed; } $newCorrelation = new Correlation(); $newCorrelation->factorid = 8; $newCorrelation->batch = $batch; $countStudents = count($students); if ($countStudents > 0) { $newCorrelation->ratio = $totalUnemployed / $countStudents; } else { $newCorrelation->ratio = 0; } $newCorrelation->unittype = 'program'; $newCorrelation->programid = $programid; $newCorrelation->save(); } }