コード例 #1
0
 }
 // Query the database
 $set_where = '';
 $card_tokens = array();
 if (($str = getTextSearchConditions($name, 'c.name')) !== '') {
     $card_tokens[] = $str;
 }
 if (($str = getTextSearchConditions($rulesText, 'c.rules_text')) !== '') {
     $card_tokens[] = $str;
 }
 if (($str = getTextSearchConditions($types, 'c.types')) !== '') {
     $card_tokens[] = $str;
 }
 if ($manaCost) {
     // TODO: check for invalid mana cost
     $card_tokens[] = 'c.mana_cost = "' . normalizeManaCost($manaCost) . '"';
 }
 if ($banned == 'y') {
     $card_tokens[] = 'c.is_banned = 1';
 } else {
     if ($banned == 'n') {
         $card_tokens[] = 'c.is_banned = 0';
     }
 }
 if ($pow !== '') {
     if ($powComparator === 'eq') {
         $card_tokens[] = 'c.power = "' . $pow . '"';
     } else {
         // TOOD: check for URL-hacked comparator
         $card_tokens[] = 'c.power_num ' . $COMPARATOR_TRANSLATIONS[$powComparator] . ' ' . $pow;
     }
コード例 #2
0
function createFromCockatriceFile($filename)
{
    global $db, $COLOR_TRANSLATIONS, $RARITY_TRANSLATIONS;
    $data = simplexml_load_file($filename);
    // build and insert a list of sets indexed by short name
    $sets = array();
    foreach ($data->sets->set as $set) {
        // TODO: error-checking of all kinds
        // Specifically, look at whether a set with the given shortname already exists
        $shortName = (string) $set->name;
        $sets[$shortName] = array('short_name' => $shortName, 'name' => (string) $set->longname, 'is_public' => true);
        $sql = 'INSERT INTO nga_card_sets ' . $db->sql_build_array('INSERT', $sets[$shortName]);
        echo 'Found set: ', (string) $set->longname, '<br>';
        $db->sql_query($sql);
        $sets[$shortName]['set_id'] = $db->sql_nextid();
    }
    // sets have been inserted
    // go through the list of cards, inserting each
    foreach ($data->cards->card as $card) {
        // compute some values we need
        $manacost = normalizeManaCost($card->manacost);
        $colors = array();
        foreach ($card->color as $color) {
            $colors[] = $COLOR_TRANSLATIONS[(string) $color];
        }
        $colorString = implode(',', $colors);
        $rulesText = cleanRulesTextForDB($card->text);
        $stats = getPowerAndToughness($card->pt);
        $loyalty = null;
        if ($card->loyalty != null) {
            $loyalty = (string) $card->loyalty;
        }
        // build a handy table from which the SQL statement will be built
        $card_ary = array('name' => (string) $card->name, 'mana_cost' => $manacost, 'cmc' => computeCMC($manacost), 'colors' => $colorString, 'types' => (string) $card->type, 'rules_text' => $rulesText, 'power' => $stats[0], 'toughness' => $stats[2], 'power_num' => $stats[1], 'toughness_num' => $stats[3], 'loyalty' => $loyalty);
        if (strpos((string) $card->text, '~Banned') !== false) {
            $card_ary['is_banned'] = 1;
        }
        $sql = 'INSERT INTO nga_cards ' . $db->sql_build_array('INSERT', $card_ary);
        echo 'Adding card ', (string) $card->name, '.';
        $db->sql_query($sql);
        $card_id = $db->sql_nextid();
        foreach ($card->set as $set) {
            $set_id = $sets[(string) $set]['set_id'];
            $printing_ary = array('card_id' => $card_id, 'set_id' => $set_id);
            $attr = $set->attributes();
            if (isset($attr['picURL'])) {
                $printing_ary['render_url'] = (string) $attr['picURL'];
            }
            if (isset($attr['rarity'])) {
                $elt = (string) $attr['rarity'];
                $printing_ary['rarity'] = $RARITY_TRANSLATIONS[$elt];
                echo '.. it is a "' . $elt . '" => ' . $printing_ary['rarity'];
            }
            $sql = 'INSERT INTO nga_card_printings ' . $db->sql_build_array('INSERT', $printing_ary);
            echo $sql;
            $db->sql_query($sql);
        }
        echo '<br>';
    }
    // cards have been inserted
}