/**
  * Synchronize $storageRepresentative with Cicero representative.
  * 
  * @param \Civix\CoreBundle\Entity\RepresentativeStorage $storageRepresentative
  * @return boolean
  */
 public function synchronizeRepresentative(RepresentativeStorage $storageRepresentative)
 {
     $ciceroRepresentative = $this->ciceroService->findRepresentativeByNameAndId($storageRepresentative->getFirstName(), $storageRepresentative->getLastName(), $storageRepresentative->getStorageId());
     $civixRepresentative = $storageRepresentative->getRepresentative();
     if ($ciceroRepresentative) {
         //update current data of representative from cicero
         $this->ciceroStorageService->fillStorRepresentativeByApiObj($storageRepresentative, $ciceroRepresentative);
         $this->entityManager->persist($storageRepresentative);
         //update representative in civix
         if ($civixRepresentative instanceof Representative) {
             $civixRepresentative->setOfficialTitle($storageRepresentative->getOfficialTitle());
             $civixRepresentative->setDistrict($storageRepresentative->getDistrict());
             $this->entityManager->persist($civixRepresentative);
             $this->entityManager->flush($civixRepresentative);
         }
         $this->entityManager->flush($storageRepresentative);
     } else {
         //unlink district and storage
         if ($civixRepresentative instanceof Representative) {
             $civixRepresentative->setDistrict(null);
             $civixRepresentative->setStorageId(null);
             $this->entityManager->persist($civixRepresentative);
             $this->entityManager->flush($civixRepresentative);
         }
         $this->entityManager->remove($storageRepresentative);
         $this->entityManager->flush($storageRepresentative);
         return false;
     }
     return true;
 }
Пример #2
0
 public function updateReprStorageProfile(RepresentativeStorage $representative)
 {
     $openStateId = $this->getRepresentativeByName($representative->getFirstName(), $representative->getLastName());
     if ($openStateId) {
         $representative->setOpenstateId($openStateId);
     }
     return $representative;
 }
Пример #3
0
 public function updateReprStorageProfile(RepresentativeStorage $representative)
 {
     $response = $this->getRepresentativeByName($representative->getFirstName(), $representative->getLastName());
     foreach ($response as $objField => $objValue) {
         $fieldName = ucfirst($objField);
         $representativeSetMethod = 'set' . $fieldName;
         $representativeGetMethod = 'get' . $fieldName;
         if (method_exists($representative, $representativeSetMethod) && method_exists($representative, $representativeGetMethod)) {
             $currentPropertyValue = $representative->{$representativeGetMethod}();
             if (empty($currentPropertyValue)) {
                 $representative->{$representativeSetMethod}($objValue);
             }
         }
     }
     return $representative;
 }
 public function getLastName()
 {
     $this->__load();
     return parent::getLastName();
 }