Template/Update (Part 34)

* convert dbtype 'areatrigger'
This commit is contained in:
Sarjuuk 2025-08-13 19:23:10 +02:00
parent 3f7f522d50
commit 1672883186
6 changed files with 273 additions and 229 deletions

View file

@ -0,0 +1,141 @@
<?php
namespace Aowow;
if (!defined('AOWOW_REVISION'))
die('illegal access');
class AreatriggerBaseResponse extends TemplateResponse implements ICache
{
use TrDetailPage, TrCache;
protected int $cacheType = CACHE_TYPE_PAGE;
protected int $requiredUserGroup = U_GROUP_STAFF;
protected string $template = 'detail-page-generic';
protected string $pageName = 'areatrigger';
protected ?int $activeTab = parent::TAB_DATABASE;
protected array $breadcrumb = [0, 102];
public int $type = Type::AREATRIGGER;
public int $typeId = 0;
private AreaTriggerList $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 AreaTriggerList(array(['id', $this->typeId]));
if ($this->subject->error)
$this->generateNotFound(Lang::game('areatrigger'), Lang::areatrigger('notFound'));
$this->h1 = $this->subject->getField('name') ?: 'Areatrigger #'.$this->typeId;
$this->gPageInfo += array(
'type' => $this->type,
'typeId' => $this->typeId,
'name' => $this->h1
);
/*************/
/* Menu Path */
/*************/
$this->breadcrumb[] = $this->subject->getField('type');
/**************/
/* Page Title */
/**************/
array_unshift($this->title, $this->h1, Util::ucFirst(Lang::game('areatrigger')));
/****************/
/* Main Content */
/****************/
$_type = $this->subject->getField('type');
// get spawns
if ($spawns = $this->subject->getSpawns(SPAWNINFO_FULL))
{
$this->addDataLoader('zones');
$this->map = array(
['parent' => 'mapper-generic'], // Mapper
$spawns, // mapperData
null, // ShowOnMap
[Lang::areatrigger('foundIn')] // foundIn
);
foreach ($spawns as $areaId => $_)
$this->map[3][$areaId] = ZoneList::getName($areaId);
}
// Smart AI
if ($_type == AT_TYPE_SMART)
{
$sai = new SmartAI(SmartAI::SRC_TYPE_AREATRIGGER, $this->typeId, ['teleportTargetArea' => $this->subject->getField('areaId')]);
if ($sai->prepare())
{
$this->extendGlobalData($sai->getJSGlobals());
$this->smartAI = $sai->getMarkup();
}
}
$this->redButtons = array(
BUTTON_LINKS => false,
BUTTON_WOWHEAD => false
);
/**************/
/* Extra Tabs */
/**************/
$this->lvTabs = new Tabs(['parent' => "\$\$WH.ge('tabs-generic')"], 'tabsRelated', true);
// tab: conditions
$cnd = new Conditions();
$cnd->getBySourceEntry($this->typeId, Conditions::SRC_AREATRIGGER_CLIENT)->prepare();
if ($tab = $cnd->toListviewTab())
{
$this->extendGlobalData($cnd->getJsGlobals());
$this->lvTabs->addDataTab(...$tab);
}
if ($_type == AT_TYPE_OBJECTIVE)
{
$relQuest = new QuestList(array(['id', $this->subject->getField('quest')]));
if (!$relQuest->error)
{
$this->extendGlobalData($relQuest->getJSGlobals(GLOBALINFO_SELF | GLOBALINFO_REWARDS));
$this->lvTabs->addListviewTab(new Listview(['data' => $relQuest->getListviewData()], QuestList::$brickFile));
}
}
else if ($_type == AT_TYPE_TELEPORT)
{
$relZone = new ZoneList(array(['id', $this->subject->getField('areaId')]));
if (!$relZone->error)
$this->lvTabs->addListviewTab(new Listview(['data' => $relZone->getListviewData()], ZoneList::$brickFile));
}
else if ($_type == AT_TYPE_SCRIPT)
{
$relTrigger = new AreaTriggerList(array(['id', $this->typeId, '!'], ['name', $this->subject->getField('name')]));
if (!$relTrigger->error)
$this->lvTabs->addListviewTab(new Listview(['data' => $relTrigger->getListviewData(), 'name' => Util::ucFirst(Lang::game('areatrigger'))]), AreaTriggerList::$brickFile, 'areatrigger');
}
parent::generate();
}
}
?>

View file

@ -0,0 +1,100 @@
<?php
namespace Aowow;
if (!defined('AOWOW_REVISION'))
die('illegal access');
class AreatriggersBaseResponse extends TemplateResponse implements ICache
{
use TrListPage, TrCache;
protected int $type = Type::AREATRIGGER;
protected int $cacheType = CACHE_TYPE_PAGE;
protected int $requiredUserGroup = U_GROUP_STAFF;
protected string $template = 'areatriggers';
protected string $pageName = 'areatriggers';
protected ?int $activeTab = parent::TAB_DATABASE;
protected array $breadcrumb = [0, 102];
protected array $scripts = [[SC_JS_FILE, 'js/filters.js']];
protected array $expectedGET = ['filter' => ['filter' => FILTER_VALIDATE_REGEXP, 'options' => ['regexp' => Filter::PATTERN_PARAM]]];
protected array $validCats = [0, 1, 2, 3, 4, 5];
public function __construct(string $pageParam)
{
$this->getCategoryFromUrl($pageParam);
if (isset($this->category[0]))
$this->forward('?areatriggers&filter=ty='.$this->category[0]);
parent::__construct($pageParam);
$this->filter = new AreaTriggerListFilter($this->_get['filter'] ?? '');
$this->filterError = $this->filter->error;
}
protected function generate() : void
{
$this->h1 = Util::ucFirst(Lang::game('areatriggers'));
$this->filter->evalCriteria();
$fiForm = $this->filter->values;
/**************/
/* Page Title */
/**************/
array_unshift($this->title, $this->h1);
if (count($fiForm['ty']) == 1)
array_unshift($this->title, Lang::areatrigger('types', $fiForm['ty'][0]));
/*************/
/* Menu Path */
/*************/
if (count($fiForm['ty']) == 1)
$this->breadcrumb[] = $fiForm['ty'];
/****************/
/* Main Content */
/****************/
$this->redButtons[BUTTON_WOWHEAD] = false;
$conditions = [];
if ($_ = $this->filter->getConditions())
$conditions[] = $_;
$this->filterError = $this->filter->error; // maybe the evalX() caused something
$tabData = [];
$trigger = new AreaTriggerList($conditions, ['calcTotal' => true]);
if (!$trigger->error)
{
$tabData['data'] = $trigger->getListviewData();
// create note if search limit was exceeded; overwriting 'note' is intentional
if ($trigger->getMatches() > Cfg::get('SQL_LIMIT_DEFAULT'))
{
$tabData['note'] = sprintf(Util::$tryFilteringEntityString, $trigger->getMatches(), '"'.Lang::game('areatriggers').'"', Cfg::get('SQL_LIMIT_DEFAULT'));
$tabData['_truncated'] = 1;
}
}
$this->lvTabs = new Tabs(['parent' => "\$\$WH.ge('tabs-generic')"]);
$this->lvTabs->addListviewTab(new Listview($tabData, AreaTriggerList::$brickFile, 'areatrigger'));
parent::generate();
}
}
?>

View file

@ -1,125 +0,0 @@
<?php
namespace Aowow;
if (!defined('AOWOW_REVISION'))
die('illegal access');
// menuId 102: Areatrigger g_initPath()
// tabid 0: Database g_initHeader()
class AreaTriggerPage extends GenericPage
{
use TrDetailPage;
protected $type = Type::AREATRIGGER;
protected $typeId = 0;
protected $tpl = 'detail-page-generic';
protected $path = [0, 102];
protected $tabId = 0;
protected $mode = CACHE_TYPE_PAGE;
protected $reqUGroup = U_GROUP_STAFF;
public function __construct($pageCall, $id)
{
parent::__construct($pageCall, $id);
$this->typeId = intVal($id);
$this->subject = new AreaTriggerList(array(['id', $this->typeId]));
if ($this->subject->error)
$this->notFound(Lang::game('areatrigger'), Lang::areatrigger('notFound'));
$this->name = $this->subject->getField('name') ?: 'AT #'.$this->typeId;
}
protected function generatePath()
{
$this->path[] = $this->subject->getField('type');
}
protected function generateTitle()
{
array_unshift($this->title, $this->name, Util::ucFirst(Lang::game('areatrigger')));
}
protected function generateContent()
{
$this->addScript([SC_JS_FILE, '?data=zones']);
$_type = $this->subject->getField('type');
/****************/
/* Main Content */
/****************/
// get spawns
$map = null;
if ($spawns = $this->subject->getSpawns(SPAWNINFO_FULL))
{
$map = ['data' => ['parent' => 'mapper-generic'], 'mapperData' => &$spawns, 'foundIn' => Lang::areatrigger('foundIn')];
foreach ($spawns as $areaId => &$areaData)
$map['extra'][$areaId] = ZoneList::getName($areaId);
}
// smart AI
$sai = null;
if ($_type == AT_TYPE_SMART)
{
$sai = new SmartAI(SmartAI::SRC_TYPE_AREATRIGGER, $this->typeId, ['teleportTargetArea' => $this->subject->getField('areaId')]);
if ($sai->prepare())
$this->extendGlobalData($sai->getJSGlobals());
}
$this->map = $map;
$this->infobox = false;
$this->smartAI = $sai?->getMarkup();
$this->redButtons = array(
BUTTON_LINKS => false,
BUTTON_WOWHEAD => false
);
/**************/
/* Extra Tabs */
/**************/
// tab: conditions
$cnd = new Conditions();
$cnd->getBySourceEntry($this->typeId, Conditions::SRC_AREATRIGGER_CLIENT)->prepare();
if ($tab = $cnd->toListviewTab())
{
$this->extendGlobalData($cnd->getJsGlobals());
$this->lvTabs[] = $tab;
}
if ($_type == AT_TYPE_OBJECTIVE)
{
$relQuest = new QuestList(array(['id', $this->subject->getField('quest')]));
if (!$relQuest->error)
{
$this->extendGlobalData($relQuest->getJSGlobals(GLOBALINFO_SELF | GLOBALINFO_REWARDS));
$this->lvTabs[] = [QuestList::$brickFile, ['data' => array_values($relQuest->getListviewData())]];
}
}
else if ($_type == AT_TYPE_TELEPORT)
{
$relZone = new ZoneList(array(['id', $this->subject->getField('areaId')]));
if (!$relZone->error)
{
$this->lvTabs[] = [ZoneList::$brickFile, ['data' => array_values($relZone->getListviewData())]];
}
}
else if ($_type == AT_TYPE_SCRIPT)
{
$relTrigger = new AreaTriggerList(array(['id', $this->typeId, '!'], ['name', $this->subject->getField('name')]));
if (!$relTrigger->error)
{
$this->lvTabs[] = [AreaTriggerList::$brickFile, ['data' => array_values($relTrigger->getListviewData()), 'name' => Util::ucFirst(Lang::game('areatrigger'))], 'areatrigger'];
}
}
}
}
?>

View file

@ -1,85 +0,0 @@
<?php
namespace Aowow;
if (!defined('AOWOW_REVISION'))
die('illegal access');
// menuId 102: Areatrigger g_initPath()
// tabid 0: Database g_initHeader()
class AreaTriggersPage extends GenericPage
{
use TrListPage;
protected $type = Type::AREATRIGGER;
protected $tpl = 'areatriggers';
protected $path = [0, 102];
protected $tabId = 0;
protected $mode = CACHE_TYPE_PAGE;
protected $validCats = [0, 1, 2, 3, 4, 5];
protected $scripts = [[SC_JS_FILE, 'js/filters.js']];
protected $reqUGroup = U_GROUP_STAFF;
protected $_get = ['filter' => ['filter' => FILTER_UNSAFE_RAW]];
public function __construct($pageCall, $pageParam)
{
$this->getCategoryFromUrl($pageParam);
if (isset($this->category[0]))
header('Location: ?areatriggers&filter=ty='.$this->category[0], true, 302);
parent::__construct($pageCall, $pageParam);
$this->filterObj = new AreaTriggerListFilter($this->_get['filter'] ?? '');
$this->name = Util::ucFirst(Lang::game('areatriggers'));
}
protected function generateContent()
{
$this->filterObj->evalCriteria();
$conditions = [];
if ($_ = $this->filterObj->getConditions())
$conditions[] = $_;
$tabData = [];
$trigger = new AreaTriggerList($conditions, ['calcTotal' => true]);
if (!$trigger->error)
{
$tabData['data'] = array_values($trigger->getListviewData());
// create note if search limit was exceeded; overwriting 'note' is intentional
if ($trigger->getMatches() > Cfg::get('SQL_LIMIT_DEFAULT'))
{
$tabData['note'] = sprintf(Util::$tryFilteringEntityString, $trigger->getMatches(), '"'.Lang::game('areatriggers').'"', Cfg::get('SQL_LIMIT_DEFAULT'));
$tabData['_truncated'] = 1;
}
if ($this->filterObj->error)
$tabData['_errors'] = 1;
}
$this->lvTabs[] = [AreaTriggerList::$brickFile, $tabData, 'areatrigger'];
}
protected function generateTitle()
{
array_unshift($this->title, $this->name);
$form = $this->filterObj->values;
if (count($form['ty']) == 1)
array_unshift($this->title, Lang::areatrigger('types', $form['ty'][0]));
}
protected function generatePath()
{
$form = $this->filterObj->values;
if (count($form['ty']) == 1)
$this->path[] = $form['ty'];
}
}
?>

View file

@ -11,7 +11,9 @@ Listview.templates.areatrigger = {
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);
}
}
},
@ -75,5 +77,12 @@ Listview.templates.areatrigger = {
],
getItemLink: function(areatrigger) {
return '?areatrigger=' + areatrigger.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);
}
}
}

View file

@ -1,10 +1,11 @@
<?php namespace Aowow; ?>
<?php
$this->brick('header');
$f = $this->filterObj->values // shorthand
?>
namespace Aowow\Template;
use \Aowow\Lang;
$this->brick('header');
$f = $this->filter->values; // shorthand
?>
<div class="main" id="main">
<div class="main-precontents" id="main-precontents"></div>
<div class="main-contents" id="main-contents">
@ -12,29 +13,32 @@ $f = $this->filterObj->values // shorthand
<?php
$this->brick('announcement');
$this->brick('pageTemplate', ['fiQuery' => $this->filterObj->query, 'fiMenuItem' => [101]]);
$this->brick('pageTemplate', ['fiQuery' => $this->filter->query, 'fiMenuItem' => [102]]);
?>
<div class="text"><h1><?=$this->name; ?>&nbsp;<?=$this->brick('redButtons'); ?></h1></div>
<div id="fi" style="display: <?=($this->filterObj->query ? 'block' : 'none'); ?>;">
<div id="fi" style="display: <?=($this->filter->query ? 'block' : 'none'); ?>;">
<form action="?filter=areatriggers" method="post" name="fi" onsubmit="return fi_submit(this)" onreset="return fi_reset(this)">
<div class="text">
<?php
$this->brick('headIcons');
$this->brick('redButtons');
?>
<h1><?=$this->h1; ?></h1>
</div>
<div class="rightpanel">
<div style="float: left"><?=Util::ucFirst(Lang::game('type')).Lang::main('colon'); ?></div>
<div style="float: left"><?=Lang::game('type').Lang::main('colon'); ?></div>
<small><a href="javascript:;" onclick="document.forms['fi'].elements['ty[]'].selectedIndex = -1; return false" onmousedown="return false"><?=Lang::main('clear'); ?></a></small>
<div class="clear"></div>
<select name="ty[]" size="6" multiple="multiple" class="rightselect">
<?php
foreach (Lang::areatrigger('types') as $i => $str):
echo ' <option value="'.$i.'"'.(isset($f['ty']) && in_array($i, (array)$f['ty']) ? ' selected' : null).' >'.$str."</option>\n";
endforeach;
?>
<?=$this->makeOptionsList(Lang::areatrigger('types'), $f['ty'] ?? [], 28); ?>
</select>
</div>
<table>
<tr>
<td><?=Util::ucFirst(Lang::main('name')).Lang::main('colon'); ?></td>
<td><?=$this->ucFirst(Lang::main('name')).Lang::main('colon'); ?></td>
<td colspan="2">
<table><tr>
<td>&nbsp;<input type="text" name="na" size="30" <?=(isset($f['na']) ? 'value="'.Util::htmlEscape($f['na']).'" ' : null); ?>/></td>
<td>&nbsp;<input type="text" name="na" size="30" <?=($f['na'] ? 'value="'.$this->escHTML($f['na']).'" ' : ''); ?>/></td>
</tr></table>
</td>
</tr><tr>
@ -43,7 +47,7 @@ endforeach;
<div id="fi_criteria" class="padded criteria"><div></div></div><div><a href="javascript:;" id="fi_addcriteria" onclick="fi_addCriterion(this); return false"><?=Lang::main('addFilter'); ?></a></div>
<div class="padded2">
<?=Lang::main('match').Lang::main('colon'); ?><input type="radio" name="ma" value="" id="ma-0" <?=(!isset($f['ma']) ? 'checked="checked" ' : null); ?>/><label for="ma-0"><?=Lang::main('allFilter'); ?></label><input type="radio" name="ma" value="1" id="ma-1" <?=(isset($f['ma']) ? 'checked="checked" ' : null); ?> /><label for="ma-1"><?=Lang::main('oneFilter'); ?></label>
<?=Lang::main('match'); ?><input type="radio" name="ma" value="" id="ma-0" <?=(!$f['ma'] ? 'checked="checked" ' : ''); ?>/><label for="ma-0"><?=Lang::main('allFilter'); ?></label><input type="radio" name="ma" value="1" id="ma-1" <?=($f['ma'] ? 'checked="checked" ' : ''); ?> /><label for="ma-1"><?=Lang::main('oneFilter'); ?></label>
</div>
<div class="clear"></div>
@ -57,7 +61,7 @@ endforeach;
</div>
<div class="pad clear"></div>
<?php $this->brick('filter'); ?>
<?=$this->renderFilter(12); ?>
<?php $this->brick('lvTabs'); ?>