/**
  * @see parent::check()
  */
 function check()
 {
     $this->completeField("debut", "fin");
     if ($this->debut == null || $this->fin == null) {
         return parent::check();
     }
     $siblings = $this->getSiblings();
     if (count($siblings)) {
         foreach ($siblings as $_sibling) {
             if ($_sibling->debut == null || $_sibling->fin == null) {
                 continue;
             }
             if (CMbRange::collides($this->debut, $this->fin, $_sibling->debut, $_sibling->fin) || CMbRange::inside($this->debut, $this->fin, $_sibling->debut, $_sibling->fin) || CMbRange::inside($_sibling->debut, $_sibling->fin, $this->debut, $this->fin)) {
                 return "Collision de personnel !";
             }
         }
     }
     return parent::check();
 }
Пример #2
0
 /**
  * Calcul si la réeducation est en cours au jour donné au regard des jours ouvrés
  *
  * @param string $date_min Date minimale
  * @param string $date_max Date maximale
  *
  * @return bool
  */
 function getDatesEnCours($date_min, $date_max)
 {
     $this->loadRefSejour();
     return $this->_encours = CMbRange::collides($date_min, $date_max, $this->_premier_jour, $this->_dernier_jour);
 }
 /**
  * check before store
  *
  * @return null|string
  */
 function check()
 {
     $this->completeField("date_debut", "date_fin", "user_id");
     $plage_conge = new CPlageConge();
     $plage_conge->user_id = $this->user_id;
     $plages_conge = $plage_conge->loadMatchingList();
     unset($plages_conge[$this->_id]);
     /** @var $plages_conge CPlageConge[] */
     foreach ($plages_conge as $_plage) {
         if (CMbRange::collides($this->date_debut, $this->date_fin, $_plage->date_debut, $_plage->date_fin)) {
             return CAppUI::tr("CPlageConge-conflit %s", $_plage->_view);
         }
     }
     return parent::check();
 }
Пример #4
0
 /**
  * @deprecated use rearrange2
  * rearrange a list of object in an optimized list
  * 
  * @param array   $intervals   $intervals key => array(lower, upper);
  * @param boolean $permissive  [optional]
  * @param array   &$uncollided array of uncollided elements
  *
  * @return array $lines lignes avec les keys positionned
  */
 static function rearrange($intervals, $permissive = true, &$uncollided = array())
 {
     if (!count($intervals)) {
         return array();
     }
     $lines = array();
     $uncollided = $intervals;
     // multisort ruins the keys if numeric
     if (!is_numeric(reset(array_keys($intervals)))) {
         array_multisort($intervals, SORT_ASC, CMbArray::pluck($intervals, "lower"));
         //order by lower elements ASC
     }
     foreach ($intervals as $_interval_id => $_interval) {
         foreach ($lines as &$_line) {
             $line_occupied = false;
             foreach ($_line as $_positioned_id) {
                 $positioned = $intervals[$_positioned_id];
                 if (CMbRange::collides($_interval["lower"], $_interval["upper"], $positioned["lower"], $positioned["upper"], $permissive)) {
                     $line_occupied = true;
                     unset($uncollided[$_positioned_id]);
                     //continue 2; // Next line
                 }
             }
             if ($line_occupied) {
                 continue;
             }
             $_line[] = $_interval_id;
             continue 2;
             // Next interval
         }
         $lines[count($lines)] = array($_interval_id);
     }
     return $lines;
 }
 /**
  * Tells if it collides with another affectation
  *
  * @param self $aff Other affectation
  *
  * @return bool
  */
 function collide($aff)
 {
     if ($this->_id && $aff->_id && $this->_id == $aff->_id) {
         return false;
     }
     return CMbRange::collides($this->entree, $this->sortie, $aff->entree, $aff->sortie);
 }
Пример #6
0
 /**
  * Check if the object collides another
  *
  * @param CSejour $sejour                 Sejour
  * @param bool    $collides_update_sejour Launch updateFormFields
  *
  * @return boolean
  */
 function collides(CSejour $sejour, $collides_update_sejour = true)
 {
     if ($this->_id && $sejour->_id && $this->_id == $sejour->_id) {
         return false;
     }
     if ($this->annule || $sejour->annule) {
         return false;
     }
     if (in_array($this->type, $this->_not_collides) || in_array($sejour->type, $this->_not_collides)) {
         return false;
     }
     if (CAppUI::conf('dPplanningOp CSejour ssr_not_collides', $this->loadRefEtablissement()->_guid)) {
         if ($this->type == "ssr" xor $sejour->type == "ssr") {
             return false;
         }
     }
     if ($this->group_id != $sejour->group_id) {
         return false;
     }
     if ($collides_update_sejour) {
         $this->updateFormFields();
     }
     switch ($this->conf("check_collisions")) {
         case "no":
             return false;
         case "date":
             $lower1 = CMbDT::date($this->entree);
             $upper1 = CMbDT::date($this->sortie);
             $lower2 = CMbDT::date($sejour->entree);
             $upper2 = CMbDT::date($sejour->sortie);
             break;
         default:
         case "datetime":
             $lower1 = $this->entree;
             $upper1 = $this->sortie;
             $lower2 = $sejour->entree;
             $upper2 = $sejour->sortie;
             break;
     }
     return CMbRange::collides($lower1, $upper1, $lower2, $upper2, false);
 }
Пример #7
0
 /**
  * Charge le séjour et vérifie les dates liées
  *
  * @return CSejour
  */
 function loadRefSejour()
 {
     /** @var CSejour $sejour */
     $sejour = $this->loadFwdRef("sejour_id", true);
     $sejour->loadRefPatient();
     $entree = CMbDT::date($sejour->_entree);
     $sortie = CMbDT::date($sejour->_sortie);
     $this->_in_bounds = CMbRange::collides($this->date_monday, $this->_date_sunday, $entree, $sortie, false);
     $this->_in_bounds_mon = CMbRange::in($this->date_monday, $entree, $sortie);
     $this->_in_bounds_tue = CMbRange::in($this->_date_tuesday, $entree, $sortie);
     $this->_in_bounds_wed = CMbRange::in($this->_date_wednesday, $entree, $sortie);
     $this->_in_bounds_thu = CMbRange::in($this->_date_thursday, $entree, $sortie);
     $this->_in_bounds_fri = CMbRange::in($this->_date_friday, $entree, $sortie);
     $this->_in_bounds_sat = CMbRange::in($this->_date_saturday, $entree, $sortie);
     $this->_in_bounds_sun = CMbRange::in($this->_date_sunday, $entree, $sortie);
     return $this->_ref_sejour = $sejour;
 }
Пример #8
0
 /**
  * Fragment un remplacement par des congés du remplacant
  *
  * @return array Fragments d'intervales de dates
  */
 function makeFragments()
 {
     $fragments = array();
     $croppers = array();
     foreach ($this->_ref_replacer_conges as $_conge) {
         $croppers[] = array("lower" => CMbDT::date("-1 DAY", $_conge->date_debut), "upper" => CMbDT::date("+1 DAY", $_conge->date_fin));
     }
     if (count($this->_ref_replacer_conges) > 0) {
         $fragments = CMbRange::multiCrop(array(array("lower" => $this->deb, "upper" => $this->fin)), $croppers);
         foreach ($fragments as $key => $_fragment) {
             if (!CMbRange::collides($this->_min_deb, $this->_max_fin, $_fragment[0], $_fragment[1])) {
                 unset($fragments[$key]);
             }
         }
     }
     return $this->_ref_replacement_fragments = $fragments;
 }