/**
  * For our form we have to add all 3 addresses. Filled or not filled.
  * But it's bad to add these empty addresses into DB. So we remove empty addresses here.
  *
  * @param \JWeiland\Clubdirectory\Domain\Model\Club $club
  */
 protected function removeEmptyAddresses(\JWeiland\Clubdirectory\Domain\Model\Club $club)
 {
     /** @var \TYPO3\CMS\Extbase\Object\ObjectManager $objectManager */
     $objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
     /** @var \JWeiland\Clubdirectory\Domain\Model\Address $emptyAddress */
     $emptyAddress = $objectManager->get('JWeiland\\Clubdirectory\\Domain\\Model\\Address');
     $addresses = clone $club->getAddresses();
     /** @var \JWeiland\Clubdirectory\Domain\Model\Address $address */
     foreach ($addresses as $address) {
         if ($address == $emptyAddress) {
             $club->removeAddress($address);
         }
     }
 }
 /**
  * If no poi record was connected with address try to create one.
  *
  * @param \JWeiland\Clubdirectory\Domain\Model\Club $club
  */
 protected function addMapRecordIfPossible(\JWeiland\Clubdirectory\Domain\Model\Club $club)
 {
     /** @var \JWeiland\Clubdirectory\Domain\Model\Address $address */
     foreach ($club->getAddresses() as $address) {
         // add a new poi record if not set already
         if ($address->getTxMaps2Uid() === null) {
             $results = $this->geocodeUtility->findPositionByAddress($address->getAddress());
             if (count($results)) {
                 $results->rewind();
                 /** @var \JWeiland\Maps2\Domain\Model\RadiusResult $result */
                 $result = $results->current();
                 /** @var \JWeiland\Maps2\Domain\Model\PoiCollection $poi */
                 $poi = $this->objectManager->get('JWeiland\\Maps2\\Domain\\Model\\PoiCollection');
                 $poi->setCollectionType('Point');
                 $poi->setTitle($result->getFormattedAddress());
                 $poi->setAddress($result->getFormattedAddress());
                 $poi->setLatitude($result->getGeometry()->getLocation()->getLatitude());
                 $poi->setLongitude($result->getGeometry()->getLocation()->getLongitude());
                 $poi->setLatitudeOrig($result->getGeometry()->getLocation()->getLatitude());
                 $poi->setLongitudeOrig($result->getGeometry()->getLocation()->getLongitude());
                 $address->setTxMaps2Uid($poi);
             }
         }
     }
 }
 /**
  * action edit.
  *
  * @param \JWeiland\Clubdirectory\Domain\Model\Club $club
  */
 public function editAction(\JWeiland\Clubdirectory\Domain\Model\Club $club)
 {
     // this is something very terrible of extbase
     // because of the checkboxes in address records we have to add all 3 addresses. Filled or not filled.
     for ($i = count($club->getAddresses()); $i < 3; ++$i) {
         $club->getAddresses()->attach(new Address());
     }
     $this->view->assign('club', $club);
     $this->view->assign('categories', $this->categoryRepository->findByParent($this->extConf->getRootCategory()));
     $this->view->assign('addressTitles', $this->getAddressTitles());
 }