Advertisement
Guest User

Migrations/Data/ORM/LoadCalendarEventTypeData.php

a guest
Jun 27th, 2015
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.09 KB | None | 0 0
  1. <?php
  2.  
  3. namespace BP\CalendarBundle\Migrations\Data\ORM;
  4.  
  5. use Doctrine\Common\DataFixtures\AbstractFixture;
  6. use Doctrine\Common\Persistence\ObjectManager;
  7.  
  8. use Oro\Bundle\EntityExtendBundle\Entity\Repository\EnumValueRepository;
  9. use Oro\Bundle\EntityExtendBundle\Tools\ExtendHelper;
  10.  
  11. class LoadCalendarEventTypeData extends AbstractFixture
  12. {
  13.     /** @var array */
  14.     protected $data = [
  15.         'Spotkanie' => true,
  16.         'Rozmowa telefoniczna' => false,
  17.         'Inne' => false,
  18.         'Czas prywatny' => false,
  19.     ];
  20.  
  21.     /**
  22.      * @param ObjectManager $manager
  23.      */
  24.     public function load(ObjectManager $manager)
  25.     {
  26.         $className = ExtendHelper::buildEnumValueClassName('calendar_event_type');
  27.  
  28.         /** @var EnumValueRepository $enumRepo */
  29.         $enumRepo = $manager->getRepository($className);
  30.  
  31.         $priority = 1;
  32.         foreach ($this->data as $name => $isDefault) {
  33.             $enumOption = $enumRepo->createEnumValue($name, $priority++, $isDefault);
  34.             $manager->persist($enumOption);
  35.         }
  36.  
  37.         $manager->flush();
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement