예제 #1
0
 /**
  * @param Contact $entity
  * @param array   $result
  *
  * @return array
  */
 protected function prepareContactEntities(Contact $entity, array $result)
 {
     // use contact source name instead of label
     $source = $entity->getSource();
     if ($source) {
         $result['source'] = $source->getName();
     } else {
         $result['source'] = null;
     }
     // use contact method name instead of label
     $method = $entity->getMethod();
     if ($method) {
         $result['method'] = $method->getName();
     } else {
         $result['method'] = null;
     }
     $result['emails'] = array();
     foreach ($entity->getEmails() as $email) {
         $result['emails'][] = array('email' => $email->getEmail(), 'primary' => $email->isPrimary());
     }
     $result['phones'] = array();
     foreach ($entity->getPhones() as $phone) {
         $result['phones'][] = array('phone' => $phone->getPhone(), 'primary' => $phone->isPrimary());
     }
     // set contact group data
     $groupsData = array();
     foreach ($entity->getGroups() as $group) {
         $groupsData[] = parent::getPreparedItem($group);
     }
     $result['groups'] = $groupsData;
     // convert addresses to plain array
     $addressData = array();
     /** @var $address ContactAddress */
     foreach ($entity->getAddresses() as $address) {
         $addressArray = parent::getPreparedItem($address);
         $addressArray['types'] = $address->getTypeNames();
         $addressArray = $this->removeUnusedValues($addressArray, array('owner'));
         // @todo: just a temporary workaround until new API is implemented
         // the normal solution can be to use region_name virtual field and
         // exclusion rule declared in oro/entity.yml
         // - for 'region' field use a region text if filled; otherwise, use region name
         // - remove regionText field from a result
         if (!empty($addressArray['regionText'])) {
             $addressArray['region'] = $addressArray['regionText'];
         }
         unset($addressArray['regionText']);
         $addressData[] = $addressArray;
     }
     $result['addresses'] = $addressData;
     return $result;
 }
예제 #2
0
 /**
  * @param Contact $entity
  */
 protected function processMultipleRelations(Contact $entity)
 {
     // update groups
     foreach ($entity->getGroups() as $group) {
         $entity->removeGroup($group);
         if ($group = $this->findExistingEntity($group)) {
             $entity->addGroup($group);
         }
     }
     // clear accounts
     foreach ($entity->getAccounts() as $account) {
         $entity->removeAccount($account);
     }
     // update addresses
     /** @var ContactAddress $contactAddress */
     foreach ($entity->getAddresses() as $contactAddress) {
         // update address types
         foreach ($contactAddress->getTypes() as $addressType) {
             $contactAddress->removeType($addressType);
             $existingAddressType = $this->findExistingEntity($addressType);
             if ($existingAddressType) {
                 $contactAddress->addType($existingAddressType);
             }
         }
     }
 }