/** * @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)); } }
/** * @param Contact $contact * @param EntityManager $entityManager */ protected function setCreatedProperties(Contact $contact, EntityManager $entityManager) { if (!$contact->getCreatedAt()) { $contact->setCreatedAt(new \DateTime('now', new \DateTimeZone('UTC'))); } if (!$contact->getCreatedBy()) { $contact->setCreatedBy($this->getUser($entityManager)); } }
public function testPrePersistWithAlreadySetCreatedAtAndCreatedBy() { $entity = new Contact(); $createdAt = new \DateTime(); $createdBy = new User(); $entity->setCreatedAt($createdAt)->setCreatedBy($createdBy); $this->mockSecurityContext(); $em = $this->getEntityManagerMock(); $args = new LifecycleEventArgs($entity, $em); $this->contactListener->prePersist($args); $this->assertSame($createdAt, $entity->getCreatedAt()); $this->assertSame($createdBy, $entity->getCreatedBy()); }
/** * @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; }