コード例 #1
0
 /**
  * @name insert($pAdherent)
  * @param AdherentVO
  * @return AdherentVO
  * @desc Ajoute un adherent
  */
 private function insert($pAdherent)
 {
     // Initialisation du Logger
     $lLogger =& Log::singleton('file', CHEMIN_FICHIER_LOGS);
     $lLogger->setMask(Log::MAX(LOG_LEVEL));
     // Si pas de liaison création d'un nouveau compte
     $lNvCompte = false;
     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
         $lNvCompte = true;
     }
     // Insertion de la première mise à jour
     $pAdherent->setDateMaj(StringUtils::dateTimeAujourdhuiDb());
     // 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);
     }
     // Enregistre l'adherent dans la BDD
     $lIdAdherent = AdherentManager::insert($pAdherent);
     if ($lNvCompte) {
         // Création d'un compte
         $lCompte = $lCompteService->get($lCompte->getId());
         $lCompte->setIdAdherentPrincipal($lIdAdherent);
         // Positionnement de l'adhérent en adhérent principal du compte
         $lCompteService->set($lCompte);
     } else {
         // Liaison avec un autre compte
         // Les adhérents du compte
         $lListeAdherent = $this->selectActifByIdCompte($pAdherent->getIdCompte());
         // Le premier adhérent
         $lAdherent = $lListeAdherent[0];
         $lAdhesionService = new AdhesionService();
         // Les adhésions sur le premier adhérent
         $lAdhesions = $lAdhesionService->getAdhesionSurAdherent($lAdherent->getId());
         // Positionne les mêmes adhésions
         foreach ($lAdhesions as $lAdhesion) {
             if (!is_null($lAdhesion->getAdadId())) {
                 $lAdhesionAdherentDetail = $lAdhesionService->getAdhesionAdherent($lAdhesion->getAdadId());
                 $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($lIdAdherent);
                     $lAdhesionService->setAdhesionAdherent($lAdhesionAdherent);
                 }
             }
         }
     }
     $pAdherent->setId($lIdAdherent);
     $pAdherent->setNumero('Z' . $lIdAdherent);
     // Mise à jour du numéro dans l'objet
     AdherentManager::update($pAdherent);
     // Mise à jour de la base
     // Ajout des autorisations de l'adherent
     $lModuleService = new ModuleService();
     $lModulesDefaut = $lModuleService->selectAllDefautVisible();
     $lAutorisations = array();
     foreach ($lModulesDefaut as $lModule) {
         $lAutorisation = new AutorisationVO();
         $lAutorisation->setIdAdherent($lIdAdherent);
         $lAutorisation->setIdModule($lModule->getId());
         //AutorisationManager::insert($lAutorisation);
         array_push($lAutorisations, $lAutorisation);
     }
     if (!empty($lAutorisations)) {
         AutorisationManager::insertByArray($lAutorisations);
     }
     //$lAdherent = AdherentManager::select($lIdAdherent);
     // Insertion des informations de connexion
     $lMdp = MotDePasseUtils::generer();
     $lIdentification = new IdentificationVO();
     $lIdentification->setIdLogin($lIdAdherent);
     $lIdentification->setLogin($pAdherent->getNumero());
     $lIdentification->setPass(md5($lMdp));
     $lIdentification->setType(1);
     $lIdentification->setAutorise(1);
     IdentificationManager::insert($lIdentification);
     // Ajout à la mailing liste
     $lMailingListeService = new MailingListeService();
     if ($pAdherent->getCourrielPrincipal() != "") {
         $lMailingListeService->insert($pAdherent->getCourrielPrincipal());
     }
     if ($pAdherent->getCourrielSecondaire() != "") {
         $lMailingListeService->insert($pAdherent->getCourrielSecondaire());
     }
     // Envoi du mail de confirmation
     if ($pAdherent->getCourrielPrincipal() != "") {
         $lTo = $pAdherent->getCourrielPrincipal();
     } else {
         if ($pAdherent->getCourrielSecondaire() != "") {
             $lTo = $pAdherent->getCourrielSecondaire();
         } else {
             // Pas de mail sur le compte : Envoi au gestionnaire
             $lTo = MAIL_SUPPORT;
         }
     }
     $lFrom = MAIL_SUPPORT;
     $jour = date("d-m-Y");
     $heure = date("H:i");
     $lSujet = "Votre Compte zeybux";
     $lContenu = file_get_contents(CHEMIN_TEMPLATE . MOD_GESTION_ADHERENTS . "/" . "MailAjoutAdherent.html");
     $lContenu = str_replace(array("{LOGIN}", "{MOT_PASSE}", "{PROP_NOM}", "{ZEYBUX_ADRESSE_SITE}"), array($pAdherent->getNumero(), $lMdp, PROP_NOM, ZEYBUX_ADRESSE_SITE), $lContenu);
     $lHeaders = file_get_contents(CHEMIN_TEMPLATE . COMMUN_TEMPLATE . "/" . "EnteteMail.html");
     $lHeaders = str_replace("{FROM}", $lFrom, $lHeaders);
     $VerifEnvoiMail = TRUE;
     $VerifEnvoiMail = @mail($lTo, $lSujet, $lContenu, $lHeaders);
     if ($VerifEnvoiMail === FALSE) {
         $lVr = new TemplateVR();
         $lVr->setValid(false);
         $lVr->getLog()->setValid(false);
         $lErreur = new VRerreur();
         $lErreur->setCode(MessagesErreurs::ERR_118_CODE);
         $lErreur->setMessage(MessagesErreurs::ERR_118_MSG);
         $lVr->getLog()->addErreur($lErreur);
         $lLogger->log("Erreur d'envoi du mail de création de l'adhérent " . $pAdherent->getNumero() . "par : " . $_SESSION[ID_CONNEXION] . ".", PEAR_LOG_INFO);
         // Maj des logs
         $lLogger->log($lVr->export(), PEAR_LOG_INFO);
         // Maj des logs
     } else {
         $lLogger->log("Envoi du mail de création de l'adhérent " . $pAdherent->getNumero() . "par : " . $_SESSION[ID_CONNEXION] . ".", PEAR_LOG_INFO);
         // Maj des logs
     }
     return $pAdherent;
 }