/** * @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; }
/** * @param Contact $entity */ protected function processSecurityRelations(Contact $entity) { // update owner $owner = $entity->getOwner(); if ($owner) { $owner = $this->findExistingEntity($owner); } if (!$owner) { $token = $this->securityContext->getToken(); if ($token) { $owner = $token->getUser(); } } $entity->setOwner($owner); // update organization $organization = $entity->getOrganization(); if ($organization) { $organization = $this->findExistingEntity($organization); } if (!$organization) { $token = $this->securityContext->getToken(); if ($token && $token instanceof OrganizationContextTokenInterface) { $organization = $token->getOrganizationContext(); } } $entity->setOrganization($organization); }