Guest User

Untitled

a guest
Mar 24th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.04 KB | None | 0 0
  1. <?php
  2.  
  3. namespace AppBundle\DataFixtures\ORM;
  4.  
  5. use AppBundle\Entity\Ride;
  6. use AppBundle\Service\BookingChargeChargerService;
  7. use Doctrine\Common\DataFixtures\AbstractFixture;
  8. use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
  9. use Doctrine\Common\Persistence\ObjectManager;
  10. use Symfony\Component\DependencyInjection\ContainerAwareInterface;
  11. use Symfony\Component\DependencyInjection\ContainerInterface;
  12. use Symfony\Component\Form\Form;
  13. use UserBundle\Entity\User;
  14.  
  15. class Fixtures40Bookings extends AbstractFixture implements OrderedFixtureInterface, ContainerAwareInterface
  16. {
  17. /**
  18. * @var ContainerInterface
  19. */
  20. private $container;
  21.  
  22. /**
  23. * {@inheritDoc}
  24. */
  25. public function setContainer(ContainerInterface $container = null)
  26. {
  27. $this->container = $container;
  28. }
  29.  
  30. /**
  31. * Load data fixtures with the passed EntityManager
  32. *
  33. * @param \Doctrine\Common\Persistence\ObjectManager $manager
  34. */
  35. function load(ObjectManager $manager)
  36. {
  37. $bookingFakeCreator = $this->container->get('booking.fake.creator');
  38.  
  39. /**************************************************************************************************************
  40. * BOOKINGS FOR RIDE MR-0000
  41. *************************************************************************************************************/
  42.  
  43. /** @var Ride $ride */
  44. $ride = $this->getReference("ride-MR-0000");
  45.  
  46. $bookingFakeCreator->createFakeBooking(
  47. array($ride->getMainRideSegmentBelongingToOutward()),
  48. 1,
  49. [
  50. 'user' => $this->getReference("admin"),
  51. ]
  52. );
  53.  
  54. $bookingFakeCreator->createFakeBooking(
  55. array($ride->getMainRideSegmentBelongingToOutward(), $ride->getMainRideSegmentBelongingToReturn()),
  56. 2,
  57. [
  58. 'user' => $this->getReference("admin"),
  59. ]
  60. );
  61.  
  62. /**************************************************************************************************************
  63. * BOOKINGS FOR RIDE CH-0001
  64. *************************************************************************************************************/
  65.  
  66. /** @var Ride $ride */
  67. $ride = $this->getReference("ride-CH-0001");
  68.  
  69. // confirm
  70. $this->container->get('ride.confirmer')->confirmRide($ride);
  71.  
  72. $bookingFakeCreator->createFakeBooking(
  73. array($ride->getMainRideSegmentBelongingToOutward(), $ride->getMainRideSegmentBelongingToReturn()),
  74. 2,
  75. [
  76. 'user' => $this->getReference("admin"),
  77. 'booking_optionals' => [
  78. $this->getReference('booking_optional_SKIPASS'),
  79. $this->getReference('booking_optional_SKI_LESSON'),
  80. $this->getReference('booking_optional_AXA'),
  81. ],
  82. ]
  83. );
  84.  
  85. /*
  86. * process BookingCharges
  87. *
  88. * @todo this code is duplicated of AdminBundle\Command\ContinuousCommand: refactor ContinuousCommand code in a service and call the service from here
  89. */
  90. /** @var BookingChargeChargerService */
  91. $bookingChargeCharger = $this->container->get('booking_charge.charger');
  92.  
  93. $bookingChargesIds = $manager->getRepository('AppBundle:BookingCharge')->findChargeable(true);
  94. foreach ($bookingChargesIds as $bookingChargeId) {
  95. $bookingCharge = $manager->getRepository('AppBundle:BookingCharge')->find($bookingChargeId);
  96. $bookingChargeCharger->chargeBookingChargeOrThrowBookingException($bookingCharge);
  97. }
  98. /** end process BookingCharges */
  99.  
  100. /**************************************************************************************************************
  101. * flush
  102. *************************************************************************************************************/
  103. $manager->flush();
  104. }
  105.  
  106. /**
  107. * {@inheritDoc}
  108. */
  109. public function getOrder()
  110. {
  111. return 40; // the order in which fixtures will be loaded
  112. }
  113. }
Add Comment
Please, Sign In to add comment