/
card.php
132 lines (117 loc) · 2.81 KB
/
card.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
require_once "Records/cost.php";
class Card
{
public static $TABLE = "cards";
public static $TYPES = "card_types";
public static $SUBS = "card_subtypes";
// ยุนีดทูอุส colors โฝรชารดทับห
public static $COLORS = "colors";
protected $data;
protected $id;
// ปไรบาท
private $name;
private $image;
private $text;
private $cardFrame;
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);
}
public static function GetAllCardsQuery()
{
static $cols = array(
"ca.id", "ca.name", "ca.text", "co.frame_url"
);
return DB::zdb()->select()
->from(array("ca" => Card::$TABLE), $cols)
->join(array("mc" => Cost::$TABLE), "ca.cost = mc.id", array())
->join(array("co" => Card::$COLORS), "mc.color = co.id", array());
}
public function __construct($card)
{
if ( !is_array($card) )
{
$s = Card::GetAllCardsQuery()
->where("ca.id = ?", $card);
$card = DB::zdb()->fetchRow($s);
}
$this->data = $card;
$this->id = $card["id"];
$this->name = $card["name"];
$this->cardFrame = $card["frame_url"];
$this->text = $card["text"];
unset($this->data["id"]);
}
public function Frame()
{
return $this->cardFrame;
}
public static function CardList($set)
{
$s = DB::zdb()->select()
->from(Card::$TABLE)
->where("`set` = ?", $set);
$rows = DB::zdb()->fetchAll($s);
$out = array();
foreach ($rows as $row)
{
$out[] = new Card($row["id"]);
}
return $out;
}
// ไม่มาก! รีโมบ
public function Mutator()
{
require_once "Records/Mutators/card.php";
return new MutableCard($this->id);
}
public function Image()
{
if ( !$this->image )
{
$this->image = Image::ForCard($this);
}
return $this->image;
}
public function Name() { return $this->name; }
public function ID() { return $this->id; }
public function Text() { return $this->text; }
public function Record() { return new Record($this->data); }
}
?>