diff --git a/Form/DataTransformer/PersonToIdTransformer.php b/Form/DataTransformer/PersonToIdTransformer.php new file mode 100644 index 000000000..102c2b690 --- /dev/null +++ b/Form/DataTransformer/PersonToIdTransformer.php @@ -0,0 +1,70 @@ +om = $om; + } + + /** + * Transforms an object (issue) to a string (id). + * + * @param Issue|null $issue + * @return string + */ + public function transform($issue) + { + if (null === $issue) { + return ""; + } + + return $issue->getId(); + } + + /** + * Transforms a string (id) to an object (issue). + * + * @param string $id + * + * @return Issue|null + * + * @throws TransformationFailedException if object (issue) is not found. + */ + public function reverseTransform($id) + { + if (!$id) { + return null; + } + + $issue = $this->om + ->getRepository('CLChillPersonBundle:Person') + ->findOneBy(array('id' => $id)) + ; + + if (null === $issue) { + throw new TransformationFailedException(sprintf( + 'An issue with id "%s" does not exist!', + $id + )); + } + + return $issue; + } +} +?> \ No newline at end of file