- decoupled filter from type-classes, this is required for items.php to be

groupable
- force profile.lastupdated to new Date; trial and aerror on
  raid-progress; remove 'profile=summary' from generated pages (is generated by
  jscript)
- fixed some misc errors
This commit is contained in:
Sarjuuk
2014-03-19 22:06:04 +01:00
parent d89d2c8c91
commit 1ced59c113
22 changed files with 257 additions and 176 deletions

View File

@@ -24,9 +24,9 @@ class AchievementList extends BaseType
todo: evaluate TC custom-data-tables: a*_criteria_data should be merged on installation, a*_reward linked with mail_loot_template and achievement
*/
public function __construct($conditions = [], $applyFilter = false)
public function __construct($conditions = [])
{
parent::__construct($conditions, $applyFilter);
parent::__construct($conditions);
// post processing
foreach ($this->iterate() as &$_curTpl)

View File

@@ -11,7 +11,6 @@ abstract class BaseType
protected $templates = [];
protected $curTpl = []; // lets iterate!
protected $filter = null;
protected $matches = null; // total matches unaffected by sqlLimit in config
protected $queryBase = '';
@@ -50,7 +49,7 @@ abstract class BaseType
* results in
* WHERE ((`id` = 45) OR (`name` NOT LIKE "%test%") OR ((`flags` & 255) AND (`flags2` & 15)) OR ((`mask` & 3) = 0)) OR (`joinedTbl`.`field` IS NULL) LIMIT 5
*/
public function __construct($conditions = [], $applyFilter = false)
public function __construct($conditions = [])
{
$where = [];
$linking = ' AND ';
@@ -60,23 +59,12 @@ abstract class BaseType
if (!$this->queryBase || $conditions === null)
return;
// may be called without filtering
if ($applyFilter && class_exists($className.'Filter'))
{
$fiName = $className.'Filter';
$this->filter = new $fiName($this);
}
$prefixes = [];
if (preg_match('/FROM \??[\w\_]+( AS)?\s?`?(\w+)`?$/i', $this->queryBase, $match))
$prefixes['base'] = $match[2];
else
$prefixes['base'] = '';
// add conditions from filter
// to consider - conditions from filters are already escaped and contain sql-wildcards reescaping those sucks
$conditions[] = $this->filter ? $this->filter->getConditions() : null;
$resolveCondition = function ($c, $supLink) use (&$resolveCondition, &$prefixes)
{
$subLink = '';
@@ -344,47 +332,46 @@ abstract class BaseType
return $this->matches;
}
public function filterGetForm($key = null, $raw = false)
protected function extendQueryOpts($extra) // needs to be called from __construct
{
$form = [];
if (!$this->filter)
return $form;
foreach ($this->filter->getForm() as $name => $data)
foreach ($extra as $tbl => $sets)
{
if (!$data || ($key && $name != $key))
if (!isset($this->queryOpts[$tbl])) // allow adding only to known tables
continue;
switch ($name)
foreach ($sets as $module => $value)
{
case 'setCriteria':
$form[$name] = $raw ? $data : 'fi_setCriteria('.$data['cr'].', '.$data['crs'].', '.$data['crv'].');';
break;
case 'extraCols':
$form[$name] = $raw ? $data : 'fi_extraCols = '.json_encode(array_unique($data), JSON_NUMERIC_CHECK).';';
break;
case 'setWeights':
$form[$name] = $raw ? $data : 'fi_setWeights('.json_encode($data, JSON_NUMERIC_CHECK).', 0, 1, 1);';
break;
case 'form':
if ($key == $name) // only if explicitely specifies
$form[$name] = $data;
break;
default:
break;
if (!$value)
continue;
switch ($module)
{
// additional (str)
case 'g': // group by
case 'h': // having
case 'o': // order by
if (!empty($this->queryOpts[$tbl][$module]))
$this->queryOpts[$tbl][$module] .= $value;
else
$this->queryOpts[$tbl][$module] = $value;
break;
// additional (arr)
case 'j': // join
if (is_array($this->queryOpts[$tbl][$module]))
$this->queryOpts[$tbl][$module][0][] = $value;
else
$this->queryOpts[$tbl][$module] = $value;
break;
// replacement
case 'l': // limit
case 's': // select
$this->queryOpts[$tbl][$module] = $value;
break;
}
}
}
return $key ? (empty($form[$key]) ? [] : $form[$key]) : $form;
}
public function filterGetError()
{
if ($this->filter)
return $this->filter->error;
else
return false;
}
// should return data required to display a listview of any kind
@@ -555,7 +542,6 @@ abstract class Filter
private $cndSet = [];
protected $parent = null; // itemFilter requires this
protected $fiData = ['c' => [], 'v' =>[]];
protected $formData = array( // data to fill form fields
'form' => [], // base form - unsanitized
@@ -565,10 +551,8 @@ abstract class Filter
);
// parse the provided request into a usable format; recall self with GET-params if nessecary
public function __construct($parent)
public function __construct()
{
$this->parent = $parent;
// prefer POST over GET, translate to url
if (!empty($_POST))
{
@@ -610,7 +594,7 @@ abstract class Filter
}
// do get request
header('Location: '.STATIC_URL.'?'.$_SERVER['QUERY_STRING'].'='.implode(';', $tmp));
header('Location: '.HOST_URL.'?'.$_SERVER['QUERY_STRING'].'='.implode(';', $tmp));
}
// sanitize input and build sql
else if (!empty($_GET['filter']))
@@ -704,9 +688,39 @@ abstract class Filter
array_unshift($this->cndSet, empty($this->fiData['v']['ma']) ? 'AND' : 'OR');
}
public function getForm()
public function getForm($key = null, $raw = false)
{
return $this->formData;
$form = [];
if (!$this->formData)
return $form;
foreach ($this->formData as $name => $data)
{
if (!$data || ($key && $name != $key))
continue;
switch ($name)
{
case 'setCriteria':
$form[$name] = $raw ? $data : 'fi_setCriteria('.$data['cr'].', '.$data['crs'].', '.$data['crv'].');';
break;
case 'extraCols':
$form[$name] = $raw ? $data : 'fi_extraCols = '.json_encode(array_unique($data), JSON_NUMERIC_CHECK).';';
break;
case 'setWeights':
$form[$name] = $raw ? $data : 'fi_setWeights('.json_encode($data, JSON_NUMERIC_CHECK).', 0, 1, 1);';
break;
case 'form':
if ($key == $name) // only if explicitely specified
$form[$name] = $data;
break;
default:
break;
}
}
return $key ? (empty($form[$key]) ? [] : $form[$key]) : $form;
}
public function getConditions()

View File

@@ -19,9 +19,9 @@ class GameObjectList extends BaseType
'ir' => ['j' => ['gameobject_involvedrelation ir ON ir.id = o.id', true]] // ends at GO
);
public function __construct($conditions = [], $applyFilter = false)
public function __construct($conditions = [])
{
parent::__construct($conditions, $applyFilter);
parent::__construct($conditions);
if ($this->error)
return;

View File

@@ -28,13 +28,13 @@ class ItemList extends BaseType
'i' => ['o' => 'i.quality DESC, i.itemLevel DESC']
);
public function __construct($conditions = [], $applyFilter = false, $miscData = null)
public function __construct($conditions = [], $miscData = null)
{
// search by statweight
if ($miscData && isset($miscData['wt']) && isset($miscData['wtv']))
$conditions[] = $this->createConditionsForWeights($miscData);
if ($miscData && !empty($miscData['extraOpts']))
$this->extendQueryOpts($miscData['extraOpts']);
parent::__construct($conditions, $applyFilter);
parent::__construct($conditions);
foreach ($this->iterate() as &$_curTpl)
{
@@ -283,7 +283,8 @@ class ItemList extends BaseType
$currency[] = [-$k, $qty];
}
$data[$this->id]['stock'] = $cost['stock'];
$data[$this->id]['stock'] = $cost['stock']; // display as column in lv
$data[$this->id]['avail'] = $cost['stock']; // display as number on icon
$data[$this->id]['cost'] = [$this->getField('buyPrice')];
if ($e = $cost['event'])
@@ -354,8 +355,6 @@ class ItemList extends BaseType
/* even more complicated crap
"source":[5],"sourcemore":[{"n":"Commander Oxheart","t":1,"ti":64606,"z":5842}],
avail unk
rel unk
modelviewer {type:X, displayid:Y, slot:z} .. not sure, when to set
*/
@@ -1128,47 +1127,6 @@ class ItemList extends BaseType
unset($this->json[$this->id][$k]);
}
public function createConditionsForWeights(&$data)
{
if (count($data['wt']) != count($data['wtv']))
return null;
$select = $cnd = [];
$wtSum = 0;
foreach ($data['wt'] as $k => $v)
{
@$str = Util::$itemFilter[$v];
$qty = intVal($data['wtv'][$k]);
if ($str && $qty)
{
if ($str == 'rgdspeed') // dont need no duplicate column
$str = 'speed';
if ($str == 'mledps') // todo (med): unify rngdps and mledps to dps
$str = 'dps';
$select[] = '(`is`.`'.$str.'` * '.$qty.')';
$cnd[] = ['is.'.$str, 0, '>'];
$wtSum += $qty;
}
else // well look at that.. erronous indizes or zero-weights
{
unset($data['wt'][$k]);
unset($data['wtv'][$k]);
}
}
if (count($cnd) > 1)
array_unshift($cnd, 'OR');
else if (count($cnd) == 1)
$cnd = $cnd[0];
$this->queryOpts['is']['s'] = $select ? ', ('.implode(' + ', $select).') / '.$wtSum.' AS score' : null;
return $cnd;
}
private function canTeachSpell()
{
// 483: learn recipe; 55884: learn mount/pet
@@ -1438,8 +1396,8 @@ class ItemList extends BaseType
class ItemListFilter extends Filter
{
// usable-by - limit weapon/armor selection per CharClass - itemClass => available itemsubclasses
private $ubFilter = [];
private $ubFilter = []; // usable-by - limit weapon/armor selection per CharClass - itemClass => available itemsubclasses
public $extraOpts = null; // score for statWeights
protected $enums = array(
99 => array( // profession | recycled for 86, 87
null, 171, 164, 185, 333, 202, 129, 755, 165, 186, 197, true, false, 356, 182, 773
@@ -1569,7 +1527,7 @@ class ItemListFilter extends Filter
177 => [FILTER_CR_STAFFFLAG, 'flagsExtra' ], // flags2
);
public function __construct($parent)
public function __construct()
{
$classes = new CharClassList();
foreach ($classes->iterate() as $cId => $_tpl)
@@ -1586,7 +1544,50 @@ class ItemListFilter extends Filter
$this->ubFilter[$cId][ITEM_CLASS_ARMOR][] = $i;
}
parent::__construct($parent);
parent::__construct();
}
public function createConditionsForWeights(&$data)
{
if (count($data['wt']) != count($data['wtv']))
return null;
$select = $cnd = [];
$wtSum = 0;
foreach ($data['wt'] as $k => $v)
{
@$str = Util::$itemFilter[$v];
$qty = intVal($data['wtv'][$k]);
if ($str && $qty)
{
if ($str == 'rgdspeed') // dont need no duplicate column
$str = 'speed';
if ($str == 'mledps') // todo (med): unify rngdps and mledps to dps
$str = 'dps';
$select[] = '(`is`.`'.$str.'` * '.$qty.')';
$cnd[] = ['is.'.$str, 0, '>'];
$wtSum += $qty;
}
else // well look at that.. erronous indizes or zero-weights
{
unset($data['wt'][$k]);
unset($data['wtv'][$k]);
}
}
if (count($cnd) > 1)
array_unshift($cnd, 'OR');
else if (count($cnd) == 1)
$cnd = $cnd[0];
if ($select)
$this->extraOpts['is']['s'] = ', ('.implode(' + ', $select).') / '.$wtSum.' AS score';
return $cnd;
}
protected function createSQLForCriterium(&$cr)
@@ -1873,7 +1874,7 @@ class ItemListFilter extends Filter
$_v['wt'] = (array)$_v['wt'];
$_v['wtv'] = (array)$_v['wtv'];
$parts[] = $this->parent->createConditionsForWeights($_v);
$parts[] = $this->createConditionsForWeights($_v);
foreach ($_v['wt'] as $_)
$this->formData['extraCols'][] = $_;

View File

@@ -17,9 +17,9 @@ class ItemsetList extends BaseType
protected $queryBase = 'SELECT *, id AS ARRAY_KEY FROM ?_itemset `set`';
protected $queryOpts = ['set' => ['o' => 'maxlevel DESC']];
public function __construct($conditions = [], $applyFilter = false)
public function __construct($conditions = [])
{
parent::__construct($conditions, $applyFilter);
parent::__construct($conditions);
// post processing
foreach ($this->iterate() as &$_curTpl)

View File

@@ -24,9 +24,9 @@ class QuestList extends BaseType
'itemStart' => ['j' => ['?_items itemStart ON itemStart.startQuest = qt.id', true], 'g' => 'qt.id'] // started by item .. grouping required, as the same quest may have multiple starter
);
public function __construct($conditions = [], $applyFilter = false)
public function __construct($conditions = [])
{
parent::__construct($conditions, $applyFilter);
parent::__construct($conditions);
// post processing
foreach ($this->iterate() as $id => &$_curTpl)
@@ -48,7 +48,7 @@ class QuestList extends BaseType
for ($i = 0; $i < 9; $i++)
unset($_curTpl['Field'.$i]);
// todo (med): extend for reward case
// store requirements
$data = [];
for ($i = 1; $i < 7; $i++)
{
@@ -66,9 +66,34 @@ class QuestList extends BaseType
if ($_ = $_curTpl['RequiredSourceItemId'.$i])
$data[TYPE_ITEM][] = $_;
}
if ($data)
$this->requires[$id] = $data;
// store rewards
$data = [];
if ($_ = $_curTpl['RewardTitleId'])
$data[TYPE_TITLE][] = $_;
for ($i = 1; $i < 7; $i++)
{
if ($_ = $_curTpl['RewardChoiceItemId'.$i])
$data[TYPE_ITEM][] = $_;
if ($i > 5)
continue;
if ($_ = $_curTpl['RewardFactionId'.$i])
$data[TYPE_FACTION][] = $_;
if ($i > 4)
continue;
if ($_ = $_curTpl['RewardItemId'.$i])
$data[TYPE_ITEM][] = $_;
}
if ($data)
$this->rewards[$id] = $data;
}
}

View File

@@ -53,9 +53,9 @@ class SpellList extends BaseType
protected $queryBase = 'SELECT *, id AS ARRAY_KEY FROM ?_spell s';
public function __construct($conditions = [], $applyFilter = false)
public function __construct($conditions = [])
{
parent::__construct($conditions, $applyFilter);
parent::__construct($conditions);
if ($this->error)
return;