diff --git a/endpoints/event/event.php b/endpoints/event/event.php new file mode 100644 index 00000000..5e1530b8 --- /dev/null +++ b/endpoints/event/event.php @@ -0,0 +1,337 @@ +typeId = intVal($id); + $this->contribute = Type::getClassAttrib($this->type, 'contribute') ?? CONTRIBUTE_NONE; + } + + protected function generate() : void + { + $this->subject = new WorldEventList(array(['id', $this->typeId])); + if ($this->subject->error) + $this->generateNotFound(Lang::game('event'), Lang::event('notFound')); + + $this->h1 = $this->subject->getField('name', true); + $this->dates = array( + 'firstDate' => $this->subject->getField('startTime'), + 'lastDate' => $this->subject->getField('endTime'), + 'length' => $this->subject->getField('length'), + 'rec' => $this->subject->getField('occurence') + ); + + $this->gPageInfo += array( + 'type' => $this->type, + 'typeId' => $this->typeId, + 'name' => $this->h1 + ); + + $_holidayId = $this->subject->getField('holidayId'); + + + /*************/ + /* Menu Path */ + /*************/ + + $this->breadcrumb[] = match ($this->subject->getField('scheduleType')) + { + -1 => 1, + 0, 1 => 2, + 2 => 3, + '' => 0, + default => 0 + }; + + + /**************/ + /* Page Title */ + /**************/ + + array_unshift($this->title, $this->h1, Util::ucWords(Lang::game('event'))); + + + /***********/ + /* Infobox */ + /***********/ + + $infobox = Lang::getInfoBoxForFlags($this->subject->getField('cuFlags')); + + // boss + if ($_ = $this->subject->getField('bossCreature')) + { + $this->extendGlobalIds(Type::NPC, $_); + $infobox[] = Lang::npc('rank', 3).Lang::main('colon').'[npc='.$_.']'; + } + + // display internal id to staff + if (User::isInGroup(U_GROUP_STAFF)) + $infobox[] = 'Event-Id'.Lang::main('colon').$this->typeId; + + if ($infobox) + $this->infobox = new InfoboxMarkup($infobox, ['allow' => Markup::CLASS_STAFF, 'dbpage' => true], 'infobox-contents0'); + + + /****************/ + /* Main Content */ + /****************/ + + // no entry in ?_articles? use default HolidayDescription + if ($_holidayId && empty($this->article)) + $this->article = new Markup($this->subject->getField('description', true), ['dbpage' => true]); + + if ($_holidayId) + $this->wowheadLink = sprintf(WOWHEAD_LINK, Lang::getLocale()->domain(), 'event=', $_holidayId); + + $this->headIcons = [$this->subject->getField('iconString')]; + $this->redButtons = array( + BUTTON_WOWHEAD => $_holidayId > 0, + BUTTON_LINKS => ['type' => $this->type, 'typeId' => $this->typeId] + ); + + parent::generate(); + + + /**************/ + /* Extra Tabs */ + /**************/ + + $this->lvTabs = new Tabs(['parent' => "\$\$WH.ge('tabs-generic')"], 'tabsRelated', true); + + // tab: npcs + if ($npcIds = DB::World()->selectCol('SELECT `id` AS ARRAY_KEY, IF(ec.`eventEntry` > 0, 1, 0) AS "added" FROM creature c, game_event_creature ec WHERE ec.`guid` = c.`guid` AND ABS(ec.`eventEntry`) = ?d', $this->typeId)) + { + $creatures = new CreatureList(array(['id', array_keys($npcIds)])); + if (!$creatures->error) + { + $data = $creatures->getListviewData(); + foreach ($data as &$d) + $d['method'] = $npcIds[$d['id']]; + + $tabData = ['data' => $data]; + + if ($_holidayId && CreatureListFilter::getCriteriaIndex(38, $_holidayId)) + $tabData['note'] = sprintf(Util::$filterResultString, '?npcs&filter=cr=38;crs='.$_holidayId.';crv=0'); + + $this->result->addDataLoader('zones'); // req. by secondary tooltip in this tab + $this->lvTabs->addListviewTab(new Listview($tabData, CreatureList::$brickFile)); + } + } + + // tab: objects + if ($objectIds = DB::World()->selectCol('SELECT `id` AS ARRAY_KEY, IF(eg.`eventEntry` > 0, 1, 0) AS "added" FROM gameobject g, game_event_gameobject eg WHERE eg.`guid` = g.`guid` AND ABS(eg.`eventEntry`) = ?d', $this->typeId)) + { + $objects = new GameObjectList(array(['id', array_keys($objectIds)])); + if (!$objects->error) + { + $data = $objects->getListviewData(); + foreach ($data as &$d) + $d['method'] = $objectIds[$d['id']]; + + $tabData = ['data' => $data]; + + if ($_holidayId && GameObjectListFilter::getCriteriaIndex(16, $_holidayId)) + $tabData['note'] = sprintf(Util::$filterResultString, '?objects&filter=cr=16;crs='.$_holidayId.';crv=0'); + + $this->result->addDataLoader('zones'); // req. by secondary tooltip in this tab + $this->lvTabs->addListviewTab(new Listview($tabData, GameObjectList::$brickFile)); + } + } + + // tab: achievements + if ($_ = $this->subject->getField('achievementCatOrId')) + { + $condition = $_ > 0 ? [['category', $_]] : [['id', -$_]]; + $acvs = new AchievementList($condition); + if (!$acvs->error) + { + $this->extendGlobalData($acvs->getJSGlobals(GLOBALINFO_SELF | GLOBALINFO_RELATED)); + + $tabData = array( + 'data' => $acvs->getListviewData(), + 'visibleCols' => ['category'] + ); + + if ($_holidayId && AchievementListFilter::getCriteriaIndex(11, $_holidayId)) + $tabData['note'] = sprintf(Util::$filterResultString, '?achievements&filter=cr=11;crs='.$_holidayId.';crv=0'); + + $this->lvTabs->addListviewTab(new Listview($tabData, AchievementList::$brickFile)); + } + } + + $itemCnd = []; + if ($_holidayId) + { + $itemCnd = array( + 'OR', + ['eventId', $this->typeId], // direct requirement on item + ); + + // tab: quests (by table, go & creature) + $quests = new QuestList(array(['eventId', $this->typeId])); + if (!$quests->error) + { + $this->extendGlobalData($quests->getJSGlobals(GLOBALINFO_SELF | GLOBALINFO_REWARDS)); + + $tabData = ['data'=> $quests->getListviewData()]; + + if (QuestListFilter::getCriteriaIndex(33, $_holidayId)) + $tabData['note'] = sprintf(Util::$filterResultString, '?quests&filter=cr=33;crs='.$_holidayId.';crv=0'); + + $this->lvTabs->addListviewTab(new Listview($tabData, QuestList::$brickFile)); + + $questItems = []; + foreach (array_column($quests->rewards, Type::ITEM) as $arr) + $questItems = array_merge($questItems, array_keys($arr)); + + foreach (array_column($quests->choices, Type::ITEM) as $arr) + $questItems = array_merge($questItems, array_keys($arr)); + + foreach (array_column($quests->requires, Type::ITEM) as $arr) + $questItems = array_merge($questItems, $arr); + + if ($questItems) + $itemCnd[] = ['id', $questItems]; + } + } + + // items from creature + if ($npcIds && !$creatures->error) + { + // vendor + $cIds = $creatures->getFoundIDs(); + if ($sells = DB::World()->selectCol( + 'SELECT `item` FROM npc_vendor nv WHERE `entry` IN (?a) UNION + SELECT nv1.`item` FROM npc_vendor nv1 JOIN npc_vendor nv2 ON -nv1.`entry` = nv2.`item` WHERE nv2.`entry` IN (?a) UNION + SELECT `item` FROM game_event_npc_vendor genv JOIN creature c ON genv.`guid` = c.`guid` WHERE c.`id` IN (?a)', + $cIds, $cIds, $cIds + )) + $itemCnd[] = ['id', $sells]; + } + + // tab: items + // not checking for loot ... cant distinguish between eventLoot and fillerCrapLoot + if ($itemCnd) + { + $eventItems = new ItemList($itemCnd); + if (!$eventItems->error) + { + $this->extendGlobalData($eventItems->getJSGlobals(GLOBALINFO_SELF)); + + $tabData = ['data'=> $eventItems->getListviewData()]; + + if ($_holidayId && ItemListFilter::getCriteriaIndex(160, $_holidayId)) + $tabData['note'] = sprintf(Util::$filterResultString, '?items&filter=cr=160;crs='.$_holidayId.';crv=0'); + + $this->lvTabs->addListviewTab(new Listview($tabData, ItemList::$brickFile)); + } + } + + // tab: see also (event conditions) + if ($rel = DB::World()->selectCol('SELECT IF(`eventEntry` = `prerequisite_event`, NULL, IF(`eventEntry` = ?d, `prerequisite_event`, -`eventEntry`)) FROM game_event_prerequisite WHERE `prerequisite_event` = ?d OR `eventEntry` = ?d', $this->typeId, $this->typeId, $this->typeId)) + { + if (array_filter($rel, fn($x) => $x === null)) + trigger_error('game_event_prerequisite: this event has itself as prerequisite', E_USER_WARNING); + + if ($seeAlso = array_filter($rel, fn($x) => $x > 0)) + { + $relEvents = new WorldEventList(array(['id', $seeAlso])); + $this->extendGlobalData($relEvents->getJSGlobals()); + $relData = $relEvents->getListviewData(); + foreach ($relEvents->getFoundIDs() as $id) + Conditions::extendListviewRow($relData[$id], Conditions::SRC_NONE, $this->typeId, [-Conditions::ACTIVE_EVENT, $this->typeId]); + + $this->extendGlobalData($this->subject->getJSGlobals()); + $d = $this->subject->getListviewData(); + foreach ($rel as $r) + if ($r > 0) + if (Conditions::extendListviewRow($d[$this->typeId], Conditions::SRC_NONE, $this->typeId, [-Conditions::ACTIVE_EVENT, $r])) + $this->extendGlobalIds(Type::WORLDEVENT, $r); + + $tabData = array( + 'data' => array_merge($relData, $d), + 'id' => 'see-also', + 'name' => '$LANG.tab_seealso', + 'hiddenCols' => ['date'], + 'extraCols' => ['$Listview.extraCols.condition'] + ); + $this->lvTabs->addListviewTab(new Listview($tabData, WorldEventList::$brickFile)); + } + } + + // tab: condition for + $cnd = new Conditions(); + $cnd->getByCondition(Type::WORLDEVENT, $this->typeId)->prepare(); + if ($tab = $cnd->toListviewTab('condition-for', '$LANG.tab_condition_for')) + { + $this->extendGlobalData($cnd->getJsGlobals()); + $this->lvTabs->addDataTab(...$tab); + } + + $this->result->registerDisplayHook('lvTabs', [self::class, 'tabsHook']); + $this->result->registerDisplayHook('infobox', [self::class, 'infoboxHook']); + } + + // update dates to now() + public static function tabsHook(Template\PageTemplate &$pt, Tabs &$lvTabs) : void + { + foreach ($lvTabs->iterate() as &$listview) + if (is_object($listview) && $listview?->getTemplate() == 'holiday') + WorldEventList::updateListview($listview); + } + + /* finalize infobox */ + public static function infoboxHook(Template\PageTemplate &$pt, ?InfoboxMarkup &$markup) : void + { + WorldEventList::updateDates($pt->dates, $start, $end, $rec); + $infobox = []; + + // start + if ($start) + $infobox[] = Lang::event('start').date(Lang::main('dateFmtLong'), $start); + + // end + if ($end) + $infobox[] = Lang::event('end').date(Lang::main('dateFmtLong'), $end); + + // interval + if ($rec > 0) + $infobox[] = Lang::event('interval').Util::formatTime($rec * 1000); + + // in progress + if ($start < time() && $end > time()) + $infobox[] = '[span class=q2]'.Lang::event('inProgress').'[/span]'; + + if ($infobox && !$markup) + $markup = new InfoboxMarkup($infobox, ['allow' => Markup::CLASS_STAFF, 'dbpage' => true], 'infobox-contents0'); + else if ($markup) + foreach ($infobox as $ib) + $markup->addItem($ib); + } +} + +?> diff --git a/endpoints/event/event_power.php b/endpoints/event/event_power.php new file mode 100644 index 00000000..48c75683 --- /dev/null +++ b/endpoints/event/event_power.php @@ -0,0 +1,79 @@ + ['filter' => FILTER_CALLBACK, 'options' => [Locale::class, 'tryFromDomain']] + ); + + private array $dates = []; + + public function __construct(string $id) + { + parent::__construct($id); + + // temp locale + if ($this->_get['domain']) + Lang::load($this->_get['domain']); + + $this->typeId = intVal($id); + } + + protected function generate() : void + { + $worldevent = new WorldEventList(array(['id', $this->typeId])); + if ($worldevent->error) + $this->cacheType = CACHE_TYPE_NONE; + else + { + $icon = $worldevent->getField('iconString'); + if ($icon == 'trade_engineering') + $icon = null; + + $opts = array( + 'name' => $worldevent->getField('name', true), + 'tooltip' => $worldevent->renderTooltip(), + 'icon' => $icon + ); + + $this->dates = array( + 'firstDate' => $worldevent->getField('startTime'), + 'lastDate' => $worldevent->getField('endTime'), + 'length' => $worldevent->getField('length'), + 'rec' => $worldevent->getField('occurence') + ); + + $this->setOnCacheLoaded([self::class, 'onBeforeDisplay'], $this->dates); + } + + $this->result = new Tooltip(self::POWER_TEMPLATE, $this->typeId, $opts ?? []); + } + + public static function onBeforeDisplay(string $tooltip, array $dates) : string + { + // update dates to now() + WorldEventList::updateDates($dates, $start, $end); + + return sprintf( + $tooltip, + $start ? date(Lang::main('dateFmtLong'), $start) : null, + $end ? date(Lang::main('dateFmtLong'), $end) : null + ); + } +} + +?> diff --git a/endpoints/events/events.php b/endpoints/events/events.php new file mode 100644 index 00000000..2ae4a9b9 --- /dev/null +++ b/endpoints/events/events.php @@ -0,0 +1,96 @@ +getCategoryFromUrl($pageParam); + + parent::__construct($pageParam); + } + + protected function generate() : void + { + $this->h1 = Util::ucWords(Lang::game('events')); + + + /**************/ + /* Page Title */ + /**************/ + + array_unshift($this->title, $this->h1); + if ($this->category) + array_unshift($this->title, Lang::event('category')[$this->category[0]]); + + + /*************/ + /* Menu Path */ + /*************/ + + if ($this->category) + $this->breadcrumb[] = $this->category[0]; + + + /****************/ + /* Main Content */ + /****************/ + + $this->redButtons[BUTTON_WOWHEAD] = true; + + $condition = []; + + if (!User::isInGroup(U_GROUP_EMPLOYEE)) + $condition[] = [['cuFlags', CUSTOM_EXCLUDE_FOR_LISTVIEW, '&'], 0]; + + if ($this->category) + $condition[] = match ($this->category[0]) + { + 1 => ['h.scheduleType', -1], + 2 => ['h.scheduleType', [0, 1]], + 3 => ['h.scheduleType', 2], + default => ['e.holidayId', 0] // also cat 0 + }; + + $events = new WorldEventList($condition); + $this->extendGlobalData($events->getJSGlobals()); + + $this->lvTabs = new Tabs(['parent' => "\$\$WH.ge('tabs-generic')"]); + + $this->lvTabs->addListviewTab(new Listview(['data' => $events->getListviewData()], WorldEventList::$brickFile)); + + if ($_ = array_filter($events->getListviewData(), fn($x) => $x['category'] > 0)) + $this->lvTabs->addListviewTab(new Listview(['data' => $_, 'hideCount' => 1], 'calendar')); + + parent::generate(); + + $this->result->registerDisplayHook('lvTabs', [self::class, 'tabsHook']); + } + + // recalculate dates with now() + public static function tabsHook(Template\PageTemplate &$pt, Tabs &$lvTabs) : void + { + foreach ($lvTabs->iterate() as &$listview) + if (is_object($listview) && ($listview?->getTemplate() == 'holiday' || $listview?->getTemplate() == 'holidaycal')) + WorldEventList::updateListview($listview); + } +} + +?> diff --git a/includes/dbtypes/worldevent.class.php b/includes/dbtypes/worldevent.class.php index 18ba67c6..831b57c3 100644 --- a/includes/dbtypes/worldevent.class.php +++ b/includes/dbtypes/worldevent.class.php @@ -113,7 +113,7 @@ class WorldEventList extends DBTypeList } } - public function getListviewData(bool $forNow = false) : array + public function getListviewData() : array { $data = []; @@ -132,15 +132,6 @@ class WorldEventList extends DBTypeList ); } - if ($forNow) - { - foreach ($data as &$d) - { - self::updateDates($d['_date'], $d['startDate'], $d['endDate'], $d['rec']); - unset($d['_date']); - } - } - return $data; } diff --git a/localization/locale_dede.php b/localization/locale_dede.php index ccf542bb..9369227d 100644 --- a/localization/locale_dede.php +++ b/localization/locale_dede.php @@ -1137,7 +1137,7 @@ $lang = array( 'notFound' => "Dieses Weltereignis existiert nicht.", 'start' => "Anfang: ", 'end' => "Ende: ", - 'interval' => "Intervall", + 'interval' => "Intervall: ", 'inProgress' => "Ereignis findet gerade statt", 'category' => ["Nicht kategorisiert", "Feiertage", "Wiederkehrend", "Spieler vs. Spieler"] ), diff --git a/localization/locale_enus.php b/localization/locale_enus.php index e250a297..4628acc2 100644 --- a/localization/locale_enus.php +++ b/localization/locale_enus.php @@ -1137,7 +1137,7 @@ $lang = array( 'notFound' => "This world event doesn't exist.", 'start' => "Start: ", 'end' => "End: ", - 'interval' => "Interval", + 'interval' => "Interval: ", 'inProgress' => "Event is currently in progress", 'category' => ["Uncategorized", "Holidays", "Recurring", "Player vs. Player"] ), diff --git a/localization/locale_eses.php b/localization/locale_eses.php index b38316b9..82ba9a10 100644 --- a/localization/locale_eses.php +++ b/localization/locale_eses.php @@ -1137,7 +1137,7 @@ $lang = array( 'notFound' => "Este evento del mundo no existe.", 'start' => "Empieza: ", 'end' => "Termina: ", - 'interval' => "Intervalo", + 'interval' => "Intervalo: ", 'inProgress' => "El evento está en progreso actualmente", 'category' => ["Sin categoría", "Vacacionales", "Periódicos", "Jugador contra Jugador"] ), diff --git a/localization/locale_frfr.php b/localization/locale_frfr.php index bf728dd6..96e90a94 100644 --- a/localization/locale_frfr.php +++ b/localization/locale_frfr.php @@ -1137,7 +1137,7 @@ $lang = array( 'notFound' => "Cet évènement mondial n'existe pas.", 'start' => "Début : ", 'end' => "Fin : ", - 'interval' => "Intervalle", + 'interval' => "Intervalle : ", 'inProgress' => "L'évènement est présentement en cours", 'category' => ["Non classés", "Vacances", "Récurrent", "Joueur ctr. Joueur"] ), diff --git a/localization/locale_ruru.php b/localization/locale_ruru.php index 8adbaec2..930b776a 100644 --- a/localization/locale_ruru.php +++ b/localization/locale_ruru.php @@ -1137,7 +1137,7 @@ $lang = array( 'notFound' => "Это игровое событие не существует.", 'start' => "Начало: ", 'end' => "Конец: ", - 'interval' => "[Interval]", + 'interval' => "[Interval]: ", 'inProgress' => "Событие активно в данный момент", 'category' => array("Разное", "Праздники", "Периодические", "PvP") ), diff --git a/localization/locale_zhcn.php b/localization/locale_zhcn.php index 0ea4e318..a5c5912c 100644 --- a/localization/locale_zhcn.php +++ b/localization/locale_zhcn.php @@ -1136,7 +1136,7 @@ $lang = array( 'notFound' => "这个世界事件不存在。", 'start' => "开始:", 'end' => "结束:", - 'interval' => "间隔", + 'interval' => "间隔:", 'inProgress' => "事件正在进行中", 'category' => ["未分类", "节日", "循环", "PvP"] ), diff --git a/pages/event.php b/pages/event.php deleted file mode 100644 index 2af3aefb..00000000 --- a/pages/event.php +++ /dev/null @@ -1,365 +0,0 @@ - ['filter' => FILTER_CALLBACK, 'options' => 'Aowow\Locale::tryFromDomain']]; - - private $powerTpl = '$WowheadPower.registerHoliday(%d, %d, %s);'; - private $hId = 0; - private $eId = 0; - - public function __construct($pageCall, $id) - { - parent::__construct($pageCall, $id); - - // temp locale - if ($this->mode == CACHE_TYPE_TOOLTIP && $this->_get['domain']) - Lang::load($this->_get['domain']); - - $this->typeId = intVal($id); - - $this->subject = new WorldEventList(array(['id', $this->typeId])); - if ($this->subject->error) - $this->notFound(Lang::game('event'), Lang::event('notFound')); - - $this->hId = $this->subject->getField('holidayId'); - $this->eId = $this->typeId; - $this->name = $this->subject->getField('name', true); - $this->dates = array( - 'firstDate' => $this->subject->getField('startTime'), - 'lastDate' => $this->subject->getField('endTime'), - 'length' => $this->subject->getField('length'), - 'rec' => $this->subject->getField('occurence') - ); - } - - protected function generatePath() - { - switch ($this->subject->getField('scheduleType')) - { - case '': $this->path[] = 0; break; - case -1: $this->path[] = 1; break; - case 0: - case 1: $this->path[] = 2; break; - case 2: $this->path[] = 3; break; - } - } - - protected function generateTitle() - { - array_unshift($this->title, $this->subject->getField('name', true), Util::ucFirst(Lang::game('event'))); - } - - protected function generateContent() - { - $this->addScript([SC_JS_FILE, '?data=zones']); - - /***********/ - /* Infobox */ - /***********/ - - $this->infobox = Lang::getInfoBoxForFlags($this->subject->getField('cuFlags')); - - // boss - if ($_ = $this->subject->getField('bossCreature')) - { - $this->extendGlobalIds(Type::NPC, $_); - $this->infobox[] = Lang::npc('rank', 3).Lang::main('colon').'[npc='.$_.']'; - } - - // display internal id to staff - if (User::isInGroup(U_GROUP_STAFF)) - $this->infobox[] = 'Event-Id'.Lang::main('colon').$this->eId; - - /****************/ - /* Main Content */ - /****************/ - - // no entry in ?_articles? use default HolidayDescription - if ($this->hId && empty($this->article)) - $this->article = ['text' => Util::jsEscape($this->subject->getField('description', true)), 'params' => []]; - - $this->headIcons = [$this->subject->getField('iconString')]; - $this->redButtons = array( - BUTTON_WOWHEAD => $this->hId > 0, - BUTTON_LINKS => ['type' => $this->type, 'typeId' => $this->typeId] - ); - - /**************/ - /* Extra Tabs */ - /**************/ - - $hasFilter = in_array($this->hId, [372, 283, 285, 353, 420, 400, 284, 201, 374, 409, 141, 324, 321, 424, 335, 327, 341, 181, 404, 398, 301]); - - // tab: npcs - if ($npcIds = DB::World()->selectCol('SELECT id AS ARRAY_KEY, IF(ec.eventEntry > 0, 1, 0) AS added FROM creature c, game_event_creature ec WHERE ec.guid = c.guid AND ABS(ec.eventEntry) = ?d', $this->eId)) - { - $creatures = new CreatureList(array(['id', array_keys($npcIds)])); - if (!$creatures->error) - { - $data = $creatures->getListviewData(); - foreach ($data as &$d) - $d['method'] = $npcIds[$d['id']]; - - $tabData = ['data' => array_values($data)]; - - if ($hasFilter) - $tabData['note'] = sprintf(Util::$filterResultString, '?npcs&filter=cr=38;crs='.$this->hId.';crv=0'); - - $this->lvTabs[] = [CreatureList::$brickFile, $tabData]; - } - } - - // tab: objects - if ($objectIds = DB::World()->selectCol('SELECT id AS ARRAY_KEY, IF(eg.eventEntry > 0, 1, 0) AS added FROM gameobject g, game_event_gameobject eg WHERE eg.guid = g.guid AND ABS(eg.eventEntry) = ?d', $this->eId)) - { - $objects = new GameObjectList(array(['id', array_keys($objectIds)])); - if (!$objects->error) - { - $data = $objects->getListviewData(); - foreach ($data as &$d) - $d['method'] = $objectIds[$d['id']]; - - $tabData = ['data' => array_values($data)]; - - if ($hasFilter) - $tabData['note'] = sprintf(Util::$filterResultString, '?objects&filter=cr=16;crs='.$this->hId.';crv=0'); - - $this->lvTabs[] = [GameObjectList::$brickFile, $tabData]; - } - } - - // tab: achievements - if ($_ = $this->subject->getField('achievementCatOrId')) - { - $condition = $_ > 0 ? [['category', $_]] : [['id', -$_]]; - $acvs = new AchievementList($condition); - if (!$acvs->error) - { - $this->extendGlobalData($acvs->getJSGlobals(GLOBALINFO_SELF | GLOBALINFO_RELATED)); - - $tabData = array( - 'data' => array_values($acvs->getListviewData()), - 'visibleCols' => ['category'] - ); - - if ($hasFilter) - $tabData['note'] = sprintf(Util::$filterResultString, '?achievements&filter=cr=11;crs='.$this->hId.';crv=0'); - - $this->lvTabs[] = [AchievementList::$brickFile, $tabData]; - } - } - - $itemCnd = []; - if ($this->hId) - { - $itemCnd = array( - 'OR', - ['eventId', $this->eId], // direct requirement on item - ); - - // tab: quests (by table, go & creature) - $quests = new QuestList(array(['eventId', $this->eId])); - if (!$quests->error) - { - $this->extendGlobalData($quests->getJSGlobals(GLOBALINFO_SELF | GLOBALINFO_REWARDS)); - - $tabData = ['data'=> array_values($quests->getListviewData())]; - - if ($hasFilter) - $tabData['note'] = sprintf(Util::$filterResultString, '?quests&filter=cr=33;crs='.$this->hId.';crv=0'); - - $this->lvTabs[] = [QuestList::$brickFile, $tabData]; - - $questItems = []; - foreach (array_column($quests->rewards, Type::ITEM) as $arr) - $questItems = array_merge($questItems, array_keys($arr)); - - foreach (array_column($quests->choices, Type::ITEM) as $arr) - $questItems = array_merge($questItems, array_keys($arr)); - - foreach (array_column($quests->requires, Type::ITEM) as $arr) - $questItems = array_merge($questItems, $arr); - - if ($questItems) - $itemCnd[] = ['id', $questItems]; - } - } - - // items from creature - if ($npcIds && !$creatures->error) - { - // vendor - $cIds = $creatures->getFoundIDs(); - if ($sells = DB::World()->selectCol( - 'SELECT `item` FROM npc_vendor nv WHERE `entry` IN (?a) UNION - SELECT nv1.`item` FROM npc_vendor nv1 JOIN npc_Vendor nv2 ON -nv1.`entry` = nv2.`item` WHERE nv2.`entry` IN (?a) UNION - SELECT `item` FROM game_event_npc_vendor genv JOIN creature c ON genv.`guid` = c.`guid` WHERE c.`id` IN (?a)', - $cIds, $cIds, $cIds - )) - $itemCnd[] = ['id', $sells]; - } - - // tab: items - // not checking for loot ... cant distinguish between eventLoot and fillerCrapLoot - if ($itemCnd) - { - $eventItems = new ItemList($itemCnd); - if (!$eventItems->error) - { - $this->extendGlobalData($eventItems->getJSGlobals(GLOBALINFO_SELF)); - - $tabData = ['data'=> array_values($eventItems->getListviewData())]; - - if ($hasFilter) - $tabData['note'] = sprintf(Util::$filterResultString, '?items&filter=cr=160;crs='.$this->hId.';crv=0'); - - $this->lvTabs[] = [ItemList::$brickFile, $tabData]; - } - } - - // tab: see also (event conditions) - if ($rel = DB::World()->selectCol('SELECT IF(eventEntry = prerequisite_event, NULL, IF(eventEntry = ?d, prerequisite_event, -eventEntry)) FROM game_event_prerequisite WHERE prerequisite_event = ?d OR eventEntry = ?d', $this->eId, $this->eId, $this->eId)) - { - $list = []; - array_walk($rel, function($v, $k) use (&$list) { - if ($v > 0) - $list[] = $v; - else if ($v === null) - trigger_error('game_event_prerequisite: this event has itself as prerequisite', E_USER_WARNING); - }); - - if ($list) - { - $relEvents = new WorldEventList(array(['id', $list])); - $this->extendGlobalData($relEvents->getJSGlobals()); - $relData = $relEvents->getListviewData(); - foreach ($relEvents->getFoundIDs() as $id) - Conditions::extendListviewRow($relData[$id], Conditions::SRC_NONE, $this->typeId, [-Conditions::ACTIVE_EVENT, $this->eId]); - - $this->extendGlobalData($this->subject->getJSGlobals()); - $d = $this->subject->getListviewData(); - foreach ($rel as $r) - if ($r > 0) - if (Conditions::extendListviewRow($d[$this->eId], Conditions::SRC_NONE, $this->typeId, [-Conditions::ACTIVE_EVENT, $r])) - $this->extendGlobalIds(Type::WORLDEVENT, $r); - - $relData = array_merge($relData, $d); - - $this->lvTabs[] = [WorldEventList::$brickFile, array( - 'data' => array_values($relData), - 'id' => 'see-also', - 'name' => '$LANG.tab_seealso', - 'hiddenCols' => ['date'], - 'extraCols' => ['$Listview.extraCols.condition'] - )]; - } - } - - // tab: condition for - $cnd = new Conditions(); - $cnd->getByCondition(Type::WORLDEVENT, $this->typeId)->prepare(); - if ($tab = $cnd->toListviewTab('condition-for', '$LANG.tab_condition_for')) - { - $this->extendGlobalData($cnd->getJsGlobals()); - $this->lvTabs[] = $tab; - } - } - - protected function generateTooltip() : string - { - $power = new \StdClass(); - if (!$this->subject->error) - { - $power->{'name_'.Lang::getLocale()->json()} = $this->subject->getField('name', true); - - if ($this->subject->getField('iconString') != 'trade_engineering') - $power->icon = rawurlencode($this->subject->getField('iconString', true, true)); - - $power->{'tooltip_'.Lang::getLocale()->json()} = $this->subject->renderTooltip(); - } - - return sprintf($this->powerTpl, $this->typeId, Lang::getLocale()->value, Util::toJSON($power, JSON_AOWOW_POWER)); - } - - protected function postCache() - { - // update dates to now() - WorldEventList::updateDates($this->dates, $start, $end, $rec); - - if ($this->mode == CACHE_TYPE_TOOLTIP) - { - return array( - date(Lang::main('dateFmtLong'), $start), - date(Lang::main('dateFmtLong'), $end) - ); - } - else - { - if ($this->hId) - $this->wowheadLink = sprintf(WOWHEAD_LINK, Lang::getLocale()->domain(), 'event', $this->hId); - - /********************/ - /* finalize infobox */ - /********************/ - - // start - if ($start) - array_push($this->infobox, Lang::event('start').Lang::main('colon').date(Lang::main('dateFmtLong'), $start)); - - // end - if ($end) - array_push($this->infobox, Lang::event('end').Lang::main('colon').date(Lang::main('dateFmtLong'), $end)); - - // occurence - if ($rec > 0) - array_push($this->infobox, Lang::event('interval').Lang::main('colon').Util::formatTime($rec * 1000)); - - // in progress - if ($start < time() && $end > time()) - array_push($this->infobox, '[span class=q2]'.Lang::event('inProgress').'[/span]'); - - $this->infobox = '[ul][li]'.implode('[/li][li]', $this->infobox).'[/li][/ul]'; - - /***************************/ - /* finalize related events */ - /***************************/ - - foreach ($this->lvTabs as &$view) - { - if ($view[0] != WorldEventList::$brickFile) - continue; - - foreach ($view[1]['data'] as &$data) - { - WorldEventList::updateDates($data['_date'], $start, $end, $rec); - unset($data['_date']); - $data['startDate'] = $start ? date(Util::$dateFormatInternal, $start) : false; - $data['endDate'] = $end ? date(Util::$dateFormatInternal, $end) : false; - $data['rec'] = $rec; - } - } - } - } -} - -?> diff --git a/pages/events.php b/pages/events.php deleted file mode 100644 index 4ed714c1..00000000 --- a/pages/events.php +++ /dev/null @@ -1,109 +0,0 @@ -getCategoryFromUrl($pageParam); - - parent::__construct($pageCall, $pageParam); - - $this->name = Util::ucFirst(Lang::game('events')); - } - - protected function generateContent() - { - $condition = []; - - if (!User::isInGroup(U_GROUP_EMPLOYEE)) - $condition[] = [['cuFlags', CUSTOM_EXCLUDE_FOR_LISTVIEW, '&'], 0]; - - if ($this->category) - { - switch ($this->category[0]) - { - case 0: $condition[] = ['e.holidayId', 0]; break; - case 1: $condition[] = ['h.scheduleType', -1]; break; - case 2: $condition[] = ['h.scheduleType', [0, 1]]; break; - case 3: $condition[] = ['h.scheduleType', 2]; break; - } - } - - $events = new WorldEventList($condition); - $this->extendGlobalData($events->getJSGlobals()); - - foreach ($events->iterate() as $__) - if ($d = $events->getField('requires')) - $this->dependency[$events->id] = $d; - - $data = array_values($events->getListviewData()); - - $this->lvTabs[] = [WorldEventList::$brickFile, ['data' => $data]]; - - if ($_ = array_values(array_filter($data, function($x) {return $x['category'] > 0;}))) - { - $this->lvTabs[] = ['calendar', array( - 'data' => $_, - 'hideCount' => 1 - )]; - } - } - - protected function generateTitle() - { - array_unshift($this->title, $this->name); - if ($this->category) - array_unshift($this->title, Lang::event('category')[$this->category[0]]); - } - - protected function generatePath() - { - if ($this->category) - $this->path[] = $this->category[0]; - } - - protected function postCache() - { - // recalculate dates with now() - foreach ($this->lvTabs as &$views) - { - foreach ($views[1]['data'] as &$data) - { - // is a followUp-event - if (!empty($this->dependency[$data['id']])) - { - $data['startDate'] = $data['endDate'] = false; - unset($data['_date']); - continue; - } - - WorldEventList::updateDates($data['_date'], $start, $end, $rec); - unset($data['_date']); - $data['startDate'] = $start ? date(Util::$dateFormatInternal, $start) : false; - $data['endDate'] = $end ? date(Util::$dateFormatInternal, $end) : false; - $data['rec'] = $rec; - } - } - } -} - -?>