mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-03 16:51:40 +09:00
Support "if" attribute in navigation elements of XML query
This commit is contained in:
parent
fd0491cb0d
commit
658a28dfd8
3 changed files with 25 additions and 5 deletions
|
|
@ -198,6 +198,7 @@ class DBQueryParser extends BaseParser
|
|||
$orderby->default = ($attribs['default'] ?? null) ?: null;
|
||||
$orderby->order_var = ($attribs['order'] ?? null) ?: null;
|
||||
$orderby->order_default = strtoupper($attribs['orderdefault'] ?? '') === 'DESC' ? 'DESC' : 'ASC';
|
||||
$orderby->ifvar = trim($attribs['if'] ?? '') ?: null;
|
||||
$query->navigation->orderby[] = $orderby;
|
||||
}
|
||||
foreach (['list_count', 'page_count', 'page', 'offset'] as $key)
|
||||
|
|
@ -207,6 +208,7 @@ class DBQueryParser extends BaseParser
|
|||
$query->navigation->{$key} = new DBQuery\VariableBase;
|
||||
$query->navigation->{$key}->var = trim($tag['var'] ?? '') ?: null;
|
||||
$query->navigation->{$key}->default = trim($tag['default'] ?? '') ?: null;
|
||||
$query->navigation->{$key}->ifvar = trim($tag['if'] ?? '') ?: null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,4 +11,5 @@ class OrderBy extends VariableBase
|
|||
public $default;
|
||||
public $order_var;
|
||||
public $order_default = 'ASC';
|
||||
public $ifvar;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -607,6 +607,12 @@ class Query extends VariableBase
|
|||
// Process each column definition.
|
||||
foreach ($navigation->orderby as $orderby)
|
||||
{
|
||||
// Skip
|
||||
if ($orderby->ifvar && empty($this->_args[$orderby->ifvar]))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get the name of the column or expression to order by.
|
||||
$column_name = '';
|
||||
list($column_name, $is_expression) = $orderby->getValue($this->_args);
|
||||
|
|
@ -648,23 +654,34 @@ class Query extends VariableBase
|
|||
*/
|
||||
protected function _arrangeLimitOffset(Navigation $navigation): string
|
||||
{
|
||||
$list_count = 0;
|
||||
$page = 0;
|
||||
$offset = 0;
|
||||
|
||||
// Get the list count.
|
||||
$list_count = $navigation->list_count->getValue($this->_args)[0];
|
||||
if (!$navigation->list_count->ifvar || !empty($this->_args[$navigation->list_count->ifvar]))
|
||||
{
|
||||
$list_count = $navigation->list_count->getValue($this->_args)[0];
|
||||
}
|
||||
if ($list_count <= 0)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
$page = 0;
|
||||
$offset = 0;
|
||||
|
||||
// Get the offset from the page or offset variable.
|
||||
if ($navigation->page)
|
||||
{
|
||||
$page = $navigation->page->getValue($this->_args)[0];
|
||||
if (!$navigation->page->ifvar || !empty($this->_args[$navigation->page->ifvar]))
|
||||
{
|
||||
$page = $navigation->page->getValue($this->_args)[0];
|
||||
}
|
||||
}
|
||||
if ($navigation->offset)
|
||||
{
|
||||
$offset = $navigation->offset->getValue($this->_args)[0];
|
||||
if (!$navigation->offset->ifvar || !empty($this->_args[$navigation->offset->ifvar]))
|
||||
{
|
||||
$offset = $navigation->offset->getValue($this->_args)[0];
|
||||
}
|
||||
}
|
||||
|
||||
// If page is available, set the offset and require pagination for this query.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue