-
Notifications
You must be signed in to change notification settings - Fork 19
allow custom qbpager page parameter #227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
| { | ||
| $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'; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this I find a bit hard to read. Is it |
||
| } | ||
|
|
||
| /** | ||
|
|
@@ -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) { | ||
|
|
@@ -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); | ||
|
|
||
|
|
@@ -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'; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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]); | ||
|
|
||
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 testsmidgard_styleis already a raw MgdSchema class, so the conversion fails before the direct query builder can be createdThere was a problem hiding this comment.
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