diff --git a/classes/local/dash_framework/query_builder/builder.php b/classes/local/dash_framework/query_builder/builder.php index 73e86c3..b02def8 100644 --- a/classes/local/dash_framework/query_builder/builder.php +++ b/classes/local/dash_framework/query_builder/builder.php @@ -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; diff --git a/classes/local/dash_framework/query_builder/join.php b/classes/local/dash_framework/query_builder/join.php index 1e23f96..b998534 100644 --- a/classes/local/dash_framework/query_builder/join.php +++ b/classes/local/dash_framework/query_builder/join.php @@ -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. */ diff --git a/classes/local/data_source/abstract_data_source.php b/classes/local/data_source/abstract_data_source.php index b3ffdab..eb3c216 100644 --- a/classes/local/data_source/abstract_data_source.php +++ b/classes/local/data_source/abstract_data_source.php @@ -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; } @@ -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; + } + }