mirror of
https://github.com/Sarjuuk/aowow.git
synced 2025-11-29 15:58:16 +08:00
Misc/Util
* relax numeric type requirements when working with filters * restore smart type casting functionality of Util::checkNumeric when used with NUM_ANY * enable Util::arraySumByKey to work recursively * fix source display in listview
This commit is contained in:
@@ -166,7 +166,7 @@ abstract class BaseType
|
|||||||
$op = (isset($c[2]) && $c[2] == '!') ? 'NOT IN' : 'IN';
|
$op = (isset($c[2]) && $c[2] == '!') ? 'NOT IN' : 'IN';
|
||||||
$val = '('.implode(', ', $c[1]).')';
|
$val = '('.implode(', ', $c[1]).')';
|
||||||
}
|
}
|
||||||
else if (Util::checkNumeric($c[1]))
|
else if (Util::checkNumeric($c[1])) // Note: should this be a NUM_REQ_* check?
|
||||||
{
|
{
|
||||||
$op = (isset($c[2]) && $c[2] == '!') ? '<>' : '=';
|
$op = (isset($c[2]) && $c[2] == '!') ? '<>' : '=';
|
||||||
$val = $c[1];
|
$val = $c[1];
|
||||||
@@ -880,7 +880,7 @@ trait sourceHelper
|
|||||||
|
|
||||||
$s = array_keys($this->sources[$this->id]);
|
$s = array_keys($this->sources[$this->id]);
|
||||||
if ($this->curTpl['moreType'] && $this->curTpl['moreTypeId'] && ($srcData = $this->sourceMore[$this->curTpl['moreType']]->getSourceData($this->curTpl['moreTypeId'])))
|
if ($this->curTpl['moreType'] && $this->curTpl['moreTypeId'] && ($srcData = $this->sourceMore[$this->curTpl['moreType']]->getSourceData($this->curTpl['moreTypeId'])))
|
||||||
$sm = $srcData;
|
$sm = $srcData[$this->curTpl['moreTypeId']];
|
||||||
else if (!empty($this->sources[$this->id][SRC_PVP]))
|
else if (!empty($this->sources[$this->id][SRC_PVP]))
|
||||||
$sm['p'] = $this->sources[$this->id][SRC_PVP][0];
|
$sm['p'] = $this->sources[$this->id][SRC_PVP][0];
|
||||||
|
|
||||||
|
|||||||
@@ -393,7 +393,7 @@ class CreatureListFilter extends Filter
|
|||||||
if (!$this->parentCats || $this->parentCats[0] != 1)
|
if (!$this->parentCats || $this->parentCats[0] != 1)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!Util::checkNumeric($val, NUM_REQ_INT))
|
if (!Util::checkNumeric($val, NUM_CAST_INT))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
$type = FILTER_V_LIST;
|
$type = FILTER_V_LIST;
|
||||||
@@ -518,7 +518,7 @@ class CreatureListFilter extends Filter
|
|||||||
|
|
||||||
protected function cbFaction($cr)
|
protected function cbFaction($cr)
|
||||||
{
|
{
|
||||||
if (!Util::checkNumeric($cr[1], NUM_REQ_INT))
|
if (!Util::checkNumeric($cr[1], NUM_CAST_INT))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!in_array($cr[1], $this->enums[$cr[0]]))
|
if (!in_array($cr[1], $this->enums[$cr[0]]))
|
||||||
|
|||||||
@@ -2503,7 +2503,7 @@ class ItemListFilter extends Filter
|
|||||||
|
|
||||||
protected function cbDisenchantsInto($cr)
|
protected function cbDisenchantsInto($cr)
|
||||||
{
|
{
|
||||||
if (!Util::checkNumeric($cr[1], NUM_REQ_INT))
|
if (!Util::checkNumeric($cr[1], NUM_CAST_INT))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!in_array($cr[1], $this->enums[$cr[0]]))
|
if (!in_array($cr[1], $this->enums[$cr[0]]))
|
||||||
@@ -2620,7 +2620,7 @@ class ItemListFilter extends Filter
|
|||||||
if (!$this->parentCats)
|
if (!$this->parentCats)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!Util::checkNumeric($v, NUM_REQ_INT))
|
if (!Util::checkNumeric($v, NUM_CAST_INT))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
$c = $this->parentCats;
|
$c = $this->parentCats;
|
||||||
@@ -2650,7 +2650,7 @@ class ItemListFilter extends Filter
|
|||||||
|
|
||||||
protected function cbSlotCheck(&$v)
|
protected function cbSlotCheck(&$v)
|
||||||
{
|
{
|
||||||
if (!Util::checkNumeric($v, NUM_REQ_INT))
|
if (!Util::checkNumeric($v, NUM_CAST_INT))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// todo (low): limit to concrete slots
|
// todo (low): limit to concrete slots
|
||||||
|
|||||||
@@ -557,7 +557,7 @@ class QuestListFilter extends Filter
|
|||||||
|
|
||||||
protected function cbReputation($cr, $sign)
|
protected function cbReputation($cr, $sign)
|
||||||
{
|
{
|
||||||
if (!Util::checkNumeric($cr[1], NUM_REQ_INT))
|
if (!Util::checkNumeric($cr[1], NUM_CAST_INT))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!in_array($cr[1], $this->enums[$cr[0]]))
|
if (!in_array($cr[1], $this->enums[$cr[0]]))
|
||||||
@@ -593,7 +593,7 @@ class QuestListFilter extends Filter
|
|||||||
|
|
||||||
protected function cbCurrencyReward($cr)
|
protected function cbCurrencyReward($cr)
|
||||||
{
|
{
|
||||||
if (!Util::checkNumeric($cr[1], NUM_REQ_INT))
|
if (!Util::checkNumeric($cr[1], NUM_CAST_INT))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!in_array($cr[1], $this->enums[$cr[0]]))
|
if (!in_array($cr[1], $this->enums[$cr[0]]))
|
||||||
@@ -672,7 +672,7 @@ class QuestListFilter extends Filter
|
|||||||
|
|
||||||
protected function cbEarnReputation($cr)
|
protected function cbEarnReputation($cr)
|
||||||
{
|
{
|
||||||
if (!Util::checkNumeric($cr[1], NUM_REQ_INT))
|
if (!Util::checkNumeric($cr[1], NUM_CAST_INT))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if ($cr[1] == FILTER_ENUM_ANY) // any
|
if ($cr[1] == FILTER_ENUM_ANY) // any
|
||||||
|
|||||||
@@ -2678,7 +2678,7 @@ class SpellListFilter extends Filter
|
|||||||
if (!$this->parentCats || !in_array($this->parentCats[0], [-13, -2, 7]))
|
if (!$this->parentCats || !in_array($this->parentCats[0], [-13, -2, 7]))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!Util::checkNumeric($val, NUM_REQ_INT))
|
if (!Util::checkNumeric($val, NUM_CAST_INT))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
$type = FILTER_V_LIST;
|
$type = FILTER_V_LIST;
|
||||||
@@ -2692,7 +2692,7 @@ class SpellListFilter extends Filter
|
|||||||
if (!$this->parentCats || $this->parentCats[0] != -13)
|
if (!$this->parentCats || $this->parentCats[0] != -13)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!Util::checkNumeric($val, NUM_REQ_INT))
|
if (!Util::checkNumeric($val, NUM_CAST_INT))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
$type = FILTER_V_LIST;
|
$type = FILTER_V_LIST;
|
||||||
|
|||||||
@@ -970,7 +970,7 @@ abstract class Util
|
|||||||
}
|
}
|
||||||
|
|
||||||
// doesn't handle scientific notation .. why would you input 3e3 for 3000..?
|
// doesn't handle scientific notation .. why would you input 3e3 for 3000..?
|
||||||
public static function checkNumeric(&$data, $typeCast = NUM_ANY)
|
public static function checkNumeric(&$data, $typeCast = NUM_ANY) : bool
|
||||||
{
|
{
|
||||||
if ($data === null)
|
if ($data === null)
|
||||||
return false;
|
return false;
|
||||||
@@ -991,7 +991,7 @@ abstract class Util
|
|||||||
(!is_float($data) && $typeCast == NUM_REQ_FLOAT))
|
(!is_float($data) && $typeCast == NUM_REQ_FLOAT))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
$number = $data; // do not transform strings, store state
|
$number = $data; // do not transform strings, store state
|
||||||
$nMatches = 0;
|
$nMatches = 0;
|
||||||
|
|
||||||
$number = trim($number);
|
$number = trim($number);
|
||||||
@@ -1002,7 +1002,7 @@ abstract class Util
|
|||||||
{
|
{
|
||||||
if ($typeCast == NUM_CAST_INT)
|
if ($typeCast == NUM_CAST_INT)
|
||||||
$data = intVal($number);
|
$data = intVal($number);
|
||||||
else if ($typeCast == NUM_CAST_FLOAT)
|
else // NUM_CAST_FLOAT || NUM_ANY
|
||||||
$data = floatVal($number);
|
$data = floatVal($number);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -1012,10 +1012,10 @@ abstract class Util
|
|||||||
if (is_numeric($number) || preg_match('/^0[xb]?\d+/', $number))
|
if (is_numeric($number) || preg_match('/^0[xb]?\d+/', $number))
|
||||||
{
|
{
|
||||||
$number = intVal($number, 0); // 'base 0' auto-detects base
|
$number = intVal($number, 0); // 'base 0' auto-detects base
|
||||||
if ($typeCast == NUM_CAST_INT)
|
if ($typeCast == NUM_CAST_FLOAT)
|
||||||
$data = $number;
|
|
||||||
else if ($typeCast == NUM_CAST_FLOAT)
|
|
||||||
$data = floatVal($number);
|
$data = floatVal($number);
|
||||||
|
else // NUM_CAST_INT || NUM_ANY
|
||||||
|
$data = $number;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -1034,9 +1034,19 @@ abstract class Util
|
|||||||
foreach ($arr as $k => $v)
|
foreach ($arr as $k => $v)
|
||||||
{
|
{
|
||||||
if (!isset($ref[$k]))
|
if (!isset($ref[$k]))
|
||||||
$ref[$k] = 0;
|
{
|
||||||
|
if (is_array($v))
|
||||||
|
$ref[$k] = [];
|
||||||
|
else if (Util::checkNumeric($v))
|
||||||
|
$ref[$k] = 0;
|
||||||
|
else
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$ref[$k] += $v;
|
if (is_array($ref[$k]) && is_array($v))
|
||||||
|
Util::arraySumByKey($ref[$k], $v);
|
||||||
|
else if (Util::checkNumeric($ref[$k]) && Util::checkNumeric($v))
|
||||||
|
$ref[$k] += $v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user