Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Velvel\ZDFBundle\Form\DataTransformer;
- use Symfony\Component\Form\Exception\TransformationFailedException;
- use Symfony\Component\Form\Exception\UnexpectedTypeException;
- use Symfony\Component\Form\DataTransformerInterface;
- use Doctrine\Common\Persistence\ObjectManager;
- /**
- * Country to Distributed Video Country transformer
- */
- class CountryToDVCTransformer implements DataTransformerInterface
- {
- private $om;
- /**
- * Constructor
- *
- * @param \Doctrine\Common\Persistence\ObjectManager $om Entity Manager
- *
- * @author r1pp3rj4ck <attila.bukor@velvel.hu>
- */
- public function __construct(ObjectManager $om)
- {
- $this->om = $om;
- }
- /**
- * Transforms DVC to Country array
- *
- * @param array $value DVC array
- *
- * @author r1pp3rj4ck <attila.bukor@velvel.hu>
- * @return array
- */
- public function reverseTransform($value)
- {
- var_dump('reverseTransform value:');
- var_dump($value);
- if (!$value)
- {
- return array();
- }
- if (!is_array($value))
- {
- throw new UnexpectedTypeException($value, 'array');
- }
- $array = array();
- foreach ($value as $val)
- {
- $array[] = is_object($val) ? $val->getCountry() : $val;
- }
- var_dump('reverseTransform final:');
- var_dump($array);
- return $array;
- }
- /**
- * Transforms countries to DVC array
- *
- * @param array $value Country array
- *
- * @author r1pp3rj4ck <attila.bukor@velvel.hu>
- * @return array
- */
- public function transform($value)
- {
- var_dump('transform value:');
- var_dump($value);
- if (!$value)
- {
- return array();
- }
- if (!is_array($value))
- {
- throw new UnexpectedTypeException($value, 'array');
- }
- $array = new \Doctrine\Common\Collections\ArrayCollection();
- foreach ($value as $v)
- {
- $country = $this->om->find('VelvelZDFBundle:Country', $v);
- if (!$country)
- {
- throw new TransformationFailedException;
- }
- $a = new \Velvel\ZDFBundle\Entity\DisabledVideoCountry();
- $a->setCountry($country);
- $array[] = $a;
- }
- var_dump('transform final:');
- var_dump($array);
- // die();
- return $array;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement