Exemplo n.º 1
0
 /**
  * @param Contact $entity
  */
 protected function processSingleRelations(Contact $entity)
 {
     // update source
     $source = $entity->getSource();
     if ($source) {
         $entity->setSource($this->findExistingEntity($source));
     }
     // update method
     $method = $entity->getMethod();
     if ($method) {
         $entity->setMethod($this->findExistingEntity($method));
     }
     // update assigned to
     $assignedTo = $entity->getAssignedTo();
     if ($assignedTo) {
         $entity->setAssignedTo($this->findExistingEntity($assignedTo));
     }
     // clear reports to
     $entity->setReportsTo(null);
     // update created by
     $createdBy = $entity->getCreatedBy();
     if ($createdBy) {
         $entity->setCreatedBy($this->findExistingEntity($createdBy));
     }
     // update updated by
     $updatedBy = $entity->getUpdatedBy();
     if ($updatedBy) {
         $entity->setUpdatedBy($this->findExistingEntity($updatedBy));
     }
 }
Exemplo n.º 2
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;
 }