public function handle(\Voetbal\Command\AssociationAdd $command) { $entityManager = Service::getEntityManager(); // check if name not exists in repository $associationRepos = $entityManager->getRepository("Voetbal\\DAO\\Association"); $oDAOAssociation = $associationRepos->findOneBy(array('name' => $command->getName())); if ($oDAOAssociation !== null) { throw new \Exception("de bondsnaam " . $command->getName() . " bestaat al", E_ERROR); } $oAssociation = new Association($command->getName()); $oAssociation->setDescription($command->getDescription()); $oDAOParentAssociation = null; $oParentAssociation = $command->getParent(); if ($oParentAssociation !== null) { $oDAOParentAssociation = $associationRepos->findOneBy(array('name' => $oParentAssociation->getName())); if ($oDAOParentAssociation === null) { throw new \Exception("de hoofdbond bestaat niet", E_ERROR); } } $oAssociation->setParent($oParentAssociation); $oDAOAssociation = new DAOAssociation(); $oDAOAssociation->setName($oAssociation->getName()); $oDAOAssociation->setDescription($oAssociation->getDescription()); $oDAOAssociation->setParent($oDAOParentAssociation); $entityManager->persist($oDAOAssociation); $entityManager->flush(); // return LeagueRepository::add( $oLeague ); return $oAssociation; }
public function handle(\Voetbal\Command\LeagueAdd $command) { $oLeague = new League($command->getName(), $command->getAbbreviation()); // echo "handled command addseason, should be written tot db" . PHP_EOL; $oDAOLeague = new DAOLeague(); $oDAOLeague->setName($oLeague->getName()); $oDAOLeague->setAbbreviation($oLeague->getAbbreviation()); $entityManager = Service::getEntityManager(); $entityManager->persist($oDAOLeague); $entityManager->flush(); // return LeagueRepository::add( $oLeague ); return $oLeague; }
public function handle(\Voetbal\Command\SeasonAdd $command) { $oSeason = new Season($command->getName(), $command->getPeriod()); // echo "handled command addseason, should be written tot db" . PHP_EOL; $oDAOSeason = new DAOSeason(); $oDAOSeason->setName($oSeason->getName()); $oDAOPeriod = new DAOPeriod(); $oDAOPeriod->setStartDateTime(new \DateTime("@" . $oSeason->getStartDate()->getTimestamp())); $oDAOPeriod->setEndDateTime(new \DateTime("@" . $oSeason->getEndDate()->getTimestamp())); $oDAOSeason->setPeriod($oDAOPeriod); $entityManager = Service::getEntityManager(); $entityManager->persist($oDAOSeason); $entityManager->flush(); // return SeasonRepository::add( $oSeason ); return $oSeason; }