private function loadShips(ObjectManager $manager, array $ships)
 {
     foreach ($ships as $data) {
         $ship = new Ship();
         $ship->fromArray($data);
         $manager->persist($ship);
         $metadata = $manager->getClassMetaData(get_class($ship));
         $metadata->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_NONE);
         $manager->flush();
         $this->ships[$ship->getId()] = $ship;
     }
 }
 private function loadShips(ObjectManager $manager, Faction $faction)
 {
     for ($i = 0; $i < 1000; ++$i) {
         $ship = new Ship();
         $ship->setId(9 + $i);
         $ship->setName('Fake ship ' . $i);
         $faction->addShip($ship);
         $manager->persist($faction);
         $manager->persist($ship);
         $metadata = $manager->getClassMetaData(get_class($ship));
         $metadata->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_NONE);
         $manager->flush();
     }
 }
Example #3
0
 public function __construct($vertical = false)
 {
     //dirty hack to avoid placing this logic in the right place
     //i.e. on a Grid properties aware service (X and Y size)
     $size = 5;
     parent::__construct($size, $vertical);
 }
 public function createShip($shipName, $factionId)
 {
     $em = $this->container->get('doctrine.orm.default_entity_manager');
     $faction = $em->find('AppBundle:Faction', $factionId);
     if (!$faction instanceof Faction) {
         throw new UserError(sprintf('Unknown faction with id "%d"', $factionId));
     }
     $ship = new Ship();
     $ship->setName($shipName);
     $ship->addFaction($faction);
     $em->persist($ship);
     $em->persist($faction);
     try {
         $em->flush();
     } catch (\Exception $e) {
         throw new UserError(sprintf('Could not save ship with name "%s". Retry later', $shipName));
     }
     return ['ship' => $ship, 'faction' => $faction];
 }
 public function ShipAddAction(Request $request)
 {
     $Ship = new Ship();
     $Ship->setShip1($request->get('Ship1'));
     $Ship->setShip2($request->get('Ship2'));
     $Ship->setShip3($request->get('Ship3'));
     $Ship->setShip4($request->get('Ship4'));
     $Ship->setShip5($request->get('Ship5'));
     $Ship->setShip6($request->get('Ship6'));
     $Ship->setShip7($request->get('Ship7'));
     $Ship->setShip8($request->get('Ship8'));
     $Ship->setShip9($request->get('Ship9'));
     $Ship->setShip10($request->get('Ship10'));
     $em = $this->getDoctrine()->getEntityManager();
     $em->persist($Ship);
     $em->flush($Ship);
     return $this->redirectToRoute('Default_Ship');
 }
Example #6
0
 public function __construct($vertical = false)
 {
     parent::__construct(4, $vertical);
 }