예제 #1
0
 /**
  * Get the minor faction code
  * @param Card $agenda
  * @return string
  */
 public function getMinorFactionCode(Card $agenda)
 {
     if (empty($agenda)) {
         return null;
     }
     // special case for the Core Set Banners
     $banners_core_set = ['01198' => 'baratheon', '01199' => 'greyjoy', '01200' => 'lannister', '01201' => 'martell', '01202' => 'nightswatch', '01203' => 'stark', '01204' => 'targaryen', '01205' => 'tyrell'];
     if (isset($banners_core_set[$agenda->getCode()])) {
         return $banners_core_set[$agenda->getCode()];
     }
     return null;
 }
예제 #2
0
 /**
  * Load data fixtures with the passed EntityManager
  *
  * @param ObjectManager $manager
  */
 public function load(ObjectManager $manager)
 {
     $cardAbilityData = new CardAbilityData();
     foreach ($cardAbilityData->getAbilities() as $ability) {
         if ($ability['name']) {
             $newAbility = new Ability();
             $newAbility->setName($ability['name']);
             $newAbility->setDescription($ability['description']);
             foreach ($ability['cards'] as $card) {
                 $newCard = new Card();
                 $newCard->setName($card['name']);
                 $newCard->setPower($card['power']);
                 $newCard->setTempPower($card['power']);
                 $newCard->setIsUnique($card['isUnique']);
                 $newCard->setAttackType($card['attackType']);
                 $newCard->setAbility($newAbility);
                 $manager->persist($newCard);
                 $newAbility->addCard($newCard);
             }
         } else {
             foreach ($ability['cards'] as $card) {
                 $newCard = new Card();
                 $newCard->setName($card['name']);
                 $newCard->setPower($card['power']);
                 $newCard->setTempPower($card['power']);
                 $newCard->setIsUnique($card['isUnique']);
                 $newCard->setAttackType($card['attackType']);
                 $manager->persist($newCard);
             }
         }
     }
     $manager->flush();
 }
예제 #3
0
 public function validateKings(\AppBundle\Model\SlotCollectionInterface $slots, \AppBundle\Entity\Card $agenda)
 {
     $trait = $this->translator->trans('card.traits.' . ($agenda->getCode() === '04037' ? 'winter' : 'summer'));
     $matchingTraitPlots = $slots->getPlotDeck()->filterByTrait($trait)->countCards();
     if ($matchingTraitPlots > 0) {
         return false;
     }
     return true;
 }
예제 #4
0
 /**
  *
  * @param \AppBundle\Entity\Card $card
  * @param string $api
  * @return multitype:multitype: string number mixed NULL unknown
  */
 public function getCardInfo($card, $api = false)
 {
     $cardinfo = [];
     $metadata = $this->doctrine->getManager()->getClassMetadata('AppBundle:Card');
     $fieldNames = $metadata->getFieldNames();
     $associationMappings = $metadata->getAssociationMappings();
     foreach ($associationMappings as $fieldName => $associationMapping) {
         if ($associationMapping['isOwningSide']) {
             $getter = str_replace(' ', '', ucwords(str_replace('_', ' ', "get_{$fieldName}")));
             $associationEntity = $card->{$getter}();
             if (!$associationEntity) {
                 continue;
             }
             $cardinfo[$fieldName . '_code'] = $associationEntity->getCode();
             $cardinfo[$fieldName . '_name'] = $associationEntity->getName();
         }
     }
     foreach ($fieldNames as $fieldName) {
         $getter = str_replace(' ', '', ucwords(str_replace('_', ' ', "get_{$fieldName}")));
         $value = $card->{$getter}();
         switch ($metadata->getTypeOfField($fieldName)) {
             case 'datetime':
             case 'date':
                 continue 2;
                 break;
             case 'boolean':
                 $value = (bool) $value;
                 break;
         }
         $fieldName = ltrim(strtolower(preg_replace('/[A-Z]/', '_$0', $fieldName)), '_');
         $cardinfo[$fieldName] = $value;
     }
     $cardinfo['url'] = $this->router->generate('cards_zoom', array('card_code' => $card->getCode()), true);
     $imageurl = $this->assets_helper->getUrl('bundles/cards/' . $card->getCode() . '.png');
     $imagepath = $this->rootDir . '/../web' . preg_replace('/\\?.*/', '', $imageurl);
     if (file_exists($imagepath)) {
         $cardinfo['imagesrc'] = $imageurl;
     } else {
         $cardinfo['imagesrc'] = null;
     }
     if ($api) {
         unset($cardinfo['id']);
         $cardinfo = array_filter($cardinfo, function ($var) {
             return isset($var);
         });
     } else {
         $cardinfo['text'] = $this->replaceSymbols($cardinfo['text']);
         $cardinfo['text'] = implode(array_map(function ($l) {
             return "<p>{$l}</p>";
         }, preg_split('/[\\r\\n]+/', $cardinfo['text'])));
         $cardinfo['flavor'] = $this->replaceSymbols($cardinfo['flavor']);
     }
     return $cardinfo;
 }
 public function uploadProcessAction(Request $request)
 {
     /* @var $uploadedFile \Symfony\Component\HttpFoundation\File\UploadedFile */
     $uploadedFile = $request->files->get('upfile');
     $inputFileName = $uploadedFile->getPathname();
     $inputFileType = \PHPExcel_IOFactory::identify($inputFileName);
     $objReader = \PHPExcel_IOFactory::createReader($inputFileType);
     $objReader->setReadDataOnly(true);
     $objPHPExcel = $objReader->load($inputFileName);
     $objWorksheet = $objPHPExcel->getActiveSheet();
     $enableCardCreation = $request->request->has('create');
     // analysis of first row
     $colNames = [];
     $cards = [];
     $firstRow = true;
     foreach ($objWorksheet->getRowIterator() as $row) {
         // dismiss first row (titles)
         if ($firstRow) {
             $firstRow = false;
             // analysis of first row
             foreach ($row->getCellIterator() as $cell) {
                 $colNames[$cell->getColumn()] = $cell->getValue();
             }
             continue;
         }
         $card = [];
         $cellIterator = $row->getCellIterator();
         foreach ($cellIterator as $cell) {
             $col = $cell->getColumn();
             $colName = $colNames[$col];
             //$setter = str_replace(' ', '', ucwords(str_replace('_', ' ', "set_$fieldName")));
             $card[$colName] = $cell->getValue();
         }
         if (count($card) && !empty($card['code'])) {
             $cards[] = $card;
         }
     }
     /* @var $em \Doctrine\ORM\EntityManager */
     $em = $this->get('doctrine')->getManager();
     $repo = $em->getRepository('AppBundle:Card');
     $metaData = $em->getClassMetadata('AppBundle:Card');
     $fieldNames = $metaData->getFieldNames();
     $associationMappings = $metaData->getAssociationMappings();
     $counter = 0;
     foreach ($cards as $card) {
         /* @var $entity \AppBundle\Entity\Card */
         $entity = $repo->findOneBy(array('code' => $card['code']));
         if (!$entity) {
             if ($enableCardCreation) {
                 $entity = new Card();
                 $now = new \DateTime();
                 $entity->setDateCreation($now);
                 $entity->setDateUpdate($now);
             } else {
                 continue;
             }
         }
         $changed = FALSE;
         $output = ["<h4>" . $card['name'] . "</h4>"];
         foreach ($card as $colName => $value) {
             $getter = str_replace(' ', '', ucwords(str_replace('_', ' ', "get_{$colName}")));
             $setter = str_replace(' ', '', ucwords(str_replace('_', ' ', "set_{$colName}")));
             if (key_exists($colName, $associationMappings)) {
                 $associationMapping = $associationMappings[$colName];
                 $associationRepository = $em->getRepository($associationMapping['targetEntity']);
                 $associationEntity = $associationRepository->findOneBy(['name' => $value]);
                 if (!$associationEntity) {
                     throw new \Exception("cannot find entity [{$colName}] of name [{$value}]");
                 }
                 if (!$entity->{$getter}() || $entity->{$getter}()->getId() !== $associationEntity->getId()) {
                     $changed = TRUE;
                     $output[] = "<p>association [{$colName}] changed</p>";
                     $entity->{$setter}($associationEntity);
                 }
             } else {
                 if (in_array($colName, $fieldNames)) {
                     $type = $metaData->getTypeOfField($colName);
                     if ($type === 'boolean') {
                         $value = (bool) $value;
                     }
                     if ($entity->{$getter}() != $value || $entity->{$getter}() === NULL && $entity->{$getter}() !== $value) {
                         $changed = TRUE;
                         $output[] = "<p>field [{$colName}] changed</p>";
                         $entity->{$setter}($value);
                     }
                 }
             }
         }
         if ($changed) {
             $em->persist($entity);
             $counter++;
             echo join("", $output);
         }
     }
     $em->flush();
     return new Response($counter . " cards changed or added");
 }
예제 #6
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /* @var $em \Doctrine\ORM\EntityManager */
     $em = $this->getContainer()->get('doctrine')->getManager();
     /* @var $helper \Symfony\Component\Console\Helper\QuestionHelper */
     $helper = $this->getHelper('question');
     $assets_helper = $this->getContainer()->get('templating.helper.assets');
     $rootDir = $this->getContainer()->get('kernel')->getRootDir();
     /* @var $allFactions \AppBundle\Entity\Faction[] */
     $allFactions = $em->getRepository('AppBundle:Faction')->findAll();
     /* @var $allTypes \AppBundle\Entity\Type[] */
     $allTypes = $em->getRepository('AppBundle:Type')->findAll();
     $filename = $input->getArgument('filename');
     $assumeYes = $input->getOption('yes');
     $fileUrl = "http://www.cardgamedb.com/deckbuilders/gameofthrones2ndedition/database/{$filename}.jgz";
     $output->writeln("Trying to download the file...");
     $file = file_get_contents($fileUrl);
     if (!preg_match('/^cards = (.*);$/', $file, $matches)) {
         $output->writeln("<error>Error while parsing js file</error>");
         return;
     }
     $output->writeln("File successfully downloaded");
     $json = $matches[1];
     $lookup = json_decode($json, TRUE);
     $output->writeln(count($lookup) . " cards found in file");
     foreach ($lookup as $data) {
         $name = $data['name'];
         $name = str_replace(['“', '”', '’'], ['"', '"', '\''], $name);
         $traits = $data['traits'];
         $traits = str_replace(['“', '”', '’'], ['"', '"', '\''], $traits);
         $setname = html_entity_decode($data['setname'], ENT_QUOTES);
         $setname = str_replace(['“', '”', '’'], ['"', '"', '\''], $setname);
         /* @var $pack \AppBundle\Entity\Pack */
         $pack = $em->getRepository('AppBundle:Pack')->findOneBy(array('name' => $setname));
         if (!$pack) {
             $output->writeln("<error>Cannot find pack [" . $setname . "]</error>");
             die;
         }
         if ($pack->getSize() === count($pack->getCards())) {
             // shortcut: we already know all the cards of this pack
             continue;
         }
         /* @var $card \AppBundle\Entity\Card */
         $card = $em->getRepository('AppBundle:Card')->findOneBy(array('name' => $name, 'pack' => $pack));
         if ($card && $card->getOctgnId()) {
             continue;
         }
         if (!$assumeYes) {
             $question = new ConfirmationQuestion("Shall I import the card <comment>{$name}</comment> from the set <comment>{$setname}</comment>? (Y/n) ", true);
             if (!$helper->ask($input, $output, $question)) {
                 continue;
             }
         }
         $faction = null;
         foreach ($allFactions as $oneFaction) {
             if ($data[$oneFaction->getCode()] === 'Y') {
                 $faction = $oneFaction;
             }
         }
         if (!$faction) {
             $output->writeln("<error>Cannot find faction for this card</error>");
             dump($data);
             die;
         }
         $type = null;
         foreach ($allTypes as $oneType) {
             if ($data['type'] === $oneType->getName()) {
                 $type = $oneType;
             }
         }
         if (!$type) {
             $output->writeln("<error>Cannot find type for this card</error>");
             dump($data);
             die;
         }
         $position = intval($data['num']);
         $text = $data['text'];
         $text = str_replace(['“', '”', '’', '&rsquo;'], ['"', '"', '\'', '\''], $text);
         $text = str_replace(['<br />'], ["\n"], $text);
         $text = preg_replace("/<strong class='bbc'>([^<]+)<\\/strong>/", "<b>\\1</b>", $text);
         $text = str_replace("</b>: ", ":</b> ", $text);
         $text = preg_replace("/<em class='bbc'><b>([^<]+)<\\/b><\\/em>/", "<i>\\1</i>", $text);
         $text = preg_replace("/<em class='bbc'>([^<]+)<\\/em>/", "", $text);
         $text = preg_replace_callback("/\\[(.*?)\\]/", function ($matches) use($allFactions) {
             $token = str_replace(['“', '”', '’', '&rsquo;'], ['"', '"', '\'', '\''], $matches[1]);
             foreach ($allFactions as $faction) {
                 if ($faction->getName() === $token || $faction->getName() === "The Night's Watch" && $token === "Night's Watch") {
                     return '[' . $faction->getCode() . ']';
                 }
             }
             return '[' . strtolower($token) . ']';
         }, $text);
         $text = preg_replace("/Plot deck limit: \\d./", "", $text);
         $text = preg_replace("/Deck Limit: \\d./", "", $text);
         $text = preg_replace("/ +/", " ", $text);
         $text = preg_replace("/\n+/", "\n", $text);
         $text = trim($text);
         if (!$card) {
             $card = new Card();
         }
         $card->setClaim($data['claim'] !== '' ? $data['claim'] : null);
         $card->setCode(sprintf("%02d%03d", $pack->getCycle()->getPosition(), $position));
         $card->setCost($data['cost'] !== '' && $data['cost'] !== 'X' ? $data['cost'] : null);
         $card->setDeckLimit($data['max']);
         $card->setFaction($faction);
         $card->setIllustrator(trim($data['illustrator']));
         $card->setIncome($data['gold'] !== '' ? $data['gold'] : null);
         $card->setInitiative($data['initiative'] !== '' ? $data['initiative'] : null);
         $card->setIsIntrigue($data['intrigue'] === 'Y');
         $card->setIsLoyal($data['loyal'] === 'L');
         $card->setIsMilitary($data['military'] === 'Y');
         $card->setIsPower($data['power'] === 'Y');
         $card->setIsUnique($data['unique'] === 'Y');
         $card->setName($name);
         $card->setPack($pack);
         $card->setPosition($position);
         $card->setQuantity(3);
         // it looks like $data['quantity'] is wrong
         $card->setReserve($data['reserve'] !== '' ? $data['reserve'] : null);
         $card->setStrength($data['strength'] !== '' ? $data['strength'] : null);
         $card->setText($text);
         $card->setTraits($traits);
         $card->setType($type);
         $em->persist($card);
         // trying to download image file
         $card_code = $card->getCode();
         $imageurl = $assets_helper->getUrl('bundles/cards/' . $card->getCode() . '.png');
         $imagepath = $rootDir . '/../web' . preg_replace('/\\?.*/', '', $imageurl);
         $dirname = dirname($imagepath);
         $outputfile = $dirname . DIRECTORY_SEPARATOR . $card->getCode() . ".jpg";
         $cgdburl = "http://lcg-cdn.fantasyflightgames.com/got2nd/" . $data['img'];
         $image = file_get_contents($cgdburl);
         file_put_contents($outputfile, $image);
         $output->writeln("Added card " . $card->getName());
     }
     $em->flush();
     $output->writeln("Done.");
 }
예제 #7
0
 /**
  *
  * @param \AppBundle\Entity\Card $card
  * @param string $api
  * @return multitype:multitype: string number mixed NULL unknown
  */
 public function getCardInfo($card, $api = false)
 {
     $cardinfo = [];
     $metadata = $this->doctrine->getManager()->getClassMetadata('AppBundle:Card');
     $fieldNames = $metadata->getFieldNames();
     $associationMappings = $metadata->getAssociationMappings();
     foreach ($associationMappings as $fieldName => $associationMapping) {
         if ($associationMapping['isOwningSide']) {
             $getter = str_replace(' ', '', ucwords(str_replace('_', ' ', "get_{$fieldName}")));
             $associationEntity = $card->{$getter}();
             if (!$associationEntity) {
                 continue;
             }
             $cardinfo[$fieldName . '_code'] = $associationEntity->getCode();
             $cardinfo[$fieldName . '_name'] = $associationEntity->getName();
         }
     }
     foreach ($fieldNames as $fieldName) {
         $getter = str_replace(' ', '', ucwords(str_replace('_', ' ', "get_{$fieldName}")));
         $value = $card->{$getter}();
         switch ($metadata->getTypeOfField($fieldName)) {
             case 'datetime':
             case 'date':
                 continue 2;
                 break;
             case 'boolean':
                 $value = (bool) $value;
                 break;
         }
         $fieldName = ltrim(strtolower(preg_replace('/[A-Z]/', '_$0', $fieldName)), '_');
         $cardinfo[$fieldName] = $value;
     }
     $cardinfo['url'] = $this->router->generate('cards_zoom', array('card_code' => $card->getCode()), UrlGeneratorInterface::ABSOLUTE_URL);
     $imageurl = $this->assets_helper->getUrl('bundles/cards/' . $card->getCode() . '.png');
     $imagepath = $this->rootDir . '/../web' . preg_replace('/\\?.*/', '', $imageurl);
     if (file_exists($imagepath)) {
         $cardinfo['imagesrc'] = $imageurl;
     } else {
         $cardinfo['imagesrc'] = null;
     }
     // look for another card with the same name to set the label
     $homonyms = $this->doctrine->getRepository('AppBundle:Card')->findBy(['name' => $card->getName()]);
     if (count($homonyms) > 1) {
         $cardinfo['label'] = $card->getName() . ' (' . $card->getPack()->getCode() . ')';
     } else {
         $cardinfo['label'] = $card->getName();
     }
     if ($api) {
         unset($cardinfo['id']);
         $cardinfo['ci'] = $card->getCostIncome();
         $cardinfo['si'] = $card->getStrengthInitiative();
     } else {
         $cardinfo['text'] = $this->replaceSymbols($cardinfo['text']);
         $cardinfo['text'] = $this->addAbbrTags($cardinfo['text']);
         $cardinfo['text'] = $this->splitInParagraphs($cardinfo['text']);
         $cardinfo['flavor'] = $this->replaceSymbols($cardinfo['flavor']);
     }
     return $cardinfo;
 }
예제 #8
0
 /**
  * @Route("/card/generate", name="generate_cards")
  */
 public function generateCardsAction(Request $request)
 {
     if (!$this->getRequest()->isXmlHttpRequest()) {
         throw $this->createNotFoundException();
     }
     $em = $this->getDoctrine()->getManager();
     /**/
     $entity = new Card();
     $form = $this->createForm(new CardGenerate(), $entity);
     $form->handleRequest($request);
     $expiryPeriod = $form->get("expiryPeriod")->getData();
     $series = $form->get("series")->getData();
     $amount = $form->get("amount")->getData();
     if ($amount && $series && $expiryPeriod) {
         list($currentNumber, $series) = $this->getMaxNumberOfSeries($series);
         for ($i = 0; $i < $amount; $i++) {
             $newCard = new Card();
             $newCard->setSeries($series);
             $newCard->setNumber(str_pad(++$currentNumber, 8, "0", STR_PAD_LEFT));
             $newCard->setIssueDate(new \DateTime());
             $expiryDate = new \DateTime();
             $newCard->setExpiryDate($expiryDate->modify('+' . $expiryPeriod . ' months'));
             $newCard->setAmount(0);
             $newCard->setStatus(Card::STATUS_INACTIVE);
             $em->persist($newCard);
         }
         $em->flush();
         $cards = $em->getRepository('AppBundle:Card')->findAll();
         $view = $this->renderView('card/partial/card_list.html.twig', array('cards' => $cards));
         $response = new Response($view);
         return $response;
     } else {
         return;
     }
 }