Ejemplo n.º 1
1
 public function addCotisation($login, $debut, $fin, $montant)
 {
     // vérification des droits en écriture et accès aux cotisations
     if (!$this->auth->getDroitEcriture() || !$this->auth->getDroitCotisations()) {
         throw new ApiException(403);
     }
     // récupération de la personne concernée
     $personne = PersonneQuery::create()->findOneByLogin($login);
     if (!$personne) {
         throw new ApiException(404);
     }
     // On récupère toutes les cotisations de ce user
     $cotisations = $personne->getCotisations();
     // Si une de ces cotisations englobe la nouvelle cotisation, on la refuse
     foreach ($cotisations as $cotisation) {
         if ($debut >= strtotime($cotisation->getDebut()) && $fin <= strtotime($cotisation->getFin()) && !$cotisation->getDeletedAt()) {
             throw new ApiException(409);
         }
     }
     // création de la nouvelle cotisation
     $cotisation = new Cotisation();
     $cotisation->setDebut($debut);
     $cotisation->setFin($fin);
     $cotisation->setPersonne($personne);
     $cotisation->setMontant($montant);
     // sauvegarde
     $cotisation->save();
     return $cotisation->getid();
 }