/orm/propel-build/classes/gepi/PeriodeNote.php

https://github.com/tbelliard/gepi · PHP · 128 lines · 67 code · 12 blank · 49 comment · 28 complexity · f2fe6b2bdde8f6041dc2cc7210777eee MD5 · raw file

  1. <?php
  2. /**
  3. * Skeleton subclass for representing a row from the 'periodes' table.
  4. *
  5. * Table regroupant les periodes de notes pour les classes
  6. *
  7. * You should add additional methods to this class to meet the
  8. * application requirements. This class will only be generated as
  9. * long as it does not already exist in the output directory.
  10. *
  11. * @package propel.generator.gepi
  12. */
  13. class PeriodeNote extends BasePeriodeNote {
  14. /**
  15. * @var array PeriodesNote[] Collection to store aggregation of PeriodesNote objects.
  16. */
  17. protected $dateDebut;
  18. /**
  19. *
  20. * Retourne la date de debut de periode
  21. *
  22. * @param string $format The date/time format string (either date()-style or strftime()-style).
  23. * If format is NULL, then the raw DateTime object will be returned.
  24. *
  25. * @return DateTime $date ou null si non précisé
  26. */
  27. public function getDateDebut($format = null) {
  28. if(null === $this->dateDebut) {
  29. if ($this->isNew()) {
  30. //do nothing
  31. } else {
  32. $dateDebut = null;
  33. if ($this->getNumPeriode() == 1) {
  34. //on essaye de récupérer la date de début dans le calendrier des périodes
  35. $edt_periode = EdtCalendrierPeriodeQuery::create()->filterByNumeroPeriode($this->getNumPeriode())->orderByDebutCalendrierTs()->findOne();
  36. if ($edt_periode != null) {
  37. $dateDebut = $edt_periode->getJourdebutCalendrier(null);
  38. } else {
  39. //c'est la premiere periode
  40. //on va renvoyer par default le début de l'année scolaire
  41. include_once(dirname(__FILE__).'/../../../helpers/EdtHelper.php');
  42. $dateDebut = EdtHelper::getPremierJourAnneeScolaire($this->getDateFin());
  43. }
  44. } else {
  45. //on renvoi la date de fin de la periode precedente
  46. $periode_prec = PeriodeNoteQuery::create()->filterByIdClasse($this->getIdClasse())->filterByNumPeriode($this->getNumPeriode() - 1)->findOne();
  47. if ($periode_prec != null) {
  48. $dateDebut = $periode_prec->getDateFin(null);
  49. }
  50. //on prend le lendemain
  51. if ($dateDebut !== null) {
  52. $dateDebut->modify("+24 hours");
  53. }
  54. }
  55. if ($dateDebut !== null) {
  56. //on commence la periode a 00:00
  57. $dateDebut->setTime(0,0,0);
  58. }
  59. $this->dateDebut = $dateDebut;
  60. }
  61. }
  62. if ($this->dateDebut === null) {
  63. //on initialise a un timestamp de 0 pour ne pas faire de nouveau la recherche
  64. $this->dateDebut == new DateTime('@0');
  65. return null;
  66. } else if ($this->dateDebut->format('U') == 0) {
  67. return null;
  68. }
  69. if ($format === null) {
  70. //we return a DateTime object.
  71. return $this->dateDebut;
  72. } elseif (strpos($format, '%') !== false) {
  73. return strftime($format, $this->dateDebut->format('U'));
  74. } else {
  75. return $this->dateDebut->format($format);
  76. }
  77. }
  78. /**
  79. * Compare deux periodeNote par leur numéros
  80. *
  81. * @param PeriodeNote $groupeA Le premier PeriodeNote a comparer
  82. * @param PeriodeNote $groupeB Le deuxieme PeriodeNote a comparer
  83. * @return int un entier, qui sera inférieur, égal ou supérieur à zéro suivant que le premier argument est considéré comme plus petit, égal ou plus grand que le second argument.
  84. */
  85. public static function comparePeriodeNote($a, $b) {
  86. if ($a ==null || $b == null){
  87. throw new PropelException("Objet null pour la comparaison.");
  88. }
  89. return $a->getNumPeriode() - $b->getNumPeriode();
  90. }
  91. /**
  92. * date de verrouillage de la periode. On rajoute le temps 23:59:59
  93. *
  94. * @param string $format The date/time format string (either date()-style or strftime()-style).
  95. * If format is NULL, then the raw DateTime object will be returned.
  96. * @return mixed Formatted date/time value as string or DateTime object (if format is NULL), NULL if column is NULL, and 0 if column value is 0000-00-00 00:00:00
  97. * @throws PropelException - if unable to parse/validate the date/time value.
  98. */
  99. public function getDateFin($format = 'Y-m-d H:i:s') {
  100. //on fini la periode a 23:59
  101. $date_fin = parent::getDateFin(null);
  102. if ($date_fin == null) {
  103. return null;
  104. } else {
  105. $date_fin->setTime(23,59,59);
  106. if ($format === null) {
  107. // Because propel.useDateTimeClass is TRUE, we return a DateTime object.
  108. return $date_fin;
  109. } elseif (strpos($format, '%') !== false) {
  110. return strftime($format, $date_fin->format('U'));
  111. } else {
  112. return $date_fin->format($format);
  113. }
  114. }
  115. }
  116. } // PeriodeNote