Created
March 15, 2018 13:29
-
-
Save evgeniy1204/712bb1ec12576398a4fef8c162dfffd6 to your computer and use it in GitHub Desktop.
booking
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace AppBundle\DataFixtures\ORM; | |
use AppBundle\Entity\Ride; | |
use AppBundle\Service\BookingChargeChargerService; | |
use Doctrine\Common\DataFixtures\AbstractFixture; | |
use Doctrine\Common\DataFixtures\OrderedFixtureInterface; | |
use Doctrine\Common\Persistence\ObjectManager; | |
use Symfony\Component\DependencyInjection\ContainerAwareInterface; | |
use Symfony\Component\DependencyInjection\ContainerInterface; | |
use Symfony\Component\Form\Form; | |
use UserBundle\Entity\User; | |
class Fixtures40Bookings extends AbstractFixture implements OrderedFixtureInterface, ContainerAwareInterface | |
{ | |
/** | |
* @var ContainerInterface | |
*/ | |
private $container; | |
/** | |
* {@inheritDoc} | |
*/ | |
public function setContainer(ContainerInterface $container = null) | |
{ | |
$this->container = $container; | |
} | |
/** | |
* Load data fixtures with the passed EntityManager | |
* | |
* @param \Doctrine\Common\Persistence\ObjectManager $manager | |
*/ | |
function load(ObjectManager $manager) | |
{ | |
$bookingFakeCreator = $this->container->get('booking.fake.creator'); | |
/************************************************************************************************************** | |
* BOOKINGS FOR RIDE MR-0000 | |
*************************************************************************************************************/ | |
/** @var Ride $ride */ | |
$ride = $this->getReference("ride-MR-0000"); | |
$bookingFakeCreator->createFakeBooking( | |
array($ride->getMainRideSegmentBelongingToOutward()), | |
1, | |
[ | |
'user' => $this->getReference("admin"), | |
] | |
); | |
$bookingFakeCreator->createFakeBooking( | |
array($ride->getMainRideSegmentBelongingToOutward(), $ride->getMainRideSegmentBelongingToReturn()), | |
2, | |
[ | |
'user' => $this->getReference("admin"), | |
] | |
); | |
/************************************************************************************************************** | |
* BOOKINGS FOR RIDE CH-0001 | |
*************************************************************************************************************/ | |
/** @var Ride $ride */ | |
$ride = $this->getReference("ride-CH-0001"); | |
// confirm | |
$this->container->get('ride.confirmer')->confirmRide($ride); | |
$bookingFakeCreator->createFakeBooking( | |
array($ride->getMainRideSegmentBelongingToOutward(), $ride->getMainRideSegmentBelongingToReturn()), | |
2, | |
[ | |
'user' => $this->getReference("admin"), | |
'booking_optionals' => [ | |
$this->getReference('booking_optional_SKIPASS'), | |
$this->getReference('booking_optional_SKI_LESSON'), | |
$this->getReference('booking_optional_AXA'), | |
], | |
] | |
); | |
/* | |
* process BookingCharges | |
* | |
* @todo this code is duplicated of AdminBundle\Command\ContinuousCommand: refactor ContinuousCommand code in a service and call the service from here | |
*/ | |
/** @var BookingChargeChargerService */ | |
$bookingChargeCharger = $this->container->get('booking_charge.charger'); | |
$bookingChargesIds = $manager->getRepository('AppBundle:BookingCharge')->findChargeable(true); | |
foreach ($bookingChargesIds as $bookingChargeId) { | |
$bookingCharge = $manager->getRepository('AppBundle:BookingCharge')->find($bookingChargeId); | |
$bookingChargeCharger->chargeBookingChargeOrThrowBookingException($bookingCharge); | |
} | |
/** end process BookingCharges */ | |
/************************************************************************************************************** | |
* flush | |
*************************************************************************************************************/ | |
$manager->flush(); | |
} | |
/** | |
* {@inheritDoc} | |
*/ | |
public function getOrder() | |
{ | |
return 40; // the order in which fixtures will be loaded | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment