Reorder return values of VariableBase::getValue() so that the value can be quickly accessed

This commit is contained in:
Kijin Sung 2025-02-15 22:25:25 +09:00
parent 0d14aca1c0
commit fd0491cb0d
3 changed files with 18 additions and 15 deletions

View file

@ -487,9 +487,9 @@ class DB
} }
// Collect various counts used in the page calculation. // Collect various counts used in the page calculation.
list($is_expression, $list_count) = $query->navigation->list_count->getValue($args); $list_count = $query->navigation->list_count->getValue($args)[0];
list($is_expression, $page_count) = $query->navigation->page_count->getValue($args); $page_count = $query->navigation->page_count->getValue($args)[0];
list($is_expression, $page) = $query->navigation->page->getValue($args); $page = $query->navigation->page->getValue($args)[0];
$total_count = intval($count); $total_count = intval($count);
$total_page = max(1, intval(ceil($total_count / $list_count))); $total_page = max(1, intval(ceil($total_count / $list_count)));
$last_index = $total_count - (($page - 1) * $list_count); $last_index = $total_count - (($page - 1) * $list_count);

View file

@ -609,7 +609,7 @@ class Query extends VariableBase
{ {
// Get the name of the column or expression to order by. // Get the name of the column or expression to order by.
$column_name = ''; $column_name = '';
list($is_expression, $column_name) = $orderby->getValue($this->_args); list($column_name, $is_expression) = $orderby->getValue($this->_args);
if (!$column_name) if (!$column_name)
{ {
continue; continue;
@ -649,7 +649,7 @@ class Query extends VariableBase
protected function _arrangeLimitOffset(Navigation $navigation): string protected function _arrangeLimitOffset(Navigation $navigation): string
{ {
// Get the list count. // Get the list count.
list($is_expression, $list_count) = $navigation->list_count->getValue($this->_args); $list_count = $navigation->list_count->getValue($this->_args)[0];
if ($list_count <= 0) if ($list_count <= 0)
{ {
return ''; return '';
@ -660,11 +660,11 @@ class Query extends VariableBase
// Get the offset from the page or offset variable. // Get the offset from the page or offset variable.
if ($navigation->page) if ($navigation->page)
{ {
list($is_expression, $page) = $navigation->page->getValue($this->_args); $page = $navigation->page->getValue($this->_args)[0];
} }
if ($navigation->offset) if ($navigation->offset)
{ {
list($is_expression, $offset) = $navigation->offset->getValue($this->_args); $offset = $navigation->offset->getValue($this->_args)[0];
} }
// If page is available, set the offset and require pagination for this query. // If page is available, set the offset and require pagination for this query.

View file

@ -281,11 +281,17 @@ class VariableBase
/** /**
* Get the current value, falling back to the default value if necessary. * Get the current value, falling back to the default value if necessary.
* *
* Format of return value: [value, is_expression, is_default_value]
*
* @param array $args * @param array $args
* @return array * @return array
*/ */
public function getValue(array $args): array public function getValue(array $args): array
{ {
$value = null;
$is_expression = false;
$is_default_value = false;
if ($this->var && Query::isValidVariable($args[$this->var] ?? null, $this instanceof ColumnWrite)) if ($this->var && Query::isValidVariable($args[$this->var] ?? null, $this instanceof ColumnWrite))
{ {
if ($args[$this->var] === '') if ($args[$this->var] === '')
@ -293,35 +299,32 @@ class VariableBase
if ($this instanceof ColumnWrite) if ($this instanceof ColumnWrite)
{ {
$value = $args[$this->var]; $value = $args[$this->var];
$is_expression = false;
} }
else else
{ {
list($is_expression, $value) = $this->getDefaultValue(); list($is_expression, $value) = $this->getDefaultValue();
$is_default_value = true;
} }
} }
else else
{ {
$is_expression = false;
$value = $args[$this->var]; $value = $args[$this->var];
} }
} }
elseif ($this->default !== null) elseif ($this->default !== null)
{ {
list($is_expression, $value) = $this->getDefaultValue(); list($is_expression, $value) = $this->getDefaultValue();
} $is_default_value = true;
else
{
$is_expression = null;
$value = null;
} }
return [$is_expression, $value]; return [$value, $is_expression, $is_default_value];
} }
/** /**
* Get the default value of this variable. * Get the default value of this variable.
* *
* Format of return value: [is_expression, value]
*
* @return array * @return array
*/ */
public function getDefaultValue(): array public function getDefaultValue(): array