/** * Vérification de la possibilité de merger plusieurs séjours * * @param CSejour[] $sejours Séjours concernés * * @return void|string */ function checkMerge($sejours = array()) { if ($msg = parent::checkMerge($sejours)) { return $msg; } // Cas des prescriptions $count_prescription = 0; foreach ($sejours as $_sejour) { $_sejour->loadRefPrescriptionSejour(); if ($_sejour->_ref_prescription_sejour && $_sejour->_ref_prescription_sejour->_id) { // Suppression des prescriptions vide $prescription = new CPrescription(); $prescription->load($_sejour->_ref_prescription_sejour->_id); $back_props = $prescription->getBackProps(); $count_back_props = 0; // On retire les logs de la liste des backprops unset($back_props["logs"]); foreach ($back_props as $back_prop => $object) { $count_back_props += $prescription->countBackRefs($back_prop); } if ($count_back_props == 0) { $prescription->delete(); continue; } if ($count_prescription == 1) { return "Impossible de fusionner des sejours qui comportent chacun des prescriptions de séjour"; } $count_prescription++; } } // Cas des affectations $affectation = new CAffectation(); $where["sejour_id"] = CSQLDataSource::prepareIn(CMbArray::pluck($sejours, "_id")); /** @var CAffectation[] $affectations */ $affectations = $affectation->loadList($where); foreach ($affectations as $_affectation_1) { foreach ($affectations as $_affectation_2) { if ($_affectation_1->collide($_affectation_2)) { return CAppUI::tr("CSejour-merge-warning-affectation-conflict", $_affectation_1->_view, $_affectation_2->_view); } } } return null; }