diff --git a/endpoints/areatrigger/areatrigger.php b/endpoints/areatrigger/areatrigger.php new file mode 100644 index 00000000..b0ce07ca --- /dev/null +++ b/endpoints/areatrigger/areatrigger.php @@ -0,0 +1,141 @@ +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(); + } +} + +?> diff --git a/endpoints/areatriggers/areatriggers.php b/endpoints/areatriggers/areatriggers.php new file mode 100644 index 00000000..04b06d46 --- /dev/null +++ b/endpoints/areatriggers/areatriggers.php @@ -0,0 +1,100 @@ + ['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(); + } +} + +?> diff --git a/pages/areatrigger.php b/pages/areatrigger.php deleted file mode 100644 index ecae884d..00000000 --- a/pages/areatrigger.php +++ /dev/null @@ -1,125 +0,0 @@ -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']; - } - } - } -} - -?> diff --git a/pages/areatriggers.php b/pages/areatriggers.php deleted file mode 100644 index 7c32bd24..00000000 --- a/pages/areatriggers.php +++ /dev/null @@ -1,85 +0,0 @@ - ['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']; - } -} - -?> diff --git a/template/listviews/areatrigger.tpl b/template/listviews/areatrigger.tpl index c9ee2816..0a428c0b 100644 --- a/template/listviews/areatrigger.tpl +++ b/template/listviews/areatrigger.tpl @@ -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); + } } } diff --git a/template/pages/areatriggers.tpl.php b/template/pages/areatriggers.tpl.php index 5709d0e3..3f187918 100644 --- a/template/pages/areatriggers.tpl.php +++ b/template/pages/areatriggers.tpl.php @@ -1,10 +1,11 @@ - - brick('header'); -$f = $this->filterObj->values // shorthand -?> + namespace Aowow\Template; + use \Aowow\Lang; + +$this->brick('header'); +$f = $this->filter->values; // shorthand +?>