EducationNotationUtils.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Service\Education;
  4. use App\Entity\Education\EducationNotation;
  5. use App\Enum\Education\TypeCriteriaEnum;
  6. use App\Test\Service\Access\EducationNotationUtilsTest;
  7. /**
  8. * Classe EducationNotationUtils qui contient les fonctions relatives aux évaluations d'un enseignement
  9. */
  10. class EducationNotationUtils
  11. {
  12. /**
  13. * Fonction permettant de retrouver la note calculée par rapport à la note maximale possible définie par la structure
  14. * @param EducationNotation $educationNotation
  15. * @return float|null
  16. * @see EducationNotationUtilsTest::testGetNotationTransformed()
  17. */
  18. public function getNotationTransformed(EducationNotation $educationNotation): ?float
  19. {
  20. /** @noinspection NullPointerExceptionInspection */
  21. $noteMax = $educationNotation->getEducationStudent()->getAccess()->getOrganization()->getParameters()->getAverage();
  22. return $this->calculNotationByAMaxNote($educationNotation, $noteMax);
  23. }
  24. /**
  25. * Fonction permettant de retrouver la note calculé par rapport à la note maximale du critère de notation possible définie par la structure
  26. * @param EducationNotation $educationNotation
  27. * @return float|null
  28. * @see EducationNotationUtilsTest::testGetNotationOriginal()
  29. */
  30. public function getNotationOriginal(EducationNotation $educationNotation): ?float
  31. {
  32. if(!$educationNotation->getCriteriaNotation()) {
  33. return null;
  34. }
  35. $noteMax = $educationNotation->getCriteriaNotation()->getNoteMax();
  36. return $this->calculNotationByAMaxNote($educationNotation, $noteMax);
  37. }
  38. /**
  39. * Recalcule une note sur 100 par rapport à la nouvelle note maximale passée en paramètre.
  40. *
  41. * Les notes sont toutes enregistrées sur 100 dans la DB, cette méthode permet de recalculer la note en fonction
  42. * de la note maximale de l'école.
  43. *
  44. * @param EducationNotation $educationNotation
  45. * @param float $noteMax
  46. * @return float|null
  47. */
  48. protected function calculNotationByAMaxNote(EducationNotation $educationNotation, float $noteMax): ?float
  49. {
  50. if(
  51. is_null($educationNotation->getNote()) ||
  52. !$educationNotation->getCriteriaNotation() ||
  53. $educationNotation->getCriteriaNotation()->getType() !== TypeCriteriaEnum::WITH_NOTATION()->getValue()
  54. ) {
  55. return null;
  56. }
  57. $note = ($educationNotation->getNote() * $noteMax) / 100;
  58. return round ( (float)$note , 2 );
  59. }
  60. }