In memory images/invfiles, general sql cleanup

This commit is contained in:
color.diff=auto
2021-05-12 22:31:41 -06:00
parent 5eced413cb
commit 016ea0e5d2
6 changed files with 3418 additions and 536 deletions

View File

@@ -1,8 +1,35 @@
<?php
class D2ItemData {
public $strings;
public $images;
public function getImages() {
$sql = "
SELECT code,invfile,type,type2 FROM armor
UNION ALL
SELECT code,invfile,type,type2 FROM misc
UNION ALL
SELECT code,invfile,type,type2 FROM weapons
";
$res = PDO_FetchAll($sql);
$isc = null;
foreach ($res as $r) {
$isc1[$r['code']] = $r;
$isc1[$r['code']]['code'] = $r['prop'];
$isc2[$r['type']] = $r;
$isc2[$r['type']]['type'] = $r['prop'];
}
$this->images = array_merge($isc1, $isc2);
unset($isc1);
unset($isc2);
}
public function uniqueItems($index, $doc = FALSE) {
// This is where we get props for each item
@@ -22,41 +49,51 @@ class D2ItemData {
*
*
*/
if (empty($this->images)) {
$this->getImages();
}
if (empty($res['invfile'])) {
// if (empty($res['invfile'])) {
$res['invfile'] = $this->images[$res['code']]['invfile'];
$return = $res;
// if no invfile, get from other tables
// try to get from armor, weapons, misc
$sql = "SELECT invfile FROM armor WHERE code=?";
$invfile[] = PDO_FetchRow($sql, [$res['code']]);
$sql = "SELECT invfile FROM weapons WHERE code=?";
$invfile[] = PDO_FetchRow($sql, [$res['code']]);
$sql = "SELECT invfile FROM misc WHERE code=?";
$invfile[] = PDO_FetchRow($sql, [$res['code']]);
$invfile = array_filter($invfile);
foreach ($invfile as $i) {
$x[] = $i;
}
if (!empty($x[0])) {
$x[0] = array_filter($x[0]);
}
$invClean = $x[0];
if (!empty($invClean)) {
$return = array_merge($res, $invClean);
} else {
$return = $res;
}
// $sql = "SELECT invfile FROM armor WHERE code=?";
// $invfile[] = PDO_FetchRow($sql, [$res['code']]);
//
// $sql = "SELECT invfile FROM weapons WHERE code=?";
// $invfile[] = PDO_FetchRow($sql, [$res['code']]);
//
// $sql = "SELECT invfile FROM misc WHERE code=?";
// $invfile[] = PDO_FetchRow($sql, [$res['code']]);
//
// $invfile = array_filter($invfile);
//
// foreach ($invfile as $i) {
// $x[] = $i;
// }
//
// if (!empty($x[0])) {
// $x[0] = array_filter($x[0]);
// }
// $invClean = $x[0];
// if (!empty($invClean)) {
// $return = array_merge($res, $invClean);
// } else {
// $return = $res;
// }
//$return = array_merge($res, $invClean);
} else {
$return = $res;
}
// } else {
// $return = $res;
// }
// var_dump($return);
/*
@@ -107,16 +144,14 @@ class D2ItemData {
//
//
// ( Also need func1 and val1 for each prop )
//
// for each prop, get stat
$counter = 1;
foreach ($props as $key => $val) {
// val = Prop1,Prop2 etc.
// for each propr, get all 7 stats in ISC
// for now only get stat1, and for else, use dgrp
$sql = "SELECT stat1 FROM properties WHERE code = ?";
$props[$key]['stat'] = PDO_FetchRow($sql, [$val['prop' . $counter]]);
@@ -151,12 +186,12 @@ class D2ItemData {
'string1' => $v['desc']['string1'],
'string2' => $v['desc']['string2'],
'gstring1' => $v['desc']['gstring1'],
'gstring2' => $v['desc']['gstring2'],
'gstring2' => $v['desc']['gstring2'],
'descfunc' => $v['desc']['descfunc'],
'descval' => $v['desc']['descval'],
'dgrp' => $v['desc']['dgrp'],
'dgrpfunc' => $v['desc']['dgrpfunc'],
'dgrpval' => $v['desc']['dgrpval'],
'dgrpval' => $v['desc']['dgrpval'],
"prop" => $return['prop' . $counter],
"par" => $return['par' . $counter],
"min" => $return['min' . $counter],
@@ -288,15 +323,12 @@ class D2ItemData {
public function getIscStrings($iscStat) {
if (empty($this->strings)){
if (empty($this->strings)) {
$this->getStrings();
}
return ($this->strings[$iscStat]);
}
public function getStrings() {
@@ -333,14 +365,13 @@ class D2ItemData {
";
// where p.code = iscstat
$strings = PDO_FetchAll($sql);
//var_dump($strings);
foreach($strings as $k => $v){
foreach ($strings as $k => $v) {
$this->strings[$v['prop']] = $v;
}
}
}
}