From 97f67c32cd2ed67e58901364dc3e6c82de05fe3c Mon Sep 17 00:00:00 2001 From: Sarjuuk Date: Sun, 25 Aug 2013 10:41:38 +0200 Subject: [PATCH] Skills: - implemented detail-page - implemented search --- pages/skill.php | 357 +++++++++++++++++++++++++++++++++++++++++++++ search.php | 33 ++++- template/skill.tpl | 44 ++++++ 3 files changed, 429 insertions(+), 5 deletions(-) create mode 100644 pages/skill.php create mode 100644 template/skill.tpl diff --git a/pages/skill.php b/pages/skill.php new file mode 100644 index 00000000..eeb8d873 --- /dev/null +++ b/pages/skill.php @@ -0,0 +1,357 @@ +loadCache($cacheKeyPage, $pageData)) +{ + $skill = new SkillList(array(['id', $_id])); + if ($skill->error) + $smarty->notFound(Lang::$game['skill']); + + $_cat = $skill->getField('typeCat'); + + $pageData = array( + 'title' => $skill->getField('name', true), + 'path' => [0, 14], + 'relTabs' => [], + 'page' => array( + 'name' => $skill->getField('name', true), + 'icon' => $skill->getField('iconString'), + 'id' => $_id + ), + ); + + $pageData['path'][] = (in_array($_cat, [9, 11]) || $_id == 762) ? $_id : $_cat; + + if (in_array($_cat, [-5, 9, 11])) + { + $condition = array( + ['OR', ['s.reagent1', 0, '>'], ['s.reagent2', 0, '>'], ['s.reagent3', 0, '>'], ['s.reagent4', 0, '>'], ['s.reagent5', 0, '>'], ['s.reagent6', 0, '>'], ['s.reagent7', 0, '>'], ['s.reagent8', 0, '>']], + ['OR', ['s.skillLine1', $_id], ['AND', ['s.skillLine1', 0, '>'], ['s.skillLine2OrMask', $_id]]], + 0 + ); + + $recipes = new SpellList($condition); // also relevant for 3 + if (!$recipes->error) + { + // 1 recipes [spells] (crafted) + $recipes->addGlobalsToJscript($smarty); + + $pageData['relTabs'][] = array( + 'file' => 'spell', + 'data' => $recipes->getListviewData(), + 'params' => array( + 'tabs' => '$tabsRelated', + 'id' => 'recipes', + 'name' => '$LANG.tab_recipes', + 'visibleCols' => "$['reagents', 'source']", + 'note' => sprintf(Util::$filterResultString, '?spells='.$_cat.'.'.$_id.'&filter=cr=20;crs=1;crv=0') + ) + ); + } + + // 2 recipe Items [items] (Books) + $conditions = array( + ['RequiredSkill', $_id], + ['class', ITEM_CLASS_RECIPE], + 0 + ); + + $recipeItems = new ItemList($conditions); + if (!$recipeItems->error) + { + $recipeItems->addGlobalsToJscript($smarty, GLOBALINFO_SELF); + + $pageData['relTabs'][] = array( + 'file' => 'item', + 'data' => $recipeItems->getListviewData(), + 'params' => array( + 'id' => 'recipe-items', + 'name' => '$LANG.tab_recipeitems', + 'tabs' => '$tabsRelated', + // 'note' => sprintf(Util::$filterResultString, "?items=9.subClass") // todo (med): after items + ) + ); + } + + // 3 crafted items [items] + $created = []; + foreach ($recipes->iterate() as $__) + if ($recipes->canCreateItem()) + for ($i = 1; $i < 4; $i++) + if ($_ = $recipes->getField('effect'.$i.'CreateItemId')) + $created[] = $_; + + if ($created) + { + $created = new ItemList(array(['i.entry', $created], 0)); + if (!$created->error) + { + $created->addGlobalsToJscript($smarty, GLOBALINFO_SELF); + + $pageData['relTabs'][] = array( + 'file' => 'item', + 'data' => $created->getListviewData(), + 'params' => array( + 'id' => 'crafted-items', + 'name' => '$LANG.tab_crafteditems', + 'tabs' => '$tabsRelated', + // 'note' => sprintf(Util::$filterResultString, "?items&filter=cr=86;crs=6;crv=0") // todo (med): after items; [craftedbyProfession (name)] + ) + ); + } + } + + // 4a required by [item] + $conditions = array( + ['RequiredSkill', $_id], + ['class', ITEM_CLASS_RECIPE, '!'], + 0 + ); + + $reqBy = new ItemList($conditions); + if (!$reqBy->error) + { + $reqBy->addGlobalsToJscript($smarty, GLOBALINFO_SELF); + + $pageData['relTabs'][] = array( + 'file' => 'item', + 'data' => $reqBy->getListviewData(), + 'params' => array( + 'id' => 'required-by', + 'name' => '$LANG.tab_requiredby', + 'tabs' => '$tabsRelated', + // 'note' => sprintf(Util::$filterResultString, "?items&filter=cr=99:168;crs=6:2;crv=0:0") // todo (med): after items; [requiresProfession (yes), teachesSpell (no)] + ) + ); + } + + // 4b required by [itemset] + $conditions = array( + ['skillId', $_id], + 0 + ); + + $reqBy = new ItemsetList($conditions); + if (!$reqBy->error) + { + $reqBy->addGlobalsToJscript($smarty, GLOBALINFO_SELF); + + $pageData['relTabs'][] = array( + 'file' => 'itemset', + 'data' => $reqBy->getListviewData(), + 'params' => array( + 'id' => 'required-by-set', + 'name' => '$LANG.tab_requiredby', + 'tabs' => '$tabsRelated' + ) + ); + } + } + + // 5 spells [spells] (exclude first tab) + $reqClass = 0x0; + $reqRace = 0x0; + $condition = array( + ['AND', ['s.reagent1', 0], ['s.reagent2', 0], ['s.reagent3', 0], ['s.reagent4', 0], ['s.reagent5', 0], ['s.reagent6', 0], ['s.reagent7', 0], ['s.reagent8', 0]], + ['OR', ['s.skillLine1', $_id], ['AND', ['s.skillLine1', 0, '>'], ['s.skillLine2OrMask', $_id]]], + 0 + ); + + foreach (Util::$skillLineMask as $line1 => $sets) + foreach ($sets as $idx => $set) + if ($set[1] == $_id) + { + $condition[1][] = array('AND', ['s.skillLine1', $line1], ['s.skillLine2OrMask', 1 << $idx, '&']); + break 2; + } + + $spells = new SpellList($condition); + if (!$spells->error) + { + foreach ($spells->iterate() as $__) + { + $reqClass |= $spells->getField('reqClassMask'); + $reqRace |= $spells->getField('reqRaceMask'); + } + + $spells->addGlobalsToJscript($smarty, GLOBALINFO_SELF); + + $pageData['relTabs'][] = array( + 'file' => 'spell', + 'data' => $spells->getListviewData(), + 'params' => array( + 'tabs' => '$tabsRelated', + 'visibleCols' => "$['source']" + ) + ); + + switch ($_cat) + { + case -4: + $pageData['spells']['params']['note'] = sprintf(Util::$filterResultString, '?spells=-4'); + break; + case 7: + if ($_id != 769) // Internal + $pageData['spells']['params']['note'] = sprintf(Util::$filterResultString, '?spells='.$_cat.'.'.(log($reqClass, 2) + 1).'.'.$_id); // doesn't matter what spell; reqClass should be identical for all Class Spells + break; + case 9: + case 11: + $pageData['spells']['params']['note'] = sprintf(Util::$filterResultString, '?spells='.$_cat.'.'.$_id); + break; + + } + } + + // 6 trainers [npcs] + if (in_array($_cat, [-5, 6, 7, 8, 9, 11])) + { + $list = []; + if (@$tt = Util::$trainerTemplates[TYPE_SKILL][$_id]) + $list = DB::Aowow()->selectCol('SELECT DISTINCT entry FROM npc_trainer WHERE spell IN (?a) AND entry < 200000', $tt); + else + { + $mask = 0; + foreach (Util::$skillLineMask[-3] as $idx => $pair) + if ($pair[1] == $_id) + $mask |= 1 << $idx; + + $list = DB::Aowow()->selectCol(' + SELECT IF(t1.entry > 200000, t2.entry, t1.entry) + FROM npc_trainer t1 + JOIN aowow_spell s ON s.id = t1.spell + LEFT JOIN npc_trainer t2 ON t2.spell = -t1.entry + WHERE s.typeCat IN (-11, 9) AND (s.skillLine1 = ?d OR (s.skillLine1 > 0 AND s.skillLine2OrMask = ?d) '.($mask ? ' OR (s.skilllIne1 = -3 AND s.skillLine2OrMask = '.$mask.')' : null).')', + $_id, + $_id + ); + } + + if ($list) + { + $trainer = new CreatureList(array(0, ['ct.id', $list], ['ct.spawns', 0, '>'], ['ct.npcflag', 0x10, '&'])); + + if (!$trainer->error) + { + $trainer->addGlobalsToJscript($smarty); + + $pageData['relTabs'][] = array( + 'file' => 'creature', + 'data' => $trainer->getListviewData(), + 'params' => array( + 'tabs' => '$tabsRelated', + 'id' => 'trainer', + 'name' => '$LANG.tab_trainers', + ) + ); + } + } + } + + // 7 quests [quests] + if (in_array($_cat, [9, 11])) // only for professions + { + $sort = 0; + switch ($_id) + { + case 182: $sort = 24; break; // Herbalism + case 356: $sort = 101; break; // Fishing + case 164: $sort = 121; break; // Blacksmithing + case 171: $sort = 181; break; // Alchemy + case 165: $sort = 182; break; // Leatherworking + case 202: $sort = 201; break; // Engineering + case 197: $sort = 264; break; // Tailoring + case 185: $sort = 304; break; // Cooking + case 129: $sort = 324; break; // First Aid + case 773: $sort = 371; break; // Inscription + case 755: $sort = 373; break; // Jewelcrafting + } + + if ($sort) + { + $quests = new QuestList(array(['zoneOrSort', -$sort], 0)); + if (!$quests->error) + { + $quests->addGlobalsToJScript($smarty); + $pageData['relTabs'][] = array( + 'file' => 'quest', + 'data' => $quests->getListviewData(), + 'params' => array( + 'tabs' => '$tabsRelated', + ) + ); + } + } + } + + // 8 related classes (apply classes from 5) + $class = []; + for ($i = 0; $i < 11; $i++) + if ($reqClass & (1 << $i)) + $class[] = $i + 1; + + if ($class) + { + $classes = new CharClassList(array(['id', $class])); + if (!$classes->error) + { + $pageData['relTabs'][] = array( + 'file' => 'class', + 'data' => $classes->getListviewData(), + 'params' => array( + 'tabs' => '$tabsRelated', + ) + ); + } + } + + // 9 related races (apply races from 5) + $race = []; + for ($i = 0; $i < 12; $i++) + if ($reqRace & (1 << $i)) + $race[] = $i + 1; + + if ($race) + { + $races = new CharRaceList(array(['id', $race])); + if (!$races->error) + { + $pageData['relTabs'][] = array( + 'file' => 'race', + 'data' => $races->getListviewData(), + 'params' => array( + 'tabs' => '$tabsRelated', + ) + ); + } + } + + + $smarty->saveCache($cacheKeyPage, $pageData); +} + +// menuId 14: Skill g_initPath() +// tabId 0: Database g_initHeader() +$smarty->updatePageVars(array( + 'title' => $pageData['title']." - ".Util::ucfirst(Lang::$game['skill']), + 'path' => json_encode($pageData['path'], JSON_NUMERIC_CHECK), + 'tab' => 0, + 'type' => TYPE_SKILL, + 'typeId' => $_id +)); +$smarty->assign('community', CommunityContent::getAll(TYPE_SKILL, $_id)); // comments, screenshots, videos +$smarty->assign('lang', array_merge(Lang::$main)); +$smarty->assign('lvData', $pageData); + +// load the page +$smarty->display('skill.tpl'); + +?> diff --git a/search.php b/search.php index 99fde482..a1f531dd 100644 --- a/search.php +++ b/search.php @@ -33,14 +33,14 @@ if (!defined('AOWOW_REVISION')) 12: Listview - template: 'spell', id: 'professions', name: LANG.tab_professions, 13: Listview - template: 'spell', id: 'companions', name: LANG.tab_companions, 14: Listview - template: 'spell', id: 'mounts', name: LANG.tab_mounts, -todo 15: Listview - template: 'npc', id: 'npcs', name: LANG.tab_npcs, + 15: Listview - template: 'npc', id: 'npcs', name: LANG.tab_npcs, 16: Listview - template: 'quest', id: 'quests', name: LANG.tab_quests, 17: Listview - template: 'achievement', id: 'achievements', name: LANG.tab_achievements, 18: Listview - template: 'achievement', id: 'statistics', name: LANG.tab_statistics, todo 19: Listview - template: 'zone', id: 'zones', name: LANG.tab_zones, todo 20: Listview - template: 'object', id: 'objects', name: LANG.tab_objects, todo 21: Listview - template: 'faction', id: 'factions', name: LANG.tab_factions, -todo 22: Listview - template: 'skill', id: 'skills', name: LANG.tab_skills, hiddenCols: ['reagents', 'skill'], + 22: Listview - template: 'skill', id: 'skills', name: LANG.tab_skills, 23: Listview - template: 'pet', id: 'pets', name: LANG.tab_pets, 24: Listview - template: 'spell', id: 'npc-abilities', name: LANG.tab_npcabilities, 25: Listview - template: 'spell', id: 'spells', name: LANG.tab_uncategorizedspells, @@ -676,8 +676,7 @@ if ($searchMask & 0x4000) $conditions = array( [ 'OR', - ['name_loc'.User::$localeId, $query], - ['subname_loc'.User::$localeId, $query] + ['name_loc'.User::$localeId, $query] ], // [['cuFlags', MASKE, '&'], 0], // todo (med): exclude trigger creatures and difficulty entries $maxResults @@ -825,7 +824,31 @@ if ($searchMask & 0x20000) // if ($searchMask & 0x100000) // 22 Skills -// if ($searchMask & 0x200000) +if ($searchMask & 0x200000) +{ + $skills = new SkillList(array($maxResults, ['name_loc'.User::$localeId, $query])); + + if ($data = $skills->getListviewData()) + { + foreach ($skills->iterate() as $id => $__) + $data[$id]['param1'] = '"'.$skills->getField('iconString').'"'; + + $found['pet'] = array( + 'type' => TYPE_SKILL, + 'appendix' => ' (Skill)', + 'matches' => $skills->getMatches(), + 'file' => 'skill', + 'data' => $data, + 'params' => ['tabs' => '$myTabs'] + ); + + if ($skills->getMatches() > $maxResults) + { + $found['pet']['params']['note'] = sprintf(Util::$tryNarrowingString, 'LANG.lvnote_skillsfound', $skills->getMatches(), $maxResults); + $found['pet']['params']['_truncated'] = 1; + } + } +} // 23 Pets if ($searchMask & 0x400000) diff --git a/template/skill.tpl b/template/skill.tpl new file mode 100644 index 00000000..bcc89ddc --- /dev/null +++ b/template/skill.tpl @@ -0,0 +1,44 @@ +{include file='header.tpl'} + +
+
+
+ +{if !empty($announcements)} + {foreach from=$announcements item=item} + {include file='bricks/announcement.tpl' an=$item} + {/foreach} +{/if} + + + +{include file='bricks/infobox.tpl'} + +
+
+ + + + {$lang.links}{$lang.links} + WowheadWowhead +

{$lvData.page.name}

+ +{include file='bricks/article.tpl'} + +

{$lang.related}

+
+ +{include file='bricks/tabsRelated.tpl' tabs=$lvData.relTabs} + +{include file='bricks/contribute.tpl'} + +
+
+ +{include file='footer.tpl'}