[['ic'], 'o' => 'orderInGroup ASC'],
'ic' => ['j' => ['?_icons ic ON ic.id = a.iconId', true], 's' => ', ic.name AS 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.ID AS ARRAY_KEY, ar.TitleA, ar.TitleH, ar.ItemID, ar.Sender AS sender, ar.MailTemplateID,
ar.Subject AS subject_loc0, IFNULL(arl2.Subject, "") AS subject_loc2, IFNULL(arl3.Subject, "") AS subject_loc3, IFNULL(arl4.Subject, "") AS subject_loc4, IFNULL(arl6.Subject, "") AS subject_loc6, IFNULL(arl8.Subject, "") AS subject_loc8,
ar.Text AS text_loc0, IFNULL(arl2.Text, "") AS text_loc2, IFNULL(arl3.Text, "") AS text_loc3, IFNULL(arl4.Text, "") AS text_loc4, IFNULL(arl6.Text, "") AS text_loc6, IFNULL(arl8.Text, "") AS text_loc8
FROM
achievement_reward ar
LEFT JOIN
achievement_reward_locale arl2 ON arl2.ID = ar.ID AND arl2.Locale = "frFR"
LEFT JOIN
achievement_reward_locale arl3 ON arl3.ID = ar.ID AND arl3.Locale = "deDE"
LEFT JOIN
achievement_reward_locale arl4 ON arl4.ID = ar.ID AND arl4.Locale = "zhCN"
LEFT JOIN
achievement_reward_locale arl6 ON arl6.ID = ar.ID AND arl6.Locale = "esES"
LEFT JOIN
achievement_reward_locale arl8 ON arl8.ID = ar.ID AND arl8.Locale = "ruRU"
WHERE
ar.ID IN (?a)',
$this->getFoundIDs()
);
foreach ($this->iterate() as $_id => &$_curTpl)
{
$_curTpl['rewards'] = [];
if (!empty($rewards[$_id]))
{
$_curTpl = array_merge($rewards[$_id], $_curTpl);
if ($rewards[$_id]['MailTemplateID'])
{
// using class Loot creates an inifinite loop cirling between Loot, ItemList and SpellList or something
// $mailSrc = new Loot();
// $mailSrc->getByContainer(LOOT_MAIL, $rewards[$_id]['mailTemplate']);
// foreach ($mailSrc->iterate() as $loot)
// $_curTpl['rewards'][] = [TYPE_ITEM, $loot['id']];
// lets just assume for now, that mailRewards for achievements do not contain references
$mailRew = DB::World()->selectCol('SELECT Item FROM mail_loot_template WHERE Reference <= 0 AND entry = ?d', $rewards[$_id]['MailTemplateID']);
foreach ($mailRew AS $mr)
$_curTpl['rewards'][] = [TYPE_ITEM, $mr];
}
}
//"rewards":[[11,137],[3,138]] [type, typeId]
if (!empty($_curTpl['ItemID']))
$_curTpl['rewards'][] = [TYPE_ITEM, $_curTpl['ItemID']];
if (!empty($_curTpl['itemExtra']))
$_curTpl['rewards'][] = [TYPE_ITEM, $_curTpl['itemExtra']];
if (!empty($_curTpl['TitleA']))
$_curTpl['rewards'][] = [TYPE_TITLE, $_curTpl['TitleA']];
if (!empty($_curTpl['TitleH']))
if (empty($_curTpl['TitleA']) || $_curTpl['TitleA'] != $_curTpl['TitleH'])
$_curTpl['rewards'][] = [TYPE_TITLE, $_curTpl['TitleH']];
// 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;
}
$criteria .= '- '.Util::jsEscape($crtName);
if ($crt['completionFlags'] & ACHIEVEMENT_CRITERIA_FLAG_MONEY_COUNTER)
$criteria .= ' '.Lang::nf($crt['value2' ] / 10000).'';
$criteria .= '
';
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 .= '
|