public function approveRepresentative(Representative $representative) { $representative->setStatus(Representative::STATUS_ACTIVE); //find in current representative storage $reprStorageObj = $this->entityManager->getRepository('CivixCoreBundle:RepresentativeStorage')->getSTRepresentativeByOfficialInfo($representative->getFirstName(), $representative->getLastName(), $representative->getOfficialTitle()); if (!$reprStorageObj) { //update database from api $district = $this->ciceroService->updateByRepresentativeInfo($representative); //if no representative in cicero api if (!$district) { //try to get info by address $districts = $this->ciceroService->getRepresentativeByLocation($representative->getOfficialAddress(), $representative->getCity(), $representative->getState()->getCode(), $representative->getCountry(), true); if (!empty($districts)) { $district = array_shift($districts); $representative->setIsNonLegislative(1); } else { return false; } } $representative->setDistrict($district); } else { $representative->setDistrict($reprStorageObj->getDistrict()); $representative->setStorageId($reprStorageObj->getStorageId()); } return $representative; }
/** * Get representative from api, save his, get district id * @param Representative $representative Representative object * * @return integer */ public function updateByRepresentativeInfo(Representative $representative) { $representativesFromApi = $this->ciceroService->findRepresentativeByOfficialData($representative->getFirstName(), $representative->getLastName(), $representative->getOfficialTitle()); if ($representativesFromApi) { return $this->updateRepresentativeStorage($representativesFromApi, $representative); } return false; }
public static function toRepresentativeOwnerData(Representative $representative) { $data = ['id' => $representative->getId(), 'type' => $representative->getType(), 'official_title' => $representative->getOfficialTitle(), 'first_name' => $representative->getFirstName(), 'last_name' => $representative->getLastName(), 'avatar_file_path' => $representative->getAvatarFileName()]; if ($representative->getStorageId()) { $data['storage_id'] = $representative->getStorageId(); } return $data; }
public function getOfficialTitle() { $this->__load(); return parent::getOfficialTitle(); }