示例#1
0
 /**
  * Change Representative Storage object according to object which was getten from Cicero Api
  * 
  * @param \Civix\CoreBundle\Entity\RepresentativeStorage $storeObj
  * @param Object $repr Cicero Api object
  * 
  * @return \Civix\CoreBundle\Entity\RepresentativeStorage
  */
 public function fillStorRepresentativeByApiObj(RepresentativeStorage $storeObj, $repr)
 {
     $storeObj->setStorageId($repr->id);
     $storeObj->setFirstName(trim($repr->first_name));
     $storeObj->setLastName(trim($repr->last_name));
     $storeObj->setOfficialTitle(trim($repr->office->title));
     $storeObj->setAvatarSrc($repr->photo_origin_url);
     //create district
     $representativeDistrict = $this->createDistrict($repr->office->district);
     $storeObj->setDistrict($representativeDistrict);
     $storeObj->setContactEmail($repr->office->chamber->contact_email);
     $storeObj->setWebsite($repr->office->chamber->url);
     $storeObj->setCountry($repr->office->district->country);
     if (isset($repr->addresses[0])) {
         $storeObj->setPhone($repr->addresses[0]->phone_1);
         $storeObj->setFax($repr->addresses[0]->fax_1);
         $state = $this->entityManager->getRepository('CivixCoreBundle:State')->findOneByCode($repr->addresses[0]->state);
         $storeObj->setState($state);
         $storeObj->setCity($repr->addresses[0]->city);
         $storeObj->setAddressLine1($repr->addresses[0]->address_1);
         $storeObj->setAddressLine2($repr->addresses[0]->address_2);
         $storeObj->setAddressLine3($repr->addresses[0]->address_3);
     }
     //extended profile
     $storeObj->setParty($repr->party);
     if (isset($repr->notes[1]) && \DateTime::createFromFormat('Y-m-d', $repr->notes[1]) !== false) {
         $storeObj->setBirthday(new \DateTime($repr->notes[1]));
     }
     if (isset($repr->current_term_start_date)) {
         $storeObj->setStartTerm(new \DateTime($repr->current_term_start_date));
     }
     if (isset($repr->term_end_date)) {
         $storeObj->setEndTerm(new \DateTime($repr->term_end_date));
     }
     //social networks
     foreach ($repr->identifiers as $identificator) {
         $socialType = strtolower(isset($identificator->identifier_type) ? $identificator->identifier_type : '');
         $socialMethod = 'set' . ucfirst($socialType);
         if (method_exists($storeObj, $socialMethod)) {
             $storeObj->{$socialMethod}($identificator->identifier_value);
         }
     }
     //save photo
     if (!empty($repr->photo_origin_url)) {
         $fileInfo = explode('.', basename($repr->photo_origin_url));
         $fileExt = array_pop($fileInfo);
         $storeObj->setAvatarFileName(uniqid() . '.' . $fileExt);
         if (false !== ($header = $this->checkLink($repr->photo_origin_url))) {
             if (strpos($header, 'image') !== false) {
                 //square avatars
                 try {
                     $temp_file = tempnam(sys_get_temp_dir(), 'avatar') . '.' . $fileExt;
                     $this->saveImageFromUrl($storeObj->getAvatarSrc(), $temp_file);
                     $this->cropImageService->rebuildImage($temp_file, $temp_file);
                     $fileUpload = new UploadedFile($temp_file, $storeObj->getAvatarFileName());
                     $storeObj->setAvatar($fileUpload);
                 } catch (\Exception $exc) {
                     $this->logger->addError('Image ' . $storeObj->getAvatarSrc() . '. ' . $exc->getMessage());
                     $storeObj->setAvatarFileName(null);
                 }
             }
         }
     }
     //update profile from congress api
     $this->congressService->updateReprStorageProfile($storeObj);
     //update profile from openstate api
     $this->openstatesService->updateReprStorageProfile($storeObj);
     return $storeObj;
 }
 public function setWebsite($url)
 {
     $this->__load();
     return parent::setWebsite($url);
 }