| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <?php
- declare(strict_types=1);
- namespace App\Service\Education;
- use App\Entity\Education\EducationNotation;
- use App\Enum\Education\TypeCriteriaEnum;
- use App\Test\Service\Access\EducationNotationUtilsTest;
- /**
- * Classe EducationNotationUtils qui contient les fonctions relatives aux évaluations d'un enseignement
- */
- class EducationNotationUtils
- {
- /**
- * Fonction permettant de retrouver la note calculée par rapport à la note maximale possible définie par la structure
- * @param EducationNotation $educationNotation
- * @return float|null
- * @see EducationNotationUtilsTest::testGetNotationTransformed()
- */
- public function getNotationTransformed(EducationNotation $educationNotation): ?float
- {
- /** @noinspection NullPointerExceptionInspection */
- $noteMax = $educationNotation->getEducationStudent()->getAccess()->getOrganization()->getParameters()->getAverage();
- return $this->calculNotationByAMaxNote($educationNotation, $noteMax);
- }
- /**
- * Fonction permettant de retrouver la note calculé par rapport à la note maximale du critère de notation possible définie par la structure
- * @param EducationNotation $educationNotation
- * @return float|null
- * @see EducationNotationUtilsTest::testGetNotationOriginal()
- */
- public function getNotationOriginal(EducationNotation $educationNotation): ?float
- {
- if(!$educationNotation->getCriteriaNotation()) {
- return null;
- }
- $noteMax = $educationNotation->getCriteriaNotation()->getNoteMax();
- return $this->calculNotationByAMaxNote($educationNotation, $noteMax);
- }
- /**
- * Recalcule une note sur 100 par rapport à la nouvelle note maximale passée en paramètre.
- *
- * Les notes sont toutes enregistrées sur 100 dans la DB, cette méthode permet de recalculer la note en fonction
- * de la note maximale de l'école.
- *
- * @param EducationNotation $educationNotation
- * @param float $noteMax
- * @return float|null
- */
- protected function calculNotationByAMaxNote(EducationNotation $educationNotation, float $noteMax): ?float
- {
- if(
- is_null($educationNotation->getNote()) ||
- !$educationNotation->getCriteriaNotation() ||
- $educationNotation->getCriteriaNotation()->getType() !== TypeCriteriaEnum::WITH_NOTATION()->getValue()
- ) {
- return null;
- }
- $note = ($educationNotation->getNote() * $noteMax) / 100;
- return round ( (float)$note , 2 );
- }
- }
|