|
From: <du...@us...> - 2012-12-04 20:09:00
|
Revision: 10318
http://sourceforge.net/p/xoops/svn/10318
Author: dugris
Date: 2012-12-04 20:08:57 +0000 (Tue, 04 Dec 2012)
Log Message:
-----------
Fix groupby in criteria & model
Modified Paths:
--------------
XoopsCore/branches/2.6.x/2.6.0/htdocs/class/criteria.php
XoopsCore/branches/2.6.x/2.6.0/htdocs/class/model/joint.php
XoopsCore/branches/2.6.x/2.6.0/htdocs/class/model/read.php
XoopsCore/branches/2.6.x/2.6.0/htdocs/class/model/stats.php
Modified: XoopsCore/branches/2.6.x/2.6.0/htdocs/class/criteria.php
===================================================================
--- XoopsCore/branches/2.6.x/2.6.0/htdocs/class/criteria.php 2012-12-03 23:33:54 UTC (rev 10317)
+++ XoopsCore/branches/2.6.x/2.6.0/htdocs/class/criteria.php 2012-12-04 20:08:57 UTC (rev 10318)
@@ -161,16 +161,8 @@
*/
public function getGroupby()
{
- return $this->groupby ? " GROUP BY {$this->groupby}" : "";
+ return isset($this->groupby) ? $this->groupby : "";
}
-
- /**
- * @return string
- */
- public function getGroupbyField()
- {
- return $this->groupby ? $this->groupby : "";
- }
}
/**
Modified: XoopsCore/branches/2.6.x/2.6.0/htdocs/class/model/joint.php
===================================================================
--- XoopsCore/branches/2.6.x/2.6.0/htdocs/class/model/joint.php 2012-12-03 23:33:54 UTC (rev 10317)
+++ XoopsCore/branches/2.6.x/2.6.0/htdocs/class/model/joint.php 2012-12-04 20:08:57 UTC (rev 10318)
@@ -98,6 +98,9 @@
$sql .= " ORDER BY {$sort} " . $criteria->getOrder();
$orderSet = true;
}
+ if ($criteria->getGroupby() != '') {
+ $sql .= ' GROUP BY (' . $criteria->getGroupby() . ')';
+ }
$limit = $criteria->getLimit();
$start = $criteria->getStart();
}
@@ -139,6 +142,9 @@
$sql = " SELECT COUNT(DISTINCT {$this->handler->keyName}) AS count" . " FROM {$this->handler->table} AS o" . " LEFT JOIN {$this->handler->table_link} AS l ON o.{$this->handler->field_object} = l.{$this->handler->field_link}";
if (isset($criteria) && is_subclass_of($criteria, "criteriaelement")) {
$sql .= " " . $criteria->renderWhere();
+ if ($criteria->getGroupby() != '') {
+ $sql .= ' GROUP BY (' . $criteria->getGroupby() . ')';
+ }
}
if (!$result = $this->handler->db->query($sql)) {
return false;
Modified: XoopsCore/branches/2.6.x/2.6.0/htdocs/class/model/read.php
===================================================================
--- XoopsCore/branches/2.6.x/2.6.0/htdocs/class/model/read.php 2012-12-03 23:33:54 UTC (rev 10317)
+++ XoopsCore/branches/2.6.x/2.6.0/htdocs/class/model/read.php 2012-12-04 20:08:57 UTC (rev 10318)
@@ -57,7 +57,7 @@
if (isset($criteria)) {
$sql .= " " . $criteria->renderWhere();
if ($groupby = $criteria->getGroupby()) {
- $sql .= $groupby;
+ $sql .= ' GROUP BY (' . $groupby . ')';
}
if ($sort = $criteria->getSort()) {
$sql .= " ORDER BY {$sort} " . $criteria->getOrder();
@@ -138,6 +138,9 @@
if ($sort = $criteria->getSort()) {
$sql .= ' ORDER BY ' . $sort . ' ' . $criteria->getOrder();
}
+ if ($groupby = $criteria->getGroupby()) {
+ $sql .= ' GROUP BY (' . $groupby . ')';
+ }
$limit = $criteria->getLimit();
$start = $criteria->getStart();
}
Modified: XoopsCore/branches/2.6.x/2.6.0/htdocs/class/model/stats.php
===================================================================
--- XoopsCore/branches/2.6.x/2.6.0/htdocs/class/model/stats.php 2012-12-03 23:33:54 UTC (rev 10317)
+++ XoopsCore/branches/2.6.x/2.6.0/htdocs/class/model/stats.php 2012-12-04 20:08:57 UTC (rev 10318)
@@ -44,15 +44,17 @@
$field = '';
$groupby = false;
if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
- if ($criteria->getGroupbyField() != '') {
+ if ($criteria->getGroupby() != '') {
$groupby = true;
- $field = $criteria->getGroupbyField() . ", ";
+ $field = $criteria->getGroupby() . ", ";
}
}
$sql = "SELECT {$field} COUNT(*) FROM `{$this->handler->table}`";
if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
$sql .= ' ' . $criteria->renderWhere();
- $sql .= $criteria->getGroupby();
+ if ($criteria->getGroupby() != '') {
+ $sql .= ' GROUP BY (' . $criteria->getGroupby() . ')';
+ }
}
$result = $this->handler->db->query($sql);
if (!$result) {
@@ -87,7 +89,7 @@
$sql_where = $criteria->renderWhere();
$limit = $criteria->getLimit();
$start = $criteria->getStart();
- if ($groupby = $criteria->getGroupbyField()) {
+ if ($groupby = $criteria->getGroupby()) {
$groupby_key = $groupby;
}
}
|