Example #1
0
	/**
	 * Returns a new PeriodeNoteQuery object.
	 *
	 * @param     string $modelAlias The alias of a model in the query
	 * @param     Criteria $criteria Optional Criteria to build the query from
	 *
	 * @return    PeriodeNoteQuery
	 */
	public static function create($modelAlias = null, $criteria = null)
	{
		if ($criteria instanceof PeriodeNoteQuery) {
			return $criteria;
		}
		$query = new PeriodeNoteQuery();
		if (null !== $modelAlias) {
			$query->setModelAlias($modelAlias);
		}
		if ($criteria instanceof Criteria) {
			$query->mergeWith($criteria);
		}
		return $query;
	}
Example #2
0
  	/**
	 *
	 * Retourne la date de debut de periode
	 *
	 * @param      string $format The date/time format string (either date()-style or strftime()-style).
	 *							If format is NULL, then the raw DateTime object will be returned.
	 *
	 * @return DateTime $date ou null si non précisé
	 */
	public function getDateDebut($format = null) {
	    if(null === $this->dateDebut) {
		    if ($this->isNew()) {
			    //do nothing
		    } else {
			    $dateDebut = null;
			    if ($this->getNumPeriode() == 1) {
				//on essaye de récupérer la date de début dans le calendrier des périodes
				$edt_periode = EdtCalendrierPeriodeQuery::create()->filterByNumeroPeriode($this->getNumPeriode())->orderByDebutCalendrierTs()->findOne();
				if ($edt_periode != null) {
				    $dateDebut = $edt_periode->getJourdebutCalendrier(null);
				} else {
				    //c'est la premiere periode
				    //on va renvoyer par default le début de l'année scolaire
				    include_once(dirname(__FILE__).'/../../../helpers/EdtHelper.php');
				    $dateDebut = EdtHelper::getPremierJourAnneeScolaire($this->getDateFin());
				}
			    } else {
				//on renvoi la date de fin de la periode precedente
				$periode_prec = PeriodeNoteQuery::create()->filterByIdClasse($this->getIdClasse())->filterByNumPeriode($this->getNumPeriode() - 1)->findOne();
				if ($periode_prec != null) {
				    $dateDebut = $periode_prec->getDateFin(null);
				}
				//on prend le lendemain
				if ($dateDebut !== null) {
				    $dateDebut->modify("+24 hours");
				}
			    }
			    if ($dateDebut !== null) {
				//on commence la periode a 00:00
				$dateDebut->setTime(0,0,0);
			    }
			    $this->dateDebut = $dateDebut;
		    }
	    }
	    if ($this->dateDebut === null) {
		    //on initialise a un timestamp de 0  pour ne pas faire de nouveau la recherche
		    $this->dateDebut == new DateTime('@0');
		    return null;
	    } else if ($this->dateDebut->format('U') == 0) {
		    return null;
	    }

	    if ($format === null) {
		    //we return a DateTime object.
		    return $this->dateDebut;
	    } elseif (strpos($format, '%') !== false) {
		    return strftime($format, $this->dateDebut->format('U'));
	    } else {
		    return $this->dateDebut->format($format);
	    }
	}
Example #3
0
	/**
	 * Removes this object from datastore and sets delete attribute.
	 *
	 * @param      PropelPDO $con
	 * @return     void
	 * @throws     PropelException
	 * @see        BaseObject::setDeleted()
	 * @see        BaseObject::isDeleted()
	 */
	public function delete(PropelPDO $con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(PeriodeNotePeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
		}

		$con->beginTransaction();
		try {
			$deleteQuery = PeriodeNoteQuery::create()
				->filterByPrimaryKey($this->getPrimaryKey());
			$ret = $this->preDelete($con);
			if ($ret) {
				$deleteQuery->delete($con);
				$this->postDelete($con);
				$con->commit();
				$this->setDeleted(true);
			} else {
				$con->commit();
			}
		} catch (Exception $e) {
			$con->rollBack();
			throw $e;
		}
	}
Example #4
0
	/**
	 * Retourne la periode de note correspondante à la date donnée en paramètre.
         * On regarde proritairement les dates de fin des périodes de notes,
         * puis les renseignements de l'edt.
         * Si aucune période n'est trouvée on retourne la dernière période ouverte pour l'ordre de nommage,
         * Si toujours aucune période n'est trouvée on renvoi null
	 *
	 * @return     PeriodeNote $periode la periode de la date précisée, ou null si non trouvé
	 */
	public function getPeriodeNote($v = 'now') {
            // we treat '' as NULL for temporal objects because DateTime('') == DateTime('now')
	    // -- which is unexpected, to say the least.
	    //$dt = new DateTime();
	    if ($v === null || $v === '') {
		    $dt = null;
	    } elseif ($v instanceof DateTime) {
		    $dt = clone $v;
	    } else {
		    // some string/numeric value passed; we normalize that so that we can
		    // validate it.
		    try {
			    if (is_numeric($v)) { // if it's a unix timestamp
				    $dt = new DateTime('@'.$v, new DateTimeZone('UTC'));
				    // We have to explicitly specify and then change the time zone because of a
				    // DateTime bug: http://bugs.php.net/bug.php?id=43003
				    $dt->setTimeZone(new DateTimeZone(date_default_timezone_get()));
			    } else {
				    $dt = new DateTime($v);
			    }
		    } catch (Exception $x) {
			    throw new PropelException('Error parsing date/time value: ' . var_export($v, true), $x);
		    }
	    }

		foreach ($this->getPeriodeNotes() as $periode) {
		    if ($periode->getDateDebut('U') <= $dt->format('U')
				    && $periode->getDateFin(null) != null && $periode->getDateFin('U') > $dt->format('U')) {
                        return $periode;
                    }
		}

                //si on est là on a trouvé aucune période renseignée qui convienne. On va regarder l'edt
		//on verifie si il y a une periode du calendrier avec une periode de note precisee
		$calendrier_periode = EdtCalendrierPeriodePeer::retrieveEdtCalendrierPeriodeActuelle($dt);
		if ($calendrier_periode != null && $calendrier_periode->getNumeroPeriode() != null && $calendrier_periode->getNumeroPeriode() != 0) {
		    $criteria = new Criteria();
		    $criteria->add(PeriodeNotePeer::NUM_PERIODE,$calendrier_periode->getNumeroPeriode());
		    $periodes = $this->getPeriodeNotes($criteria);
		    return $periodes->getFirst();
		}

                //si on est là on a toujours trouvé aucune période. On renvoi la première période qui peut convenir
                //et qui n'est pas encore achevée
		foreach ($this->getPeriodeNotes() as $periode) {
                    if ($periode->getDateDebut('U') <= $dt->format('U')
                        && ($periode->getDateFin(null) === null || $periode->getDateFin('U') > $dt->format('U'))) {
                        return $periode;
                    }
		}

                //si on a toujours aucune période, on renvoi la dernière période dans l'ordre des numéro, ou null si on ne trouve rien
                $query = PeriodeNoteQuery::create();
                return $query->filterByIdClasse($this->getId())->orderByNumPeriode(Criteria::DESC)->findOne();
	}
Example #5
0
	/**
	 * Returns the number of related PeriodeNote objects.
	 *
	 * @param      Criteria $criteria
	 * @param      boolean $distinct
	 * @param      PropelPDO $con
	 * @return     int Count of related PeriodeNote objects.
	 * @throws     PropelException
	 */
	public function countPeriodeNotes(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
	{
		if(null === $this->collPeriodeNotes || null !== $criteria) {
			if ($this->isNew() && null === $this->collPeriodeNotes) {
				return 0;
			} else {
				$query = PeriodeNoteQuery::create(null, $criteria);
				if($distinct) {
					$query->distinct();
				}
				return $query
					->filterByClasse($this)
					->count($con);
			}
		} else {
			return count($this->collPeriodeNotes);
		}
	}
Example #6
0
      	/**
	 *
	 * Retourne la periode de note associée
	 *
	 *
	 * @return PeriodeNote $periode_note
	 */
	public function getPeriodeNote() {
	    return PeriodeNoteQuery::create()->filterByIdClasse($this->getIdClasse())->filterByNumPeriode($this->getPeriode())->findOne();
	}