Skip to content

Instantly share code, notes, and snippets.

@evgeniy1204
Created March 15, 2018 13:28
Show Gist options
  • Save evgeniy1204/c5457542024dbb267df57c88f15cb197 to your computer and use it in GitHub Desktop.
Save evgeniy1204/c5457542024dbb267df57c88f15cb197 to your computer and use it in GitHub Desktop.
booking
<?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