/** * Renvoi vrai ou faux selon que l'établissement est ouvert à cette horaire (sans se préocupper des vacances) * * @param mixed $dt * @return boolean */ public static function isHoraireOuvert($dt) { $jour_semaine = EdtHelper::$semaine_declaration[$dt->format("w")]; $horaire_tab = EdtHorairesEtablissementPeer::retrieveAllEdtHorairesEtablissementArrayCopy(); if (isset($horaire_tab[$jour_semaine])) { $horaire = $horaire_tab[$jour_semaine]; } else { return false; } if ($dt->format('Hi') >= $horaire->getFermetureHoraireEtablissement('Hi') || $dt->format('Hi') < $horaire->getOuvertureHoraireEtablissement('Hi')) { //etab fermé return false; } return true; }
/** * Compte les demi-journees saisies. Les saisies doivent ètre triées par ordre de début. * Cette méthode ne travaille que sur les dates, et prend en compte les fermeture de l'établissement * * @param PropelObjectCollection $abs_saisie_col collection d'objets AbsenceEleveSaisie * * @return PropelCollection une collection de date time par demi journee comptee (un datetime pour le matin et un datetime pour l'apres midi */ public static function compte_demi_journee($abs_saisie_col, $date_debut_iteration = null, $date_fin_iteration = null) { if ($abs_saisie_col->isEmpty()) { return new PropelCollection(); } $abs_saisie_col->uasort(array("AbsencesEleveSaisieHelper", "compare_debut_absence")); //on récupère l'heure de demi-journée $heure_demi_journee = 11;//11:50 par défaut si rien n'est précisé dans les settings $minute_demi_journee = 50; if (getSettingValue("abs2_heure_demi_journee") != null) { try { $dt_demi_journee = new DateTime(getSettingValue("abs2_heure_demi_journee")); $heure_demi_journee = $dt_demi_journee->format('H'); $minute_demi_journee = $dt_demi_journee->format('i'); } catch (Exception $x) { } } //on va regarder la date du début pour notre algorithme if ($date_debut_iteration == null) { $date_debut_iteration = $abs_saisie_col->getFirst()->getDebutAbs(null); } if ($date_debut_iteration->format('Hi') < $heure_demi_journee.$minute_demi_journee) { $date_debut_iteration->setTime(0, 0, 0); } else { $date_debut_iteration->setTime(12, 0, 0); } //on va regarder la date du fin pour notre algorithme if ($date_fin_iteration == null) { foreach ($abs_saisie_col as $saisie) { if ($date_fin_iteration == null || $saisie->getFinAbs('U') > $date_fin_iteration->format('U')) { $date_fin_iteration = $saisie->getFinAbs(null); } } } if ($date_fin_iteration->format('Hi') < $heure_demi_journee.$minute_demi_journee) { $date_fin_iteration->setTime(12, 0, 0); } else { $date_fin_iteration->setTime(23, 59, 59); $date_fin_iteration->modify("+1 second"); } $date_fin_iteration->modify("+2 hours");//on ajout deux heures pour prendre en compte un décalage dans la date de compteur (+1h35) dans l'algorithme plus bas $result = new PropelCollection(); $date_compteur = clone $date_debut_iteration; $horaire_tab = EdtHorairesEtablissementPeer::retrieveAllEdtHorairesEtablissementArrayCopy(); require_once(dirname(__FILE__)."/EdtHelper.php"); foreach($abs_saisie_col as $saisie) { if ($date_compteur->format('U') < $saisie->getDebutAbs('U')) { $date_compteur = clone $saisie->getDebutAbs(null); } if ($date_compteur >= $date_fin_iteration) { break; } while ($date_compteur <= $saisie->getFinAbs(null) && $date_compteur < $date_fin_iteration) { //est-ce un jour de la semaine ouvert ? if (!EdtHelper::isJourneeOuverte($date_compteur)) { //etab fermé on va passer au lendemain $date_compteur->setTime(23, 59, 59); $date_compteur->modify("+2 hours"); continue; } elseif (!EdtHelper::isHoraireOuvert($date_compteur)) { $horaire = $horaire_tab[EdtHelper::$semaine_declaration[$date_compteur->format("w")]]; if ($date_compteur->format('Hi') < $horaire->getOuvertureHoraireEtablissement('Hi')) { //c'est le matin, on règle sur l'heure d'ouverture $date_compteur->setTime($horaire->getOuvertureHoraireEtablissement('H'), $horaire->getOuvertureHoraireEtablissement('i')); } else { //on est apres la fermeture, on va passer au lendemain $date_compteur->setTime(23, 59, 59); $date_compteur->modify("+2 hours"); } continue; } elseif ($date_compteur < $saisie->getDebutAbs(null) && !EdtHelper::isHoraireOuvert($saisie->getDebutAbs(null))) { $date_compteur->modify("+19 minutes"); continue; } if ($date_compteur->format('Hi') < $heure_demi_journee.$minute_demi_journee) { $date_compteur->setTime(0, 0, 0); } else { $date_compteur->setTime(12, 0, 0); } $date_compteur_suivante = clone $date_compteur; $date_compteur_suivante->modify("+15 hours");//en ajoutant 15 heure on est sur de passer a la demi-journee suivante if ($date_compteur_suivante->format('H') < 12) { $date_compteur_suivante->setTime(0, 0, 0); } else { $date_compteur_suivante->setTime($heure_demi_journee, $minute_demi_journee, 0); } if ($saisie->getDebutAbs(null) < $date_compteur_suivante && $saisie->getFinAbs(null) > $date_compteur) { $result->append(clone $date_compteur); //on ajoute 1h35 //pour eviter le cas ou on a une saisie par exemple sur 11h45 -> 13h et de la compter comme deux demi-journees $date_compteur_suivante->modify("+1 hour"); $date_compteur_suivante->modify("+45 minutes"); } $date_compteur = $date_compteur_suivante; $saisie->clearAllReferences(); } } return $result; }
/** * Populates the object using an array. * * This is particularly useful when populating an object from one of the * request arrays (e.g. $_POST). This method goes through the column * names, checking to see whether a matching key exists in populated * array. If so the setByName() method is called for that column. * * You can specify the key type of the array by additionally passing one * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME, * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM. * The default key type is the column's phpname (e.g. 'AuthorId') * * @param array $arr An array to populate the object from. * @param string $keyType The type of keys the array uses. * @return void */ public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME) { $keys = EdtHorairesEtablissementPeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) $this->setIdHoraireEtablissement($arr[$keys[0]]); if (array_key_exists($keys[1], $arr)) $this->setDateHoraireEtablissement($arr[$keys[1]]); if (array_key_exists($keys[2], $arr)) $this->setJourHoraireEtablissement($arr[$keys[2]]); if (array_key_exists($keys[3], $arr)) $this->setOuvertureHoraireEtablissement($arr[$keys[3]]); if (array_key_exists($keys[4], $arr)) $this->setFermetureHoraireEtablissement($arr[$keys[4]]); if (array_key_exists($keys[5], $arr)) $this->setPauseHoraireEtablissement($arr[$keys[5]]); if (array_key_exists($keys[6], $arr)) $this->setOuvertHoraireEtablissement($arr[$keys[6]]); }
/** * Find object by primary key using raw SQL to go fast. * Bypass doSelect() and the object formatter by using generated code. * * @param mixed $key Primary key to use for the query * @param PropelPDO $con A connection object * * @return EdtHorairesEtablissement A model object, or null if the key is not found */ protected function findPkSimple($key, $con) { $sql = 'SELECT ID_HORAIRE_ETABLISSEMENT, DATE_HORAIRE_ETABLISSEMENT, JOUR_HORAIRE_ETABLISSEMENT, OUVERTURE_HORAIRE_ETABLISSEMENT, FERMETURE_HORAIRE_ETABLISSEMENT, PAUSE_HORAIRE_ETABLISSEMENT, OUVERT_HORAIRE_ETABLISSEMENT FROM horaires_etablissement WHERE ID_HORAIRE_ETABLISSEMENT = :p0'; try { $stmt = $con->prepare($sql); $stmt->bindValue(':p0', $key, PDO::PARAM_INT); $stmt->execute(); } catch (Exception $e) { Propel::log($e->getMessage(), Propel::LOG_ERR); throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), $e); } $obj = null; if ($row = $stmt->fetch(PDO::FETCH_NUM)) { $obj = new EdtHorairesEtablissement(); $obj->hydrate($row); EdtHorairesEtablissementPeer::addInstanceToPool($obj, (string) $key); } $stmt->closeCursor(); return $obj; }
/** * Renvoie la liste des creneaux de la journee * * @return array EdtCreneau */ public static function retrieveAllEdtHorairesEtablissementArrayCopy(){ if (self::$_all_horaires_array_copy == null) { self::$_all_horaires_array_copy = EdtHorairesEtablissementPeer::retrieveAllEdtHorairesEtablissement()->getArrayCopy('JourHoraireEtablissement'); } return self::$_all_horaires_array_copy; }
/** * Retrieve multiple objects by pkey. * * @param array $pks List of primary keys * @param PropelPDO $con the connection to use * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function retrieveByPKs($pks, PropelPDO $con = null) { if ($con === null) { $con = Propel::getConnection(EdtHorairesEtablissementPeer::DATABASE_NAME, Propel::CONNECTION_READ); } $objs = null; if (empty($pks)) { $objs = array(); } else { $criteria = new Criteria(EdtHorairesEtablissementPeer::DATABASE_NAME); $criteria->add(EdtHorairesEtablissementPeer::ID_HORAIRE_ETABLISSEMENT, $pks, Criteria::IN); $objs = EdtHorairesEtablissementPeer::doSelect($criteria, $con); } return $objs; }