Files
alrahma_sunday_school/app/Services/Calculators/ProjectCalculator.php
T
2026-02-10 22:11:06 -05:00

33 lines
962 B
PHP

<?php
namespace App\Services\Calculators;
use App\Interfaces\ScoreCalculatorInterface;
use App\Models\ProjectModel;
class ProjectCalculator implements ScoreCalculatorInterface
{
private $projectModel;
public function __construct(ProjectModel $projectModel)
{
$this->projectModel = $projectModel;
}
/**
* Calculate the average project score for a student
*
* @param int $studentId
* @param string $semester
* @param string $schoolYear
* @return array Returns ['project_avg' => float|null]
* @throws \RuntimeException If no project scores are found
*/
public function calculate(int $studentId, string $semester, string $schoolYear, ?int $classSectionId = null): array
{
$average = $this->projectModel->getAverageProjectScore($studentId, $semester, $schoolYear, $classSectionId);
return ['project_avg' => $average !== null ? (float) $average : null];
}
}