Skip to content

Instantly share code, notes, and snippets.

@mmenozzi
Created January 28, 2013 16:26
Show Gist options
  • Save mmenozzi/4656956 to your computer and use it in GitHub Desktop.
Save mmenozzi/4656956 to your computer and use it in GitHub Desktop.
/**
* Recupera la entity da utilizzare per memorizzare l'intervista
*
* @param $interviewId
* @param \Doctrine\Common\Persistence\ObjectManager $em
* @return object
*/
public function findEntity($interviewId, ObjectManager $em)
{
$repositoryMap = array(
'Application' => 'CharlieRecruitmentBundle:Application',
'AdditionalInformation' => 'CharlieUserBundle:AdditionalInformation',
);
if (count(explode('-', $interviewId)) == 2) {
list($entity, $entityId) = explode('-', $interviewId);
}
elseif (is_numeric($interviewId)) {
$entity = 'Application';
$entityId = $interviewId;
}
else {
throw new \InvalidArgumentException(
sprintf(
'Invalid inverview id %s.',
$interviewId
)
);
}
return $em->getRepository($repositoryMap[$entity])
->find($entityId);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment