Switch to Doctrine paginator for Doctrine-based queries, update version of ORM in dependencies to fix sorting error.

This commit is contained in:
Buster Silver 2015-04-13 03:57:24 -05:00
parent d9ba19b045
commit 3e4e61314d
5 changed files with 116 additions and 64 deletions

View File

@ -1,17 +1,69 @@
<?php
namespace DF\Paginator;
class Doctrine extends \Zend_Paginator
class Doctrine implements \Countable, \IteratorAggregate
{
protected $_page_number;
protected $_num_per_page;
protected $_query;
protected $_paginator;
public function __construct($query, $page = 1, $limit = 10)
{
if ($query instanceof QueryBuilder)
$this->_page_number = $page;
$this->_num_per_page = $limit;
if ($query instanceof \Doctrine\ORM\QueryBuilder)
$query = $query->getQuery();
$query->setMaxResults($limit);
$query->setFirstResult(($page - 1) * $limit);
$query->setMaxResults($limit);
parent::__construct(new Adapter\DoctrinePaginator($query));
$this->setItemCountPerPage($limit);
$this->setCurrentPageNumber($page);
$this->_query = $query;
$this->_paginator = new \Doctrine\ORM\Tools\Pagination\Paginator($this->_query);
}
public function count()
{
return $this->_paginator->count();
}
public function getIterator()
{
return $this->_paginator->getIterator();
}
public function getPages()
{
$pageCount = ceil($this->_paginator->count() / $this->_num_per_page);
$currentPageNumber = $this->_page_number;
$pages = new \stdClass();
$pages->pageCount = $pageCount;
$pages->itemCountPerPage = $this->_num_per_page;
$pages->first = 1;
$pages->current = $currentPageNumber;
$pages->last = $pageCount;
// Previous and next
if ($currentPageNumber - 1 > 0) {
$pages->previous = $currentPageNumber - 1;
}
if ($currentPageNumber + 1 <= $pageCount) {
$pages->next = $currentPageNumber + 1;
}
// Pages in range
$pages_in_range = array();
for($i = 1; $i <= $pageCount; $i++)
$pages_in_range[] = $i;
$pages->pagesInRange = $pages_in_range;
$pages->firstPageInRange = 1;
$pages->lastPageInRange = $pageCount;
return $pages;
}
}

View File

@ -2,11 +2,12 @@
namespace DF\View\Helper;
class Paginate extends HelperAbstract
{
/**
* @param $pager \DF\Paginator\Doctrine|\Zend_Paginator
* @return string
*/
public function paginate($pager)
{
if (!($pager instanceof \Zend_Paginator))
return '';
$pages = (array)$pager->getPages();
$query_string = '';

View File

@ -40,7 +40,7 @@ class ConventionsController extends BaseController
{
$this->view->coverage = Convention::getCoverageLevels();
$query = $this->em->createQuery('SELECT c FROM Entity\Convention c ORDER BY c.start_date DESC');
$query = $this->em->createQuery('SELECT c FROM Entity\Convention c LEFT JOIN c.signups cs LEFT JOIN c.archives ca ORDER BY c.start_date DESC');
$this->view->pager = new \DF\Paginator\Doctrine($query, $this->getParam('page', 1), 15);
}

View File

@ -3,9 +3,9 @@
"description": "The Ponyville Live! primary application.",
"require": {
"zendframework/zendframework1": "1.12.6",
"doctrine/orm": "v2.4.2",
"doctrine/orm": "2.4.*",
"phpoffice/phpexcel": "1.8.0",
"james-heinrich/getid3": "v1.9.8",
"james-heinrich/getid3": "1.9.8",
"electrolinux/phpquery": "0.9.6",
"google/apiclient": "1.0.*@beta",
"filp/whoops": "1.*"

103
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "fb101dbb29d5e3f183da9b7af8e82e3b",
"hash": "6eb598b72d794bf83943f9557fd3abad",
"packages": [
{
"name": "doctrine/annotations",
@ -80,12 +80,12 @@
"source": {
"type": "git",
"url": "https://github.com/doctrine/cache.git",
"reference": "23210e0381057c5976b15dae52ef389fa180e09f"
"reference": "6c5c32eb6c596993d04e13b95d0c1e8153783d7a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/cache/zipball/23210e0381057c5976b15dae52ef389fa180e09f",
"reference": "23210e0381057c5976b15dae52ef389fa180e09f",
"url": "https://api.github.com/repos/doctrine/cache/zipball/6c5c32eb6c596993d04e13b95d0c1e8153783d7a",
"reference": "6c5c32eb6c596993d04e13b95d0c1e8153783d7a",
"shasum": ""
},
"require": {
@ -96,13 +96,13 @@
},
"require-dev": {
"phpunit/phpunit": ">=3.7",
"predis/predis": "~0.8",
"predis/predis": "~1.0",
"satooshi/php-coveralls": "~0.6"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.4.x-dev"
"dev-master": "1.5.x-dev"
}
},
"autoload": {
@ -142,7 +142,7 @@
"cache",
"caching"
],
"time": "2015-01-11 19:26:38"
"time": "2015-02-16 12:24:01"
},
{
"name": "doctrine/collections",
@ -150,12 +150,12 @@
"source": {
"type": "git",
"url": "https://github.com/doctrine/collections.git",
"reference": "38ed66e6606309bec203a9df506ffa26d956d21d"
"reference": "856cb378598f57b3ab6499b1abeb05836feb5725"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/collections/zipball/38ed66e6606309bec203a9df506ffa26d956d21d",
"reference": "38ed66e6606309bec203a9df506ffa26d956d21d",
"url": "https://api.github.com/repos/doctrine/collections/zipball/856cb378598f57b3ab6499b1abeb05836feb5725",
"reference": "856cb378598f57b3ab6499b1abeb05836feb5725",
"shasum": ""
},
"require": {
@ -208,20 +208,20 @@
"collections",
"iterator"
],
"time": "2014-11-05 15:56:21"
"time": "2015-04-04 16:54:49"
},
{
"name": "doctrine/common",
"version": "dev-master",
"version": "v2.5.0",
"source": {
"type": "git",
"url": "https://github.com/doctrine/common.git",
"reference": "c819359fc0babd36620e4b48d2eb0c6dacbc48a2"
"reference": "cd8daf2501e10c63dced7b8b9b905844316ae9d3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/common/zipball/c819359fc0babd36620e4b48d2eb0c6dacbc48a2",
"reference": "c819359fc0babd36620e4b48d2eb0c6dacbc48a2",
"url": "https://api.github.com/repos/doctrine/common/zipball/cd8daf2501e10c63dced7b8b9b905844316ae9d3",
"reference": "cd8daf2501e10c63dced7b8b9b905844316ae9d3",
"shasum": ""
},
"require": {
@ -238,7 +238,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.5.x-dev"
"dev-master": "2.6.x-dev"
}
},
"autoload": {
@ -281,7 +281,7 @@
"persistence",
"spl"
],
"time": "2015-01-01 17:37:36"
"time": "2015-04-02 19:55:44"
},
{
"name": "doctrine/dbal",
@ -289,12 +289,12 @@
"source": {
"type": "git",
"url": "https://github.com/doctrine/dbal.git",
"reference": "057c07ba0f794bde965818d14542f7610bebb6a8"
"reference": "7ff83816f0bf667a97dffc453f5b2181928ffee7"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/dbal/zipball/057c07ba0f794bde965818d14542f7610bebb6a8",
"reference": "057c07ba0f794bde965818d14542f7610bebb6a8",
"url": "https://api.github.com/repos/doctrine/dbal/zipball/7ff83816f0bf667a97dffc453f5b2181928ffee7",
"reference": "7ff83816f0bf667a97dffc453f5b2181928ffee7",
"shasum": ""
},
"require": {
@ -309,7 +309,8 @@
"symfony/console": "For helpful console commands such as SQL execution and import of files."
},
"bin": [
"bin/doctrine-dbal"
"bin/doctrine-dbal",
"bin/doctrine-dbal.php"
],
"type": "library",
"extra": {
@ -352,7 +353,7 @@
"persistence",
"queryobject"
],
"time": "2015-01-12 11:58:44"
"time": "2015-04-09 13:51:10"
},
{
"name": "doctrine/inflector",
@ -477,16 +478,16 @@
},
{
"name": "doctrine/orm",
"version": "v2.4.2",
"version": "2.4.x-dev",
"source": {
"type": "git",
"url": "https://github.com/doctrine/doctrine2.git",
"reference": "0363a5548d9263f979f9ca149decb9cfc66419ab"
"reference": "0cf7e0e628c1409c9235c9b107c9623a2e8a80ef"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/doctrine2/zipball/0363a5548d9263f979f9ca149decb9cfc66419ab",
"reference": "0363a5548d9263f979f9ca149decb9cfc66419ab",
"url": "https://api.github.com/repos/doctrine/doctrine2/zipball/0cf7e0e628c1409c9235c9b107c9623a2e8a80ef",
"reference": "0cf7e0e628c1409c9235c9b107c9623a2e8a80ef",
"shasum": ""
},
"require": {
@ -523,17 +524,6 @@
"MIT"
],
"authors": [
{
"name": "Jonathan Wage",
"email": "jonwage@gmail.com",
"homepage": "http://www.jwage.com/",
"role": "Creator"
},
{
"name": "Guilherme Blanco",
"email": "guilhermeblanco@gmail.com",
"homepage": "http://www.instaclick.com"
},
{
"name": "Roman Borschel",
"email": "roman@code-factory.org"
@ -541,6 +531,14 @@
{
"name": "Benjamin Eberlei",
"email": "kontakt@beberlei.de"
},
{
"name": "Guilherme Blanco",
"email": "guilhermeblanco@gmail.com"
},
{
"name": "Jonathan Wage",
"email": "jonwage@gmail.com"
}
],
"description": "Object-Relational-Mapper for PHP",
@ -549,7 +547,7 @@
"database",
"orm"
],
"time": "2014-02-08 16:35:09"
"time": "2015-03-31 07:45:37"
},
{
"name": "electrolinux/phpquery",
@ -597,12 +595,12 @@
"source": {
"type": "git",
"url": "https://github.com/filp/whoops.git",
"reference": "542400d23369c3c9f1ff221858ba4b220bcc4245"
"reference": "c982fe62c44798c433229cb0425c61b487cc1883"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/filp/whoops/zipball/542400d23369c3c9f1ff221858ba4b220bcc4245",
"reference": "542400d23369c3c9f1ff221858ba4b220bcc4245",
"url": "https://api.github.com/repos/filp/whoops/zipball/c982fe62c44798c433229cb0425c61b487cc1883",
"reference": "c982fe62c44798c433229cb0425c61b487cc1883",
"shasum": ""
},
"require": {
@ -647,7 +645,7 @@
"whoops",
"zf2"
],
"time": "2014-11-29 09:19:11"
"time": "2015-03-30 15:26:59"
},
{
"name": "google/apiclient",
@ -784,17 +782,17 @@
},
{
"name": "symfony/console",
"version": "2.7.x-dev",
"version": "2.8.x-dev",
"target-dir": "Symfony/Component/Console",
"source": {
"type": "git",
"url": "https://github.com/symfony/Console.git",
"reference": "fdb3285803e812d97988470722129c28343f1415"
"reference": "32f19477d488649a77227d57a7f5775b17cb336b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/Console/zipball/fdb3285803e812d97988470722129c28343f1415",
"reference": "fdb3285803e812d97988470722129c28343f1415",
"url": "https://api.github.com/repos/symfony/Console/zipball/32f19477d488649a77227d57a7f5775b17cb336b",
"reference": "32f19477d488649a77227d57a7f5775b17cb336b",
"shasum": ""
},
"require": {
@ -803,6 +801,7 @@
"require-dev": {
"psr/log": "~1.0",
"symfony/event-dispatcher": "~2.1|~3.0.0",
"symfony/phpunit-bridge": "~2.7|~3.0.0",
"symfony/process": "~2.1|~3.0.0"
},
"suggest": {
@ -813,7 +812,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.7-dev"
"dev-master": "2.8-dev"
}
},
"autoload": {
@ -837,7 +836,7 @@
],
"description": "Symfony Console Component",
"homepage": "http://symfony.com",
"time": "2015-01-09 06:51:41"
"time": "2015-04-11 08:55:16"
},
{
"name": "zendframework/zendframework1",
@ -894,12 +893,12 @@
"source": {
"type": "git",
"url": "https://github.com/phalcon/phalcon-devtools.git",
"reference": "070c3c3a51c81944ae241267e271ee9ce8ebf066"
"reference": "103c8989236f4df5206e7d37508216c46799394a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phalcon/phalcon-devtools/zipball/070c3c3a51c81944ae241267e271ee9ce8ebf066",
"reference": "070c3c3a51c81944ae241267e271ee9ce8ebf066",
"url": "https://api.github.com/repos/phalcon/phalcon-devtools/zipball/103c8989236f4df5206e7d37508216c46799394a",
"reference": "103c8989236f4df5206e7d37508216c46799394a",
"shasum": ""
},
"require": {
@ -930,7 +929,7 @@
"framework",
"phalcon"
],
"time": "2014-12-11 14:36:33"
"time": "2015-02-26 21:47:33"
}
],
"aliases": [],