[['si'], 'o' => 'orderInGroup ASC'],
'si' => ['j' => ['?_spellicon si ON si.id = a.iconId', true], 's' => ', si.iconString'],
'ac' => ['j' => ['?_achievementcriteria AS `ac` ON `ac`.`refAchievementId` = `a`.`id`', true], 'g' => '`a`.`id`']
);
/*
todo: evaluate TC custom-data-tables: a*_criteria_data should be merged on installation
*/
public function __construct($conditions = [], $miscData = null)
{
parent::__construct($conditions, $miscData);
if ($this->error)
return;
// post processing
$rewards = DB::World()->select('
SELECT ar.entry AS ARRAY_KEY, ar.*, lar.* FROM achievement_reward ar LEFT JOIN locales_achievement_reward lar ON lar.entry = ar.entry WHERE ar.entry IN (?a)',
$this->getFoundIDs()
);
foreach ($this->iterate() as $_id => &$_curTpl)
{
if (!empty($rewards[$_id]))
$_curTpl = array_merge($rewards[$_id], $_curTpl);
//"rewards":[[11,137],[3,138]] [type, typeId]
$_curTpl['rewards'] = [];
if (!empty($_curTpl['item']))
$_curTpl['rewards'][] = [TYPE_ITEM, $_curTpl['item']];
if (!empty($_curTpl['itemExtra']))
$_curTpl['rewards'][] = [TYPE_ITEM, $_curTpl['itemExtra']];
if (!empty($_curTpl['title_A']))
$_curTpl['rewards'][] = [TYPE_TITLE, $_curTpl['title_A']];
if (!empty($_curTpl['title_H']))
if (empty($_curTpl['title_A']) || $_curTpl['title_A'] != $_curTpl['title_H'])
$_curTpl['rewards'][] = [TYPE_TITLE, $_curTpl['title_H']];
// icon
$_curTpl['iconString'] = $_curTpl['iconString'] ?: 'trade_engineering';
}
}
public function getJSGlobals($addMask = GLOBALINFO_ANY)
{
$data = [];
foreach ($this->iterate() as $__)
{
if ($addMask & GLOBALINFO_SELF)
$data[TYPE_ACHIEVEMENT][$this->id] = ['icon' => $this->curTpl['iconString'], 'name' => $this->getField('name', true)];
if ($addMask & GLOBALINFO_REWARDS)
foreach ($this->curTpl['rewards'] as $_)
$data[$_[0]][$_[1]] = $_[1];
}
return $data;
}
public function getListviewData($addInfoMask = 0x0)
{
$data = [];
foreach ($this->iterate() as $__)
{
$data[$this->id] = array(
'id' => $this->id,
'name' => $this->getField('name', true),
'description' => $this->getField('description', true),
'points' => $this->curTpl['points'],
'side' => $this->curTpl['faction'],
'category' => $this->curTpl['category'],
'parentcat' => $this->curTpl['parentCat'],
);
if ($addInfoMask & ACHIEVEMENTINFO_PROFILE)
$data[$this->id]['icon'] = $this->curTpl['iconString'];
// going out on a limb here: type = 1 if in level 3 of statistics tree, so, IF (statistic AND parentCat NOT statistic (1)) i guess
if ($this->curTpl['flags'] & ACHIEVEMENT_FLAG_COUNTER && $this->curTpl['parentCat'] != 1)
$data[$this->id]['type'] = 1;
if ($_ = $this->curTpl['rewards'])
$data[$this->id]['rewards'] = $_;
else if ($_ = $this->getField('reward', true))
$data[$this->id]['reward'] = $_;
}
return $data;
}
// only for current template
public function getCriteria()
{
if (isset($this->criteria[$this->id]))
return $this->criteria[$this->id];
$result = DB::Aowow()->Select('SELECT * FROM ?_achievementcriteria WHERE `refAchievementId` = ?d ORDER BY `order` ASC', $this->id);
if (!$result)
return [];
$this->criteria[$this->id] = $result;
return $this->criteria[$this->id];
}
public function renderTooltip()
{
$criteria = $this->getCriteria();
$tmp = [];
$rows = [];
$i = 0;
foreach ($criteria as $_row)
{
if ($i++ % 2)
$tmp[] = $_row;
else
$rows[] = $_row;
}
if ($tmp)
$rows = array_merge($rows, $tmp);
$description = $this->getField('description', true);
$name = $this->getField('name', true);
$criteria = '';
$i = 0;
foreach ($rows as $crt)
{
$obj = (int)$crt['value1'];
$qty = (int)$crt['value2'];
// we could show them, but the tooltips are cluttered
if (($crt['completionFlags'] & ACHIEVEMENT_CRITERIA_FLAG_HIDDEN) && User::$perms <= 0)
continue;
$crtName = Util::localizedString($crt, 'name');
switch ($crt['type'])
{
// link to title - todo (low): crosslink
case ACHIEVEMENT_CRITERIA_TYPE_EARNED_PVP_TITLE:
$crtName = Util::ucFirst(Lang::$game['title']).Lang::$main['colon'].$crtName;
break;
// link to quest
case ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_QUEST:
if (!$crtName)
$crtName = QuestList::getName($obj);
break;
// link to spell (/w icon)
case ACHIEVEMENT_CRITERIA_TYPE_BE_SPELL_TARGET:
case ACHIEVEMENT_CRITERIA_TYPE_BE_SPELL_TARGET2:
case ACHIEVEMENT_CRITERIA_TYPE_CAST_SPELL:
case ACHIEVEMENT_CRITERIA_TYPE_LEARN_SPELL:
case ACHIEVEMENT_CRITERIA_TYPE_CAST_SPELL2:
if (!$crtName)
$crtName = SpellList::getName($obj);
break;
// link to item (/w icon)
case ACHIEVEMENT_CRITERIA_TYPE_OWN_ITEM:
case ACHIEVEMENT_CRITERIA_TYPE_USE_ITEM:
case ACHIEVEMENT_CRITERIA_TYPE_LOOT_ITEM:
case ACHIEVEMENT_CRITERIA_TYPE_EQUIP_ITEM:
if (!$crtName)
$crtName = ItemList::getName($obj);
break;
// link to faction (/w target reputation)
case ACHIEVEMENT_CRITERIA_TYPE_GAIN_REPUTATION:
if (!$crtName)
$crtName = FactionList::getName($obj);
break;
}
if ($crt['completionFlags'] & ACHIEVEMENT_CRITERIA_FLAG_MONEY_COUNTER)
$criteria .= '- '.Util::jsEscape($crtName).' '.number_format($crt['value2' ] / 10000).'
';
else
$criteria .= '- '.Util::jsEscape($crtName).'
';
if (++$i == round(count($rows)/2))
$criteria .= '
| '; $x .= Util::jsEscape($name); $x .= ' |
| ';
if ($description)
$x .= ' '.Util::jsEscape($description).' '; if ($criteria) { $x .= ' '.Lang::$achievement['criteria'].':'; $x .= '
|