I think, I've finally found a use for traits

- working on listviews displaying only the columns needed
- still fighting leftovers from class conversion
This commit is contained in:
Sarjuuk
2013-03-13 20:51:36 +01:00
parent 7c482e9319
commit 881e5143d1
4 changed files with 48 additions and 2 deletions

View File

@@ -5,6 +5,8 @@ if (!defined('AOWOW_REVISION'))
class AchievementList extends BaseType class AchievementList extends BaseType
{ {
use listviewHelper;
public $criteria = []; public $criteria = [];
public $tooltip = []; public $tooltip = [];

View File

@@ -5,7 +5,9 @@ if (!defined('AOWOW_REVISION'))
class TitleList extends BaseType class TitleList extends BaseType
{ {
private $sources = []; use listviewHelper;
public $sources = [];
protected $setupQuery = 'SELECT *, id AS ARRAY_KEY FROM ?_titles WHERE [cond] ORDER BY Id ASC'; protected $setupQuery = 'SELECT *, id AS ARRAY_KEY FROM ?_titles WHERE [cond] ORDER BY Id ASC';
protected $matchQuery = 'SELECT COUNT(1) FROM ?_titles WHERE [cond]'; protected $matchQuery = 'SELECT COUNT(1) FROM ?_titles WHERE [cond]';
@@ -33,6 +35,7 @@ class TitleList extends BaseType
} }
} }
} }
$this->reset(); // push first element back for instant use
} }
public function getListviewData() public function getListviewData()
@@ -127,7 +130,7 @@ class TitleList extends BaseType
public function getHtmlizedName($gender = GENDER_MALE) public function getHtmlizedName($gender = GENDER_MALE)
{ {
return str_replace('%s', '<span class="q0">&lt;'.Lang::$main['name'].'&gt;</span>', $this->name[$gender]); return str_replace('%s', '<span class="q0">&lt;'.Lang::$main['name'].'&gt;</span>', $this->names[$this->id][$gender]);
} }
public function addRewardsToJScript(&$ref) { } public function addRewardsToJScript(&$ref) { }

View File

@@ -193,6 +193,41 @@ abstract class BaseType
abstract public function renderTooltip(); abstract public function renderTooltip();
} }
trait listviewHelper
{
public function hasDiffCategories()
{
$this->reset();
$curCat = $this->getField('category');
if ($curCat === null)
return false;
while ($this->iterate())
if ($curCat != $this->getField('category'))
return true;
return false;
}
public function hasAnySource()
{
if (!isset($this->sources))
return false;
foreach ($this->sources as $src)
{
if (!is_array($src))
continue;
if (!empty($src))
return true;
}
return false;
}
}
class Lang class Lang
{ {
public static $main; public static $main;

View File

@@ -27,6 +27,12 @@ if (!$smarty->loadCache($cacheKey, $pageData))
) )
); );
if ($titles->hasDiffCategories())
$pageData['params']['visibleCols'] = "$['category']";
if (!$titles->hasAnySource())
$pageData['params']['hiddenCols'] = "$['source']";
$smarty->saveCache($cacheKey, $pageData); $smarty->saveCache($cacheKey, $pageData);
} }