Template/Update (Part 36)

* convert dbtype 'mail'
This commit is contained in:
Sarjuuk
2025-08-13 22:20:24 +02:00
parent 0cf9069eb1
commit 3f8d5d90e1
6 changed files with 259 additions and 230 deletions

178
endpoints/mail/mail.php Normal file
View File

@@ -0,0 +1,178 @@
<?php
namespace Aowow;
if (!defined('AOWOW_REVISION'))
die('illegal access');
class MailBaseResponse extends TemplateResponse implements ICache
{
use TrDetailPage, TrCache;
protected int $cacheType = CACHE_TYPE_PAGE;
protected string $template = 'detail-page-generic';
protected string $pageName = 'mail';
protected ?int $activeTab = parent::TAB_DATABASE;
protected array $breadcrumb = [0, 103];
public int $type = Type::MAIL;
public int $typeId = 0;
private MailList $subject;
public function __construct(string $id)
{
parent::__construct($id);
$this->typeId = intVal($id);
$this->contribute = Type::getClassAttrib($this->type, 'contribute') ?? CONTRIBUTE_NONE;
}
protected function generate() : void
{
$this->subject = new MailList(array(['id', $this->typeId]));
if ($this->subject->error)
$this->generateNotFound(Lang::game('mail'), Lang::mail('notFound'));
$this->extendGlobalData($this->subject->getJSGlobals());
$this->h1 = Util::htmlEscape($this->subject->getField('name', true));
$this->gPageInfo += array(
'type' => $this->type,
'typeId' => $this->typeId,
'name' => $this->subject->getField('name', true)
);
/**************/
/* Page Title */
/**************/
array_unshift($this->title, $this->subject->getField('name', true), Util::ucFirst(Lang::game('mail')));
/***********/
/* Infobox */
/***********/
$infobox = Lang::getInfoBoxForFlags($this->subject->getField('cuFlags'));
// sender + delay
if ($this->typeId < 0) // def. achievement
{
if ($npcId = DB::World()->selectCell('SELECT `Sender` FROM achievement_reward WHERE `ID` = ?d', -$this->typeId))
{
$infobox[] = Lang::mail('sender', ['[npc='.$npcId.']']);
$this->extendGlobalIds(Type::NPC, $npcId);
}
}
else if ($mlr = DB::World()->selectRow('SELECT * FROM mail_level_reward WHERE `mailTemplateId` = ?d', $this->typeId)) // level rewards
{
if ($mlr['level'])
$infobox[] = Lang::game('level').Lang::main('colon').$mlr['level'];
if ($r = Lang::getRaceString($mlr['raceMask'], $rIds, Lang::FMT_MARKUP))
{
$infobox[] = Lang::game('races').Lang::main('colon').$r;
$this->extendGlobalIds(Type::CHR_RACE, ...$rIds);
}
$infobox[] = Lang::mail('sender', ['[npc='.$mlr['senderEntry'].']']);
$this->extendGlobalIds(Type::NPC, $mlr['senderEntry']);
}
else // achievement or quest
{
if ($q = DB::Aowow()->selectRow('SELECT `id`, `rewardMailDelay` FROM ?_quests WHERE `rewardMailTemplateId` = ?d', $this->typeId))
{
if ($npcId= DB::World()->selectCell('SELECT `RewardMailSenderEntry` FROM quest_mail_sender WHERE `QuestId` = ?d', $q['id']))
{
$infobox[] = Lang::mail('sender', ['[npc='.$npcId.']']);
$this->extendGlobalIds(Type::NPC, $npcId);
}
else if ($npcId = DB::Aowow()->selectCell('SELECT `typeId` FROM ?_quests_startend WHERE `questId` = ?d AND `type` = ?d AND `method` & ?d', $q['id'], Type::NPC, 0x2))
{
$infobox[] = Lang::mail('sender', ['[npc='.$npcId.']']);
$this->extendGlobalIds(Type::NPC, $npcId);
}
if ($q['rewardMailDelay'] > 0)
$infobox[] = Lang::mail('delay', [Util::formatTime($q['rewardMailDelay'] * 1000)]);
}
else if ($npcId = DB::World()->selectCell('SELECT `Sender` FROM achievement_reward WHERE `MailTemplateId` = ?d', $this->typeId))
{
$infobox[] = Lang::mail('sender', ['[npc='.$npcId.']']);
$this->extendGlobalIds(Type::NPC, $npcId);
}
}
if ($infobox)
$this->infobox = new InfoboxMarkup($infobox, ['allow' => Markup::CLASS_STAFF, 'dbpage' => true], 'infobox-contents0');
/****************/
/* Main Content */
/****************/
$this->redButtons = array(
BUTTON_LINKS => ['type' => $this->type, 'typeId' => $this->typeId],
BUTTON_WOWHEAD => false
);
$this->extraText = new Markup(Util::parseHtmlText($this->subject->getField('text', true), true), ['dbpage' => true, 'allow' => Markup::CLASS_ADMIN], 'text-generic');
/**************/
/* Extra Tabs */
/**************/
$this->lvTabs = new Tabs(['parent' => "\$\$WH.ge('tabs-generic')"], 'tabsRelated', true);
// tab: attachment
if ($itemId = $this->subject->getField('attachment'))
{
$attachment = new ItemList(array(['id', $itemId]));
if (!$attachment->error)
{
$this->extendGlobalData($attachment->getJsGlobals());
$this->lvTabs->addListviewTab(new Listview(array(
'data' => $attachment->getListviewData(),
'name' => Lang::mail('attachment'),
'id' => 'attachment'
), ItemList::$brickFile));
}
}
if ($this->typeId < 0 || // used by: achievement
($acvId = DB::World()->selectCell('SELECT `ID` FROM achievement_reward WHERE `MailTemplateId` = ?d', $this->typeId)))
{
$ubAchievements = new AchievementList(array(['id', $this->typeId < 0 ? -$this->typeId : $acvId]));
if (!$ubAchievements->error)
{
$this->extendGlobalData($ubAchievements->getJsGlobals());
$this->lvTabs->addListviewTab(new Listview(array(
'data' => $ubAchievements->getListviewData(),
'id' => 'used-by-achievement'
), AchievementList::$brickFile));
}
}
else // used by: quest
{
$ubQuests = new QuestList(array(['rewardMailTemplateId', $this->typeId]));
if (!$ubQuests->error)
{
$this->extendGlobalData($ubQuests->getJsGlobals());
$this->lvTabs->addListviewTab(new Listview(array(
'data' => $ubQuests->getListviewData(),
'id' => 'used-by-quest'
), QuestList::$brickFile));
}
}
parent::generate();
}
}
?>

59
endpoints/mails/mails.php Normal file
View File

@@ -0,0 +1,59 @@
<?php
namespace Aowow;
if (!defined('AOWOW_REVISION'))
die('illegal access');
class MailsBaseResponse extends TemplateResponse implements ICache
{
use TrListPage, TrCache;
protected int $type = Type::MAIL;
protected int $cacheType = CACHE_TYPE_PAGE;
protected string $template = 'list-page-generic';
protected string $pageName = 'mails';
protected ?int $activeTab = parent::TAB_DATABASE;
protected array $breadcrumb = [0, 103];
public function __construct(string $pageParam)
{
$this->getCategoryFromUrl($pageParam);
parent::__construct($pageParam);
}
protected function generate() : void
{
$this->h1 = Util::ucFirst(Lang::game('mails'));
/**************/
/* Page Title */
/**************/
array_unshift($this->title, $this->h1);
/****************/
/* Main Content */
/****************/
$tabData = [];
$mails = new MailList();
if (!$mails->error)
$tabData['data'] = $mails->getListviewData();
$this->extendGlobalData($mails->getJsGlobals());
$this->lvTabs = new Tabs(['parent' => "\$\$WH.ge('tabs-generic')"]);
$this->lvTabs->addListviewTab(new Listview(['data' => $mails->getListviewData()], MailList::$brickFile, 'mail'));
parent::generate();
}
}
?>

View File

@@ -1,169 +0,0 @@
<?php
namespace Aowow;
if (!defined('AOWOW_REVISION'))
die('illegal access');
// menuId 103: Mail g_initPath()
// tabId 0: Database g_initHeader()
class MailPage extends GenericPage
{
use TrDetailPage;
protected $type = Type::MAIL;
protected $typeId = 0;
protected $tpl = 'detail-page-generic';
protected $path = [0, 103];
protected $tabId = 0;
protected $mode = CACHE_TYPE_PAGE;
public function __construct($pageCall, $id)
{
parent::__construct($pageCall, $id);
$this->typeId = intVal($id);
$this->subject = new MailList(array(['id', $this->typeId]));
if ($this->subject->error)
$this->notFound(lang::game('mail'), Lang::mail('notFound'));
$this->extendGlobalData($this->subject->getJSGlobals());
$this->name = Util::htmlEscape(Util::ucFirst($this->subject->getField('name', true)));
}
protected function generateContent()
{
/***********/
/* Infobox */
/***********/
$infobox = [];
// sender + delay
if ($this->typeId < 0) // def. achievement
{
if ($npcId = DB::World()->selectCell('SELECT Sender FROM achievement_reward WHERE ID = ?d', -$this->typeId))
{
$infobox[] = Lang::mail('sender').Lang::main('colon').'[npc='.$npcId.']';
$this->extendGlobalIds(Type::NPC, $npcId);
}
}
else if ($mlr = DB::World()->selectRow('SELECT * FROM mail_level_reward WHERE mailTemplateId = ?d', $this->typeId)) // level rewards
{
if ($mlr['level'])
$infobox[] = Lang::game('level').Lang::main('colon').$mlr['level'];
$rIds = [];
if ($r = Lang::getRaceString($mlr['raceMask'], $rIds, Lang::FMT_MARKUP))
{
$infobox[] = Lang::game('races').Lang::main('colon').$r;
$this->extendGlobalIds(Type::CHR_RACE, ...$rIds);
}
$infobox[] = Lang::mail('sender').Lang::main('colon').'[npc='.$mlr['senderEntry'].']';
$this->extendGlobalIds(Type::NPC, $mlr['senderEntry']);
}
else // achievement or quest
{
if ($q = DB::Aowow()->selectRow('SELECT id, rewardMailDelay FROM ?_quests WHERE rewardMailTemplateId = ?d', $this->typeId))
{
if ($npcId= DB::World()->selectCell('SELECT RewardMailSenderEntry FROM quest_mail_sender WHERE QuestId = ?d', $q['id']))
{
$infobox[] = Lang::mail('sender').Lang::main('colon').'[npc='.$npcId.']';
$this->extendGlobalIds(Type::NPC, $npcId);
}
else if ($npcId = DB::Aowow()->selectCell('SELECT typeId FROM ?_quests_startend WHERE questId = ?d AND type = ?d AND method & ?d', $q['id'], Type::NPC, 0x2))
{
$infobox[] = Lang::mail('sender').Lang::main('colon').'[npc='.$npcId.']';
$this->extendGlobalIds(Type::NPC, $npcId);
}
if ($q['rewardMailDelay'] > 0)
$infobox[] = Lang::mail('delay').Lang::main('colon').''.Util::formatTime($q['rewardMailDelay'] * 1000);
}
else if ($npcId = DB::World()->selectCell('SELECT Sender FROM achievement_reward WHERE MailTemplateId = ?d', $this->typeId))
{
$infobox[] = Lang::mail('sender').Lang::main('colon').'[npc='.$npcId.']';
$this->extendGlobalIds(Type::NPC, $npcId);
}
}
/****************/
/* Main Content */
/****************/
$this->infobox = $infobox ? '[ul][li]'.implode('[/li][li]', $infobox).'[/li][/ul]' : '';
$this->redButtons = array(
BUTTON_LINKS => ['type' => $this->type, 'typeId' => $this->typeId],
BUTTON_WOWHEAD => false
);
$this->extraText = Util::parseHtmlText($this->subject->getField('text', true), true);
/**************/
/* Extra Tabs */
/**************/
// tab: attachment
if ($itemId = $this->subject->getField('attachment'))
{
$attachment = new ItemList(array(['id', $itemId]));
if (!$attachment->error)
{
$this->extendGlobalData($attachment->getJsGlobals());
$this->lvTabs[] = [ItemList::$brickFile, array(
'data' => array_values($attachment->getListviewData()),
'name' => Lang::mail('attachment'),
'id' => 'attachment'
)];
}
}
if ($this->typeId < 0 || // used by: achievement
($acvId = DB::World()->selectCell('SELECT ID FROM achievement_reward WHERE MailTemplateId = ?d', $this->typeId)))
{
$ubAchievements = new AchievementList(array(['id', $this->typeId < 0 ? -$this->typeId : $acvId]));
if (!$ubAchievements->error)
{
$this->extendGlobalData($ubAchievements->getJsGlobals());
$this->lvTabs[] = [AchievementList::$brickFile, array(
'data' => array_values($ubAchievements->getListviewData()),
'id' => 'used-by-achievement'
)];
}
}
else if ($npcId = DB::World()->selectCell('SELECT ID FROM achievement_reward WHERE MailTemplateId = ?d', $this->typeId))
{
$infobox[] = '[Sender]: [npc='.$npcId.']';
$this->extendGlobalIds(Type::NPC, $npcId);
}
else // used by: quest
{
$ubQuests = new QuestList(array(['rewardMailTemplateId', $this->typeId]));
if (!$ubQuests->error)
{
$this->extendGlobalData($ubQuests->getJsGlobals());
$this->lvTabs[] = [QuestList::$brickFile, array(
'data' => array_values($ubQuests->getListviewData()),
'id' => 'used-by-quest'
)];
}
}
}
protected function generateTitle()
{
array_unshift($this->title, Util::ucFirst($this->subject->getField('name', true)), Util::ucFirst(Lang::game('mail')));
}
protected function generatePath() { }
}
?>

View File

@@ -1,48 +0,0 @@
<?php
namespace Aowow;
if (!defined('AOWOW_REVISION'))
die('illegal access');
// menuId 103: Mail g_initPath()
// tabid 0: Database g_initHeader()
class MailsPage extends GenericPage
{
use TrListPage;
protected $type = Type::MAIL;
protected $tpl = 'list-page-generic';
protected $path = [0, 103];
protected $tabId = 0;
protected $mode = CACHE_TYPE_PAGE;
public function __construct($pageCall, $pageParam)
{
parent::__construct($pageCall, $pageParam);
$this->name = Util::ucFirst(Lang::game('mails'));
}
protected function generateContent()
{
$tabData = [];
$mails = new MailList();
if (!$mails->error)
$tabData['data'] = array_values($mails->getListviewData());
$this->extendGlobalData($mails->getJsGlobals());
$this->lvTabs[] = [MailList::$brickFile, $tabData, 'mail'];
}
protected function generateTitle()
{
array_unshift($this->title, $this->name);
}
protected function generatePath() { }
}
?>

View File

@@ -28,17 +28,17 @@ CLISetup::registerSetup("sql", new class extends SetupScript
CLI::write('[mails] - loading data from achievement_reward');
$acvMail = DB::World()->select(
'SELECT -ar.ID, 0,
IFNULL(ar.Subject, "") AS s0, IFNULL(arl2.Subject, "") AS s2, IFNULL(arl3.Subject, "") AS s3, IFNULL(arl4.Subject, "") AS s4, IFNULL(arl6.Subject, "") AS s6, IFNULL(arl8.Subject, "") AS s8,
IFNULL(ar.Body, "") AS t0, IFNULL(arl2.Body, "") AS t2, IFNULL(arl3.Body, "") AS t3, IFNULL(arl4.Body, "") AS t4, IFNULL(arl6.Body, "") AS t6, IFNULL(arl8.Body, "") AS t8,
ItemID
'SELECT -ar.`ID`, 0,
IFNULL(ar.`Subject`, "") AS "s0", IFNULL(arl2.`Subject`, "") AS "s2", IFNULL(arl3.`Subject`, "") AS "s3", IFNULL(arl4.`Subject`, "") AS "s4", IFNULL(arl6.`Subject`, "") AS "s6", IFNULL(arl8.`Subject`, "") AS "s8",
IFNULL(ar.`Body`, "") AS "t0", IFNULL(arl2.`Body`, "") AS "t2", IFNULL(arl3.`Body`, "") AS "t3", IFNULL(arl4.`Body`, "") AS "t4", IFNULL(arl6.`Body`, "") AS "t6", IFNULL(arl8.`Body`, "") AS "t8",
`ItemID`
FROM achievement_reward ar
LEFT JOIN achievement_reward_locale arl2 ON ar.ID = arl2.ID AND arl2.Locale = "frFR"
LEFT JOIN achievement_reward_locale arl3 ON ar.ID = arl3.ID AND arl3.Locale = "deDE"
LEFT JOIN achievement_reward_locale arl4 ON ar.ID = arl4.ID AND arl4.Locale = "zhCN"
LEFT JOIN achievement_reward_locale arl6 ON ar.ID = arl6.ID AND arl6.Locale = "esES"
LEFT JOIN achievement_reward_locale arl8 ON ar.ID = arl8.ID AND arl8.Locale = "ruRU"
WHERE ar.MailTemplateID = 0 AND ar.Body <> ""'
LEFT JOIN achievement_reward_locale arl2 ON ar.`ID` = arl2.`ID` AND arl2.`Locale` = "frFR"
LEFT JOIN achievement_reward_locale arl3 ON ar.`ID` = arl3.`ID` AND arl3.`Locale` = "deDE"
LEFT JOIN achievement_reward_locale arl4 ON ar.`ID` = arl4.`ID` AND arl4.`Locale` = "zhCN"
LEFT JOIN achievement_reward_locale arl6 ON ar.`ID` = arl6.`ID` AND arl6.`Locale` = "esES"
LEFT JOIN achievement_reward_locale arl8 ON ar.`ID` = arl8.`ID` AND arl8.`Locale` = "ruRU"
WHERE ar.`MailTemplateID` = 0 AND ar.`Body` <> ""'
);
DB::Aowow()->query('INSERT INTO ?_mails VALUES (?a)', array_values($acvMail));
@@ -46,9 +46,9 @@ CLISetup::registerSetup("sql", new class extends SetupScript
CLI::write('[mails] - loading data from mail_loot_template');
// assume mails to only contain one single item, wich works for an unmodded installation
$mlt = DB::World()->selectCol('SELECT Entry AS ARRAY_KEY, Item FROM mail_loot_template');
$mlt = DB::World()->selectCol('SELECT `Entry` AS ARRAY_KEY, `Item` FROM mail_loot_template');
foreach ($mlt as $k => $v)
DB::Aowow()->query('UPDATE ?_mails SET attachment = ?d WHERE id = ?d', $v, $k);
DB::Aowow()->query('UPDATE ?_mails SET `attachment` = ?d WHERE `id` = ?d', $v, $k);
return true;
}

View File

@@ -11,7 +11,9 @@ Listview.templates.mail = {
value: 'id',
compute: function(data, td) {
if (data.id) {
$WH.ae(td, $WH.ct(data.id));
let pre = $WH.ce('pre', { style: { display: 'inline', margin: '0' }}, $WH.ct(data.id));
$WH.clickToCopy(pre);
$WH.ae(td, pre);
}
}
},
@@ -89,5 +91,12 @@ Listview.templates.mail = {
],
getItemLink: function(mail) {
return '?mail=' + mail.id;
},
onBeforeCreate : function() {
// hide duplicate id col
if (this.debug || g_user?.debug) {
let colId = this.columns.findIndex(x => x.id == 'id');
this.visibility = this.visibility.filter(x => x != colId);
}
}
}