Support order_default attribute to <index> tag in XML query

This commit is contained in:
Kijin Sung 2022-12-18 01:18:55 +09:00
parent 2a3f5d3c51
commit 4cc730e489
4 changed files with 12 additions and 10 deletions

View file

@ -11,17 +11,17 @@ abstract class BaseParser
* Get all attributes of an element as an associative array.
*
* @param SimpleXMLElement $element
* @param bool $remove_symbols
* @param bool $normalize
* @return array
*/
protected static function _getAttributes(\SimpleXMLElement $element, $remove_symbols = true): array
protected static function _getAttributes(\SimpleXMLElement $element, $normalize = true): array
{
$result = array();
foreach ($element->attributes() as $key => $val)
{
if ($remove_symbols)
if ($normalize)
{
$key = preg_replace('/[^a-z]/', '', $key);
$key = strtolower(preg_replace('/[^a-zA-Z]/', '', $key));
}
$result[trim($key)] = trim($val);
}

View file

@ -190,10 +190,12 @@ class DBQueryParser extends BaseParser
$query->navigation = new DBQuery\Navigation;
foreach ($xml->navigation->index ?: [] as $tag)
{
$attribs = self::_getAttributes($tag, true);
$orderby = new DBQuery\OrderBy;
$orderby->var = trim($tag['var']) ?: null;
$orderby->default = trim($tag['default']) ?: null;
$orderby->order_var = trim($tag['order']) ?: null;
$orderby->var = ($attribs['var'] ?? null) ?: null;
$orderby->default = ($attribs['default'] ?? null) ?: null;
$orderby->order_var = ($attribs['order'] ?? null) ?: null;
$orderby->order_default = strtoupper($attribs['orderdefault'] ?? '') === 'DESC' ? 'DESC' : 'ASC';
$query->navigation->orderby[] = $orderby;
}
foreach (['list_count', 'page_count', 'page', 'offset'] as $key)