mirror of
https://github.com/Sarjuuk/aowow.git
synced 2025-11-29 15:58:16 +08:00
removing smarty - part V
- added ObjectPage and ObjectsPage - moved loot-related functions from Util to own class - moved template-related functions from Util to GenericPage - removed redundancies from user class - enabled cache (may need some tweaking but it finally works as it should) - some bugfixes
This commit is contained in:
@@ -4,82 +4,87 @@ if (!defined('AOWOW_REVISION'))
|
||||
die('illegal access');
|
||||
|
||||
|
||||
$filter = [];
|
||||
$conditions = [];
|
||||
$cat = Util::extractURLParams($pageParam);
|
||||
$path = [0, 5];
|
||||
$validCats = [-2, -3, -4, -5, -6, 0, 3, 9, 25];
|
||||
$title = [Util::ucFirst(Lang::$game['gameObjects'])];
|
||||
$cacheKey = implode('_', [CACHETYPE_PAGE, TYPE_OBJECT, -1, $cat ? $cat[0] : -1, User::$localeId]);
|
||||
|
||||
if (!Util::isValidPage($validCats, $cat))
|
||||
$smarty->error();
|
||||
|
||||
if ($cat)
|
||||
// menuId 5: Object g_initPath()
|
||||
// tabId 0: Database g_initHeader()
|
||||
class ObjectsPage extends GenericPage
|
||||
{
|
||||
$path[] = $cat[0];
|
||||
array_unshift($title, Lang::$gameObject['cat'][$cat[0]]);
|
||||
$conditions[] = ['typeCat', (int)$cat[0]];
|
||||
}
|
||||
use ListPage;
|
||||
|
||||
if (!$smarty->loadCache($cacheKey, $pageData, $filter))
|
||||
{
|
||||
protected $type = TYPE_OBJECT;
|
||||
protected $tpl = 'objects';
|
||||
protected $path = [0, 5];
|
||||
protected $tabId = 0;
|
||||
protected $mode = CACHETYPE_PAGE;
|
||||
protected $validCats = [-2, -3, -4, -5, -6, 0, 3, 9, 25];
|
||||
protected $js = ['filters.js'];
|
||||
|
||||
$objectFilter = new GameObjectListFilter();
|
||||
if ($_ = $objectFilter->getConditions())
|
||||
$conditions[] = $_;
|
||||
|
||||
$objects = new GameObjectList($conditions, ['extraOpts' => $objectFilter->extraOpts]);
|
||||
|
||||
// menuId 5: Object g_initPath()
|
||||
// tabId 0: Database g_initHeader()
|
||||
$pageData = array(
|
||||
'page' => array(
|
||||
'tab' => 0,
|
||||
'title' => implode(" - ", $title),
|
||||
'path' => json_encode($path, JSON_NUMERIC_CHECK),
|
||||
'subCat' => $pageParam ? '='.$pageParam : '',
|
||||
'reqJS' => [STATIC_URL.'/js/filters.js']
|
||||
),
|
||||
'lv' => []
|
||||
);
|
||||
|
||||
// recreate form selection
|
||||
$filter = array_merge($objectFilter->getForm('form'), $filter);
|
||||
$filter['query'] = isset($_GET['filter']) ? $_GET['filter'] : NULL;
|
||||
$filter['fi'] = $objectFilter->getForm();
|
||||
|
||||
$params = [];
|
||||
if ($objects->hasSetFields(['reqSkill']))
|
||||
$params['visibleCols'] = "$['skill']";
|
||||
|
||||
$lv = array(
|
||||
'file' => 'object',
|
||||
'data' => $objects->getListviewData(),
|
||||
'params' => $params
|
||||
);
|
||||
|
||||
// create note if search limit was exceeded
|
||||
if ($objects->getMatches() > CFG_SQL_LIMIT_DEFAULT)
|
||||
public function __construct($pageCall, $pageParam)
|
||||
{
|
||||
$lv['params']['note'] = sprintf(Util::$tryFilteringString, 'LANG.lvnote_objectsfound', $objects->getMatches(), CFG_SQL_LIMIT_DEFAULT);
|
||||
$lv['params']['_truncated'] = 1;
|
||||
$this->category = Util::extractURLParams($pageParam);
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$this->name = Util::ucFirst(Lang::$game['gameObjects']);
|
||||
$this->subCat = $pageParam ? '='.$pageParam : '';
|
||||
}
|
||||
|
||||
if ($objectFilter->error)
|
||||
$lv['params']['_errors'] = '$1';
|
||||
protected function generateContent()
|
||||
{
|
||||
$conditions = [];
|
||||
|
||||
$pageData['lv'] = $lv;
|
||||
if ($this->category)
|
||||
$conditions[] = ['typeCat', (int)$this->category[0]];
|
||||
|
||||
$smarty->saveCache($cacheKey, $pageData, $filter);
|
||||
$objectFilter = new GameObjectListFilter();
|
||||
|
||||
// recreate form selection
|
||||
$this->filter = $objectFilter->getForm('form');
|
||||
$this->filter['query'] = isset($_GET['filter']) ? $_GET['filter'] : null;
|
||||
$this->filter['fi'] = $objectFilter->getForm();
|
||||
|
||||
if ($_ = $objectFilter->getConditions())
|
||||
$conditions[] = $_;
|
||||
|
||||
$params = $data = [];
|
||||
$objects = new GameObjectList($conditions, ['extraOpts' => $objectFilter->extraOpts]);
|
||||
if (!$objects->error)
|
||||
{
|
||||
$data = $objects->getListviewData();
|
||||
if ($objects->hasSetFields(['reqSkill']))
|
||||
$params['visibleCols'] = "$['skill']";
|
||||
|
||||
|
||||
// create note if search limit was exceeded
|
||||
if ($objects->getMatches() > CFG_SQL_LIMIT_DEFAULT)
|
||||
{
|
||||
$params['note'] = sprintf(Util::$tryFilteringString, 'LANG.lvnote_objectsfound', $objects->getMatches(), CFG_SQL_LIMIT_DEFAULT);
|
||||
$params['_truncated'] = 1;
|
||||
}
|
||||
|
||||
if ($objectFilter->error)
|
||||
$params['_errors'] = '$1';
|
||||
|
||||
}
|
||||
|
||||
$this->lvData = array(
|
||||
'file' => 'object',
|
||||
'data' => $data,
|
||||
'params' => $params
|
||||
);
|
||||
}
|
||||
|
||||
protected function generateTitle()
|
||||
{
|
||||
array_unshift($this->title, $this->name);
|
||||
if ($this->category)
|
||||
array_unshift($this->title, Lang::$gameObject['cat'][$this->category[0]]);
|
||||
}
|
||||
|
||||
protected function generatePath()
|
||||
{
|
||||
if ($this->category)
|
||||
$this->path[] = $this->category[0];
|
||||
}
|
||||
}
|
||||
|
||||
$smarty->updatePageVars($pageData['page']);
|
||||
$smarty->assign('filter', $filter);
|
||||
$smarty->assign('lang', array_merge(Lang::$main, ['colon' => Lang::$colon]));
|
||||
$smarty->assign('lvData', $pageData['lv']);
|
||||
|
||||
// load the page
|
||||
$smarty->display('objects.tpl');
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user