public static function Create($data) { $in = array(); $cost = Cost::CostFromString($data["Mana Cost"]); $in["cost"] = $cost->ID(); $in["rarity"] = strtoupper($data["Rarity"]); $map = array( "name" => "Card Name", "power" => "P", "toughness" => "T", "text" => "Card Text", "flavor" => "Flavor Text", "loyalty" => "Loyalty", "artist" => "Artist", "multiverse" => "multiverse", "number" => "Card #", "set" => "set" ); foreach( $map as $key => $val ) { if ( isset( $data[$val] ) ) $in[$key] = $data[$val]; } DB::zdb()->insert(Card::$TABLE, $in); $id = DB::zdb()->lastInsertId(); foreach( $data["Types"] as $type ) { DB::zdb()->insert(Card::$TYPES, array("card" => $id, "type" => $type) ); } foreach( $data["Subtypes"] as $type ) { DB::zdb()->insert(Card::$SUBS, array("card" => $id, "subtype" => $type) ); } Image::Import($data["multiverse"], $id); }
<?php if ( isset( $_GET["cost"] ) ) { $in = $_GET["cost"]; $cost = Cost::CostFromString($_GET["cost"]); $in = substr($in, 2); } else { $cost = new Cost($_GET["id"]); $in = $cost->EditString(); } $d = $cost->EditRecord(); $cL = $d->Get("colorless"); $clp1 = $cL+1; $cL = str_pad($cL, 2, "0", STR_PAD_LEFT); $clp1 = str_pad($clp1, 2, "0", STR_PAD_LEFT); $s = DB::zdb()->select() ->from("symbols"); $rows = DB::zdb()->fetchAll($s); $colors = array(); function BasicImgStr($color, $i) { $r = "<span onmouseover=\"hover($i);\""; $r .= " onclick=\"click_base($i);\">"; $r .= '<img src="Views/img/mana_symbols/';
public static function CostFromString($str) { $match = array(); $cond = "(1=1) "; static $colorMixer = array( "RR" => "red", "PR" => "red", "GG" => "green", "PG" => "green", "UU" => "blue", "PU" => "blue", "WW" => "white", "PW" => "white", "BB" => "black", "PB" => "black", "RG" => "hybrid", "RU" => "hybrid", "RW" => "hybrid", "RB" => "hybrid", "GU" => "hybrid", "GW" => "hybrid", "GB" => "hybrid", "UW" => "hybrid", "UB" => "hybrid", "BW" => "hybrid", "2R" => "red", "2G" => "green", "2B" => "black", "2U" => "blue", "2W" => "white" ); $uniqSymbols = array(); if ( $str == "NONE" || strlen($str) < 2 ) { $match["no_cost"] = 1; } else { $match["colorless"] = $str{0} . $str{1}; $cond .= " AND colorless = " . $match["colorless"]; $match["cmc"] = $match["colorless"]; for ( $i = 2; $i < strlen($str); $i += 2 ) { $buf = $str{$i} . $str{$i+1}; if ( array_key_exists( $buf, $colorMixer ) && !in_array($buf, $uniqSymbols) ) { $uniqSymbols[] = $buf; } if ( $buf <> "XX" ) ++$match["cmc"]; else if ( $buf{0} == '2' ) $match["cmc"] += 2; if ( array_key_exists( $buf, $match ) ) { ++$match[$buf]; } else { $match[$buf] = 1; } } $match["color"] = "colorless"; foreach ( $uniqSymbols as $symb ) { if ( $match["color"] == "colorless" || $match["color"] == $colorMixer[$symb] ) { $match["color"] = $colorMixer[$symb]; } else { $match["color"] = "gold"; } } if ( $match["color"] == "hybrid" && count($uniqSymbols) > 1 ) $match["color"] = "gold"; $s = DB::zdb()->select() ->from(Card::$COLORS, array("id")) ->where("color = ?", $match["color"]); $match["color"] = DB::zdb()->fetchOne($s); } if ( !isset( $match["no_cost"] ) ) { $cond .= " AND no_cost IS NULL "; } foreach ( Cost::$FIELDS as $key => $val ) { if ( !isset( $match[$key] ) ) { $cond .= " AND $val IS NULL "; } else { $cond .= ( " AND $val = " . $match[$key] . " "); $match[$val] = $match[$key]; unset($match[$key]); } } // Search the DB for it $s = DB::zdb()->select() ->from(Cost::$TABLE, array("id")) ->where( $cond ); $id = DB::zdb()->fetchOne($s); if ( $id ) { return new Cost($id); } else { DB::zdb()->insert(Cost::$TABLE, $match); return Cost::CostFromString($str); } }