Ejemplo n.º 1
0
 /**
  * Decoupe un deckcontent pour son affichage par type
  *
  * @param \Netrunnerdb\CardsBundle\Entity\Card $identity
  */
 public function classe($cards, $identity)
 {
     $analyse = $this->analyse($cards);
     $classeur = array();
     /* @var $slot \Netrunnerdb\BuilderBundle\Entity\Deckslot */
     foreach ($cards as $elt) {
         /* @var $card \Netrunnerdb\CardsBundle\Entity\Card */
         $card = $elt['card'];
         $qty = $elt['qty'];
         $type = $card->getType()->getName();
         if ($type == "Identity") {
             continue;
         }
         if ($type == "ICE") {
             $keywords = explode(" - ", $card->getKeywords());
             if (in_array("Barrier", $keywords)) {
                 $type = "Barrier";
             }
             if (in_array("Code Gate", $keywords)) {
                 $type = "Code Gate";
             }
             if (in_array("Sentry", $keywords)) {
                 $type = "Sentry";
             }
         }
         if ($type == "Program") {
             $keywords = explode(" - ", $card->getKeywords());
             if (in_array("Icebreaker", $keywords)) {
                 $type = "Icebreaker";
             }
         }
         $influence = 0;
         $qty_influence = $qty;
         if ($identity->getCode() == "03029" && $card->getType()->getName() == "Program") {
             $qty_influence--;
         }
         if ($card->getFaction()->getId() != $identity->getFaction()->getId()) {
             $influence = $card->getFactionCost() * $qty_influence;
         }
         $elt['influence'] = $influence;
         $elt['faction'] = str_replace(' ', '-', mb_strtolower($card->getFaction()->getName()));
         if (!isset($classeur[$type])) {
             $classeur[$type] = array("qty" => 0, "slots" => array());
         }
         $classeur[$type]["slots"][] = $elt;
         $classeur[$type]["qty"] += $qty;
     }
     if (is_string($analyse)) {
         $classeur['problem'] = $this->problem($analyse);
     } else {
         $classeur = array_merge($classeur, $analyse);
     }
     return $classeur;
 }
Ejemplo n.º 2
0
 public function confirmAction()
 {
     $cards = $this->get('session')->get('trad_upload_data');
     $locale = $this->get('session')->get('trad_upload_locale');
     /* @var $em \Doctrine\ORM\EntityManager */
     $em = $this->get('doctrine')->getManager();
     $repo = $em->getRepository('Netrunnerdb\\CardsBundle\\Entity\\Card');
     $loc = $locale != "en" ? ucfirst($locale) : "";
     foreach ($cards as $i => $card) {
         /* @var $dbcard \Netrunnerdb\CardsBundle\Entity\Card */
         $dbcard = $repo->findOneBy(array('code' => $card['code']));
         if (!$dbcard) {
             $dbcard = new Card();
             $dbcard->setTs(new \DateTime());
         }
         $card['pack'] = $em->getRepository('NetrunnerdbCardsBundle:Pack')->findOneBy(array("name{$loc}" => $card['pack']));
         $card['type'] = $em->getRepository('NetrunnerdbCardsBundle:Type')->findOneBy(array("name{$loc}" => $card['type']));
         $card['side'] = $em->getRepository('NetrunnerdbCardsBundle:Side')->findOneBy(array("name{$loc}" => $card['side']));
         $card['faction'] = $em->getRepository('NetrunnerdbCardsBundle:Faction')->findOneBy(array("name{$loc}" => $card['faction']));
         foreach ($card as $key => $value) {
             $func = 'set' . ucfirst($key);
             $dbcard->{$func}($value, $locale);
         }
         $em->persist($dbcard);
     }
     $em->flush();
     return new Response('OK');
 }
Ejemplo n.º 3
0
 /**
  *
  * @param \Netrunnerdb\CardsBundle\Entity\Card $card
  * @param string $api
  * @return multitype:multitype: string number mixed NULL unknown
  */
 public function getCardInfo($card, $api = false)
 {
     static $cache = array();
     static $cacheApi = array();
     $locale = $this->request_stack->getCurrentRequest()->getLocale();
     if (!$api && isset($cache[$card->getId()]) && isset($cache[$card->getId()][$locale])) {
         return $cache[$card->getId()][$locale];
     }
     if ($api && isset($cacheApi[$card->getId()]) && isset($cacheApi[$card->getId()][$locale])) {
         return $cacheApi[$card->getId()][$locale];
     }
     $dbh = $this->doctrine->getConnection();
     $cardinfo = array("id" => $card->getId(), "last-modified" => $card->getTs()->format('c'), "code" => $card->getCode(), "title" => $card->getTitle($locale), "type" => $card->getType()->getName($locale), "type_code" => mb_strtolower($card->getType()->getName()), "subtype" => $card->getKeywords($locale), "subtype_code" => mb_strtolower($card->getKeywords()), "text" => $card->getText($locale), "advancementcost" => $card->getAdvancementCost(), "agendapoints" => $card->getAgendaPoints(), "baselink" => $card->getBaseLink(), "cost" => $card->getCost(), "faction" => $card->getFaction()->getName($locale), "faction_code" => $card->getFaction()->getCode(), "faction_letter" => $card->getFaction()->getCode() == 'neutral' ? '-' : substr($card->getFaction()->getCode(), 0, 1), "factioncost" => $card->getFactionCost(), "flavor" => $card->getFlavor($locale), "illustrator" => $card->getIllustrator(), "influencelimit" => $card->getInfluenceLimit(), "memoryunits" => $card->getMemoryUnits(), "minimumdecksize" => $card->getMinimumDeckSize(), "number" => $card->getNumber(), "quantity" => $card->getQuantity(), "id_set" => $card->getPack()->getId(), "setname" => $card->getPack()->getName($locale), "set_code" => $card->getPack()->getCode(), "side" => $card->getSide()->getName($locale), "side_code" => mb_strtolower($card->getSide()->getName()), "strength" => $card->getStrength(), "trash" => $card->getTrashCost(), "uniqueness" => $card->getUniqueness(), "limited" => $card->getLimited(), "cyclenumber" => $card->getPack()->getCycle()->getNumber());
     $cardinfo['url'] = $this->router->generate('netrunnerdb_netrunner_cards_zoom', array('card_code' => $card->getCode(), '_locale' => $locale), true);
     $cardinfo['imagesrc'] = "";
     $cardinfo['largeimagesrc'] = "";
     if ($locale != 'en' && file_exists($this->dir . DIRECTORY_SEPARATOR . $locale . DIRECTORY_SEPARATOR . $card->getCode() . ".png")) {
         $cardinfo['imagesrc'] = "/web/bundles/netrunnerdbcards/images/cards/{$locale}/" . $card->getCode() . ".png";
         if (file_exists($this->dir . DIRECTORY_SEPARATOR . "{$locale}-large" . DIRECTORY_SEPARATOR . $card->getCode() . ".png")) {
             $cardinfo['largeimagesrc'] = "/web/bundles/netrunnerdbcards/images/cards/{$locale}-large/" . $card->getCode() . ".png";
         }
     } else {
         if (file_exists($this->dir . DIRECTORY_SEPARATOR . "en" . DIRECTORY_SEPARATOR . $card->getCode() . ".png")) {
             $cardinfo['imagesrc'] = "/web/bundles/netrunnerdbcards/images/cards/en/" . $card->getCode() . ".png";
             if (file_exists($this->dir . DIRECTORY_SEPARATOR . "en-large" . DIRECTORY_SEPARATOR . $card->getCode() . ".png")) {
                 $cardinfo['largeimagesrc'] = "/web/bundles/netrunnerdbcards/images/cards/en-large/" . $card->getCode() . ".png";
             }
         }
     }
     if ($api) {
         unset($cardinfo['id']);
         unset($cardinfo['id_set']);
         $cardinfo = array_filter($cardinfo, function ($var) {
             return isset($var);
         });
         $cacheApi[$card->getId()][$locale] = $cardinfo;
     } else {
         $cardinfo['cssfaction'] = str_replace(" ", "-", mb_strtolower($card->getFaction()->getName()));
         $cache[$card->getId()][$locale] = $cardinfo;
     }
     return $cardinfo;
 }