Ejemplo 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));
     }
 }
Ejemplo n.º 2
0
 /**
  * @param Contact $entity
  * @param array $result
  * @return array
  */
 protected function prepareExternalEntities(Contact $entity, array $result)
 {
     // set assigned to user data
     $assignedTo = $entity->getAssignedTo();
     if ($assignedTo) {
         $result['assignedTo'] = $assignedTo->getId();
     } else {
         $result['assignedTo'] = null;
     }
     // set owner user data
     $owner = $entity->getOwner();
     if ($owner) {
         $result['owner'] = $owner->getId();
     } else {
         $result['owner'] = null;
     }
     // set reports to contact data
     $reportsTo = $entity->getReportsTo();
     if ($reportsTo) {
         $result['reportsTo'] = $reportsTo->getId();
     } else {
         $result['reportsTo'] = null;
     }
     // convert accounts to plain array
     $accountsIds = array();
     foreach ($entity->getAccounts() as $account) {
         $accountsIds[] = $account->getId();
     }
     $result['accounts'] = $accountsIds;
     // set created and updated users
     $createdBy = $entity->getCreatedBy();
     if ($createdBy) {
         $result['createdBy'] = $createdBy->getId();
     } else {
         $result['createdBy'] = null;
     }
     $updatedBy = $entity->getUpdatedBy();
     if ($updatedBy) {
         $result['updatedBy'] = $updatedBy->getId();
     } else {
         $result['updatedBy'] = null;
     }
     return $result;
 }