Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions lib/org/openpsa/qbpager/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@ class org_openpsa_qbpager extends midcom_core_querybuilder
private int $_current_page = 1;
private $total;

public function __construct(string $classname, string $pager_id)
public function __construct(string $classname, string $pager_id, ?string $prefix = null)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe as a more general comment: Is it really necessary to add a new parameter here? Shouldn't pager_id be enough to uniquely identify a pager instance?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i couldn’t merge initialize() into __construct() because the parent constructor can’t be used here. it expects a DBA class and tries to resolve the classname through the MidCOM class loader. based on the tests midgard_style is already a raw MgdSchema class, so the conversion fails before the direct query builder can be created

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yeah, makes sense. Didn't notice that qbpager extends querybuilder

{
$this->initialize($pager_id);
$this->initialize($pager_id, $prefix);
parent::__construct($classname);
}

protected function initialize(string $pager_id)
protected function initialize(string $pager_id, ?string $prefix = null)
{
$this->_component = 'org.openpsa.qbpager';
if (empty($pager_id)) {
throw new midcom_error('pager_id is not set (needed for distinguishing different instances on same request)');
}

$this->_pager_id = $pager_id;
$this->_prefix = 'org_openpsa_qbpager_' . $pager_id . '_';
$this->_prefix = $prefix ?? 'org_openpsa_qbpager_' . $pager_id . '_page';

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this I find a bit hard to read. Is it ($prefix ?? 'org_openpsa_qbpager_') . $pager_id . '_page' or is it $prefix ?? ('org_openpsa_qbpager_' . $pager_id . '_page')?

}

/**
Expand Down Expand Up @@ -74,7 +74,7 @@ public function show_previousnext()
}
//@todo Move to style element
//TODO: "showing results (offset)-(offset+limit)
$page_var = $this->_prefix . 'page';
$page_var = $this->_prefix;
echo '<div class="org_openpsa_qbpager_previousnext">';

if ($this->_current_page > 1) {
Expand All @@ -99,7 +99,7 @@ public function get_pages() : array
return $pages;
}

$page_var = $this->_prefix . 'page';
$page_var = $this->_prefix;
$display_start = max(($this->_current_page - ceil($this->display_pages / 2)), 1);
$display_end = min(($this->_current_page + ceil($this->display_pages / 2)), $page_count);

Expand Down Expand Up @@ -181,12 +181,12 @@ public function show_pages()
*/
protected function parse_variables()
{
$page_var = $this->_prefix . 'page';
$page_var = $this->_prefix;
if (!empty($_REQUEST[$page_var])) {
debug_add("{$page_var} has value: {$_REQUEST[$page_var]}");
$this->_current_page = max(1, (int) $_REQUEST[$page_var]);
}
$results_var = $this->_prefix . 'results';
$results_var = 'org_openpsa_qbpager_' . $this->_pager_id . '_results';

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems a bit inconsistent to not use the prefix here. Why does this need to change?

if (!empty($_REQUEST[$results_var])) {
debug_add("{$results_var} has value: {$_REQUEST[$results_var]}");
$this->results_per_page = max(1, (int) $_REQUEST[$results_var]);
Expand Down