-
Notifications
You must be signed in to change notification settings - Fork 22
/
class.itemlist.php
160 lines (147 loc) · 4.33 KB
/
class.itemlist.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?php
/**
* $Date$
* $Revision$
* $HeadURL$
* @package EDK
*/
/**
* Fetches a information for each item in a list.
*
* The list is based on dropped items for given kill ids, dropped items for
* given kill ids or a list of itemIDs
* @package EDK
*/
class ItemList
{
private $itemarray = array();
private $destroyedIDarray = array();
private $droppedIDarray = array();
/** @var float */
public $price = 0;
/** @var boolean */
public $executed = false;
/** @var DBBaseQuery */
private $qry = null;
/**
*
* @param array $itemarray
* @param float $price
*/
function ItemList($itemarray = null, $price = 0)
{
if (isset($itemarray)) {
$this->itemarray = $itemarray;
}
$this->price = $price;
$this->qry = DBFactory::getDBQuery();
}
/**
* Add an itemID to the list of items.
* @param integer $itemID
*/
function addItem($itemID)
{
if ($this->executed) {
return false;
}
$this->itemarray[] = $itemID;
}
/**
* Add an killID to the list of kills to check for destroyed items.
* @param integer $killID
*/
function addKillDestroyed($killID)
{
if ($this->executed) {
return false;
}
$this->destroyedIDarray[] = $killID;
}
/**
* Add an killID to the list of kills to check for dropped items.
* @param integer $killID
*/
function addKillDropped($killID)
{
if ($this->executed) {
return false;
}
$this->droppedIDarray[] = $killID;
}
function execute()
{
if ($this->executed
|| (!count($this->itemarray)
&& !count($this->destroyedIDarray)
&& !count($this->droppedIDarray))) {
return;
}
$sql = "select inv.icon, inv.typeID,
itp.price, kb3_item_types.*, dga.value as metalevel, dgb.value as techlevel,
dc.value as usedcharge, dl.value as usedlauncher,
inv.groupID, inv.typeName, inv.capacity, inv.raceID, inv.mass, inv.volume,
inv.basePrice, inv.marketGroupID";
if (count($this->destroyedIDarray)) {
$sql .= ", if(dl.attributeID IS NULL,sum(itd.itd_quantity),"
."truncate(sum(itd.itd_quantity)/count(dl.attributeID),0)) "
."as itd_quantity, itd_itm_id, itd_itl_id, itl_flagText ";
} else if (count($this->droppedIDarray)) {
$sql .= ", if(dl.attributeID IS NULL,sum(itd.itd_quantity),"
."truncate(sum(itd.itd_quantity)/count(dl.attributeID),0)) "
."as itd_quantity, itd_itm_id, itd_itl_id, itl_flagText ";
}
$sql .= "from kb3_invtypes inv
left join kb3_dgmtypeattributes dga on dga.typeID=inv.typeID and dga.attributeID=633
left join kb3_dgmtypeattributes dgb on dgb.typeID=inv.typeID and dgb.attributeID=422
left join kb3_item_price itp on itp.typeID=inv.typeID
left join kb3_item_types on inv.groupID=itt_id
left join kb3_dgmtypeattributes dc on dc.typeID = inv.typeID AND dc.attributeID IN (128)
left join kb3_dgmtypeattributes dl on dl.typeID = inv.typeID AND dl.attributeID IN (137,602) ";
if (count($this->destroyedIDarray)) {
$sql .= "join kb3_items_destroyed itd on inv.typeID = itd_itm_id "
."and itd_kll_id in ("
.implode(',', $this->destroyedIDarray).") "
."left join kb3_item_locations itl "
."on (itd.itd_itl_id = itl.itl_flagID )";
} else if (count($this->droppedIDarray)) {
$sql .= "join kb3_items_dropped itd "
."on inv.typeID = itd_itm_id and itd_kll_id in ("
.implode(',', $this->droppedIDarray).") "
."left join kb3_item_locations itl "
."on (itd.itd_itl_id = itl.itl_flagID ) ";
} else {
$sql .= "where inv.typeID in (".implode(',', $this->itemarray).") ";
}
if (count($this->destroyedIDarray) || count($this->droppedIDarray)) {
$sql .= "group by itd.itd_itm_id, itd.itd_itl_id "
."order by itd.itd_itl_id ";
}
$this->qry->execute($sql);
$this->executed = true;
}
/**
* Iterate through the list of items returned, returning one for each call
*
* @return Item
*/
function getItem()
{
if (!$this->executed) {
$this->execute();
}
if ($row = $this->qry->getRow()) {
// Set up a new Item and return it.
$item = new Item($row['typeID'], $row);
return $item;
}
return null;
}
/**
* Rewind the list of items to the start.
*/
function rewind()
{
$this->qry->rewind();
}
}