Advertisement
ascott

DataTransformerConfigurationsFeaturesTransformer.php

Oct 16th, 2012
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.26 KB | None | 0 0
  1. <?php
  2. namespace Lynux\CoreBundle\Form\DataTransformer;
  3.  
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Persistence\ObjectManager;
  6. use Symfony\Component\Form\DataTransformerInterface;
  7. use Symfony\Component\Form\Exception\TransformationFailedException;
  8.  
  9. use Lynux\AssetBundle\Entity\Core\Codes;
  10. use Lynux\AssetBundle\Entity\Core\ConfigurationsFeatures;
  11.  
  12. class ConfigurationsFeaturesTransformer implements DataTransformerInterface
  13. {
  14.     private $objectManager;
  15.  
  16.     public function __construct(ObjectManager $objectManager)
  17.     {
  18.         $this->objectManager = $objectManager;
  19.     }
  20.  
  21.     // transform submitted ArrayCollection of Core\Codes
  22.     // into ArrayCollection of Core\ConfigurationsFeatures
  23.     public function transform(ArrayCollection $codes)
  24.     {
  25.         $features = new ArrayCollection();
  26.  
  27.         foreach($codes as $code) {
  28.             $feature = new ConfigurationsFeatures();
  29.             $feature->setFeatureFk($code);
  30.             $features->add($feature);
  31.         }
  32.  
  33.         return $features;
  34.     }
  35.  
  36.     // transform provided ArrayCollection of Core\ConfigurationsFeatures
  37.     // into array for form
  38.     public function reverseTransform(ArrayCollection $features)
  39.     {
  40.         return $features->toArray();
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement