Last active
January 25, 2016 14:49
-
-
Save sasezaki/e6b888006e96677aa6e1 to your computer and use it in GitHub Desktop.
zf1 paginator diffs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: Adapter/DbSelect.php | |
=================================================================== | |
--- Adapter/DbSelect.php (revision 23657) | |
+++ Adapter/DbSelect.php (revision 23658) | |
@@ -100,7 +100,9 @@ | |
if ($rowCount instanceof Zend_Db_Select) { | |
$columns = $rowCount->getPart(Zend_Db_Select::COLUMNS); | |
- $countColumnPart = $columns[0][1]; | |
+ $countColumnPart = empty($columns[0][2]) | |
+ ? $columns[0][1] | |
+ : $columns[0][2]; | |
if ($countColumnPart instanceof Zend_Db_Expr) { | |
$countColumnPart = $countColumnPart->__toString(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: Adapter/DbSelect.php | |
=================================================================== | |
--- Adapter/DbSelect.php (revision 23716) | |
+++ Adapter/DbSelect.php (revision 23717) | |
@@ -229,8 +229,7 @@ | |
$groupPart = $column; | |
} | |
- } else if (!empty($groupParts) && $groupParts[0] !== Zend_Db_Select::SQL_WILDCARD && | |
- !($groupParts[0] instanceof Zend_Db_Expr)) { | |
+ } else if (!empty($groupParts)) { | |
$groupPart = $db->quoteIdentifier($groupParts[0], true); | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: Adapter/DbSelect.php | |
=================================================================== | |
--- Adapter/DbSelect.php (revision 23723) | |
+++ Adapter/DbSelect.php (revision 23724) | |
@@ -216,7 +216,8 @@ | |
* the original query and use it as a subquery os the COUNT query. | |
*/ | |
if (($isDistinct && count($columnParts) > 1) || count($groupParts) > 1 || !empty($havingParts)) { | |
- $rowCount = $db->select()->from($this->_select); | |
+ $rowCount->reset(Zend_Db_Select::ORDER); | |
+ $rowCount = $db->select()->from($rowCount); | |
} else if ($isDistinct) { | |
$part = $columnParts[0]; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: Adapter/DbSelect.php | |
=================================================================== | |
--- Adapter/DbSelect.php (revision 24571) | |
+++ Adapter/DbSelect.php (revision 24572) | |
@@ -218,7 +218,8 @@ | |
* than one group, or if the query has a HAVING clause, then take | |
* the original query and use it as a subquery os the COUNT query. | |
*/ | |
- if (($isDistinct && count($columnParts) > 1) || count($groupParts) > 1 || !empty($havingParts)) { | |
+ if (($isDistinct && ((count($columnParts) == 1 && $columnParts[0][1] == Zend_Db_Select::SQL_WILDCARD) | |
+ || count($columnParts) > 1)) || count($groupParts) > 1 || !empty($havingParts)) { | |
$rowCount->reset(Zend_Db_Select::ORDER); | |
$rowCount = $db | |
->select() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: Paginator.php | |
=================================================================== | |
--- Paginator.php (revision 24753) | |
+++ Paginator.php (revision 24754) | |
@@ -524,13 +524,26 @@ | |
} | |
/** | |
- * Returns the total number of items available. | |
+ * Returns the total number of items available. Uses cache if caching is enabled. | |
* | |
* @return integer | |
*/ | |
public function getTotalItemCount() | |
{ | |
- return count($this->getAdapter()); | |
+ if (!$this->_cacheEnabled()) { | |
+ return count($this->getAdapter()); | |
+ } else { | |
+ $cacheId = md5($this->_getCacheInternalId(). '_itemCount'); | |
+ $itemCount = self::$_cache->load($cacheId); | |
+ | |
+ if ($itemCount === false) { | |
+ $itemCount = count($this->getAdapter()); | |
+ | |
+ self::$_cache->save($itemCount, $cacheId, array($this->_getCacheInternalId())); | |
+ } | |
+ | |
+ return $itemCount; | |
+ } | |
} | |
/** | |
@@ -1044,10 +1057,18 @@ | |
*/ | |
protected function _getCacheInternalId() | |
{ | |
- return md5(serialize(array( | |
- $this->getAdapter(), | |
- $this->getItemCountPerPage() | |
- ))); | |
+ $adapter = $this->getAdapter(); | |
+ | |
+ if (method_exists($adapter, 'getCacheIdentifier')) { | |
+ return md5(serialize(array( | |
+ $adapter->getCacheIdentifier(), $this->getItemCountPerPage() | |
+ ))); | |
+ } else { | |
+ return md5(serialize(array( | |
+ $adapter, | |
+ $this->getItemCountPerPage() | |
+ ))); | |
+ } | |
} | |
/** | |
@@ -1057,7 +1078,7 @@ | |
*/ | |
protected function _calculatePageCount() | |
{ | |
- return (integer) ceil($this->getAdapter()->count() / $this->getItemCountPerPage()); | |
+ return (integer) ceil($this->getTotalItemCount() / $this->getItemCountPerPage()); | |
} | |
/** |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment