Skip to content

Commit

Permalink
Paginator count issue fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
raja-lmsace committed Jul 22, 2024
1 parent 4970a3d commit 5fdf662
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
14 changes: 12 additions & 2 deletions classes/local/dash_framework/query_builder/builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -452,13 +452,23 @@ public function query() {
/**
* Get number of records this query will return.
*
* @param int $isunique Counted by unique id.
* @return int
* @throws dml_exception
* @throws exception\invalid_operator_exception
*/
public function count(): int {
public function count($isunique): int {
$builder = clone $this;
$builder->set_selects(['count' => 'COUNT(DISTINCT ' . $this->tablealias . '.id)']);

if ($isunique) {
$builder->set_selects([
'uni' => 'CONCAT_WS("-", cm.id, u.id, c.id, cc.id)',
'count' => 'COUNT(*)']
);
} else {
$builder->set_selects(['count' => 'COUNT(DISTINCT ' . $this->tablealias . '.id)']);
}

$builder->limitfrom(0)->limitnum(0)->remove_orderby();
if (!$records = $builder->query()) {
return 0;
Expand Down
5 changes: 5 additions & 0 deletions classes/local/dash_framework/query_builder/join.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ class join {
*/
const TYPE_LEFT_JOIN = 'LEFT JOIN';

/**
* SQL right Join.
*/
const TYPE_RIGHT_JOIN = 'RIGHT JOIN';

/**
* @var string Table name of joined table.
*/
Expand Down
11 changes: 10 additions & 1 deletion classes/local/data_source/abstract_data_source.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public function get_paginator(): paginator {

if ($this->paginator == null) {
$this->paginator = new paginator(function () {
$count = $this->get_query()->count();
$count = $this->get_query()->count($this->count_by_uniqueid());
if ($maxlimit = $this->get_max_limit()) {
return $maxlimit < $count ? $maxlimit : $count;
}
Expand Down Expand Up @@ -719,4 +719,13 @@ public function is_widget() {
return false;
}

/**
* Count a data record by uniqueid.
*
* @return boolean
*/
public function count_by_uniqueid() {
return false;
}

}

0 comments on commit 5fdf662

Please sign in to comment.