/**
  * @name updateAdhesionAdherent($pParam)
  * @return AjoutAdhesionResponse
  * @desc Met à jour une adhésion d'adhérent
  */
 public function updateAdhesionAdherent($pParam)
 {
     $lVr = AdhesionAdherentDetailValid::validUpdate($pParam);
     if ($lVr->getValid()) {
         $lAdhesionService = new AdhesionService();
         $lAdhesionAdherentDetail = AdhesionAdherentDetailToVO::convertFromArray($pParam);
         return new AjoutAdhesionResponse($lAdhesionService->setAdhesionAdherent($lAdhesionAdherentDetail));
     }
     return $lVr;
 }
Ejemplo n.º 2
0
 /**
  * @name update($pAdherent)
  * @param AdherentVO
  * @return AdherentVO
  * @desc Modifie un adherent
  */
 private function update($pAdherent)
 {
     $lAdherentActuel = AdherentManager::select($pAdherent->getId());
     // Si pas de liaison création d'un nouveau compte
     if ($pAdherent->getIdCompte() == 0) {
         // Création d'un nouveau compte
         $lCompte = new CompteVO();
         $lCompteService = new CompteService();
         $lCompte = $lCompteService->set($lCompte);
         $pAdherent->setIdCompte($lCompte->getId());
         // Laision avec l'adhérent
         $lCompte->setIdAdherentPrincipal($pAdherent->getId());
         // Positionnement de l'adhérent en adhérent principal du compte
         $lCompteService->set($lCompte);
     } else {
         if ($pAdherent->getIdCompte() != $lAdherentActuel->getIdCompte()) {
             // Liaison avec un autre compte
             $lAdhesionService = new AdhesionService();
             // Suppression des adhésions actuelles
             $lAdhesionService->deleteAdhesionAdherentByIdAdherent($pAdherent->getId());
             // Les adhérents du compte
             $lListeAdherent = $this->selectActifByIdCompte($pAdherent->getIdCompte());
             // Le premier adhérent
             $lAdherent = $lListeAdherent[0];
             // Les adhésions sur le premier adhérent
             $lAdhesions = $lAdhesionService->getAdhesionSurAdherent($lAdherent->getId());
             // Positionne les mêmes adhésions si elles existent
             foreach ($lAdhesions as $lAdhesion) {
                 $lAdhesionAdherentDetail = $lAdhesionService->getAdhesionAdherent($lAdhesion->getAdadId());
                 if ($lAdhesionAdherentDetail) {
                     $lAdhesionAdherent = $lAdhesionAdherentDetail->getAdhesionAdherent();
                     $lTypeAdhesion = $lAdhesionService->getTypeAdhesion($lAdhesionAdherent->getIdTypeAdhesion());
                     if ($lTypeAdhesion->getIdPerimetre() == 2) {
                         // Si type d'adhésion sur périmètre compte
                         $lAdhesionAdherent->setId('');
                         $lAdhesionAdherent->setIdAdherent($pAdherent->getId());
                         $lAdhesionService->setAdhesionAdherent($lAdhesionAdherent);
                     }
                 }
             }
         }
     }
     // Insertion de la date de mise à jour
     $pAdherent->setDateMaj(StringUtils::dateTimeAujourdhuiDb());
     // On reporte le numero dans la maj
     $pAdherent->setNumero($lAdherentActuel->getNumero());
     // L'adherent n'est pas supprimé
     $pAdherent->setEtat(1);
     // Mise en forme des données
     $pAdherent->setNom(StringUtils::formaterNom(trim($pAdherent->getNom())));
     $pAdherent->setPrenom(StringUtils::formaterPrenom(trim($pAdherent->getPrenom())));
     $pAdherent->setCourrielPrincipal(trim($pAdherent->getCourrielPrincipal()));
     $pAdherent->setCourrielSecondaire(trim($pAdherent->getCourrielSecondaire()));
     $pAdherent->setTelephonePrincipal(trim($pAdherent->getTelephonePrincipal()));
     $pAdherent->setTelephoneSecondaire(trim($pAdherent->getTelephoneSecondaire()));
     $pAdherent->setAdresse(trim($pAdherent->getAdresse()));
     $pAdherent->setCodePostal(trim($pAdherent->getCodePostal()));
     $pAdherent->setVille(StringUtils::formaterVille(trim($pAdherent->getVille())));
     $pAdherent->setCommentaire(trim($pAdherent->getCommentaire()));
     // Protection des dates vides
     if ($pAdherent->getDateNaissance() == '') {
         $pAdherent->setDateNaissance(StringUtils::FORMAT_DATE_NULLE);
     }
     if ($pAdherent->getDateAdhesion() == '') {
         $pAdherent->setDateAdhesion(StringUtils::FORMAT_DATE_NULLE);
     }
     if ($pAdherent->getDateMaj() == '') {
         $pAdherent->setDateMaj(StringUtils::FORMAT_DATE_NULLE);
     }
     // Maj de l'adherent dans la BDD
     $lRetour = AdherentManager::update($pAdherent);
     // Récupération des autorisations acutelles
     $lAutorisationsActuelles = AutorisationManager::selectByIdAdherent($pAdherent->getId());
     $lModuleService = new ModuleService();
     $lModulesDefaut = $lModuleService->selectAllDefautVisible();
     $lIdModuleDefaut = array();
     foreach ($lModulesDefaut as $lModule) {
         array_push($lIdModuleDefaut, $lModule->getId());
     }
     // Suppression des autorisations
     $lIdSuppAutorisation = array();
     foreach ($lAutorisationsActuelles as $lAutorisationActu) {
         // Suppression si ce n'est pas un module par defaut
         if (!in_array($lAutorisationActu->getIdModule(), $lIdModuleDefaut)) {
             $lSupp = true;
             foreach ($pAdherent->getListeModule() as $lIdModule) {
                 if ($lAutorisationActu->getIdModule() == $lIdModule) {
                     $lSupp = false;
                 }
             }
             if ($lSupp) {
                 array_push($lIdSuppAutorisation, $lAutorisationActu->getId());
             }
         }
     }
     if (!empty($lIdSuppAutorisation)) {
         AutorisationManager::deleteByArray($lIdSuppAutorisation);
     }
     // Ajout des nouvelles autorisations du compte
     $lAutorisations = array();
     foreach ($pAdherent->getListeModule() as $lIdModule) {
         $lAjout = true;
         foreach ($lAutorisationsActuelles as $lAutorisationActu) {
             if ($lAutorisationActu->getIdModule() == $lIdModule) {
                 $lAjout = false;
             }
         }
         if ($lAjout) {
             $lAutorisation = new AutorisationVO();
             $lAutorisation->setIdAdherent($pAdherent->getId());
             $lAutorisation->setIdModule($lIdModule);
             array_push($lAutorisations, $lAutorisation);
         }
     }
     if (!empty($lAutorisations)) {
         AutorisationManager::insertByArray($lAutorisations);
     }
     //Mise à jour des inscriptions de mailing liste
     $lMailingListeService = new MailingListeService();
     // Suppression des anciens mails
     if ($lAdherentActuel->getCourrielPrincipal() != "") {
         $lMailingListeService->delete($lAdherentActuel->getCourrielPrincipal());
     }
     if ($lAdherentActuel->getCourrielSecondaire() != "") {
         $lMailingListeService->delete($lAdherentActuel->getCourrielSecondaire());
     }
     // Ajout des nouveaux mails
     if ($pAdherent->getCourrielPrincipal() != "") {
         $lMailingListeService->insert($pAdherent->getCourrielPrincipal());
     }
     if ($pAdherent->getCourrielSecondaire() != "") {
         $lMailingListeService->insert($pAdherent->getCourrielSecondaire());
     }
     return $lRetour;
 }