whiteoctober / pagerfanta Goto Github PK
View Code? Open in Web Editor NEWThis project forked from babdev/pagerfanta
Pagination for PHP.
License: Other
This project forked from babdev/pagerfanta
Pagination for PHP.
License: Other
[moved to PageFantaBundle issues]
I'm using the WhiteOctoberPagerfantaBundle and I'm wondering if it's possible to add anchor, like #sometext
, at the end of the generated pagination links.
Is it possible without modification?
The refactoring in 103a140 broke all paging we had on packagist.
The following twig code returned the proper number of pages before the commit, but after the commit it returns null even though calling the getNbPages() method by hand in the controller works fine. {{ pager.nbPages }}
seems to be like twig can't detect properly which value to read for this method.
Due to an added argument for the constructor of SelectExpression
in doctrine/orm@ebe9338, the following warning occurs: Warning: Missing argument 3 for Doctrine\ORM\Query\AST\SelectExpression::__construct(), called in vendor\whiteoctober-pagerfanta\src\Pagerfanta\Adapter\DoctrineORM\CountWalker.php on line 60 and defined in vendor\doctrine\lib\Doctrine\ORM\Query\AST\SelectExpression.php line 42
I have three records in a database
19| 156.71
20| 184.50
22| 212.26
$query = $em->getRepository('M\E\Q')
->createQueryBuilder('q')
->select('q', 'SUM(q.price) AS amount')
->where('q.id IN(19, 20, 22)')
->groupBy('q.customer')
;
$pager = new Pagerfanta(new DoctrineORMAdapter($query));
$pager->setMaxPerPage(30);
$pager->setCurrentPage($request->query->get('page', 1));
$result = $pager->getCurrentPageResults();
print_r($result[0]['amount']); // 156.71 - Incorrect
$result = $query->getQuery()->getResult();
print_r($result[0]['amount']); // 553.47
When I do new DoctrineORMAdapter($query, false)
both return page and direct result return 553.47
Isn't it a bug?
Hi everyone. I have some problem in pagination with pagerfanta (that use doctrine native pagination class)
See issue http://www.doctrine-project.org/jira/browse/DDC-2381
Marco Pivetta sets status Minor and i don't know when the problem will fixed.
Use case: we have products query with one2many join. We are displaying N products on page with button "load all products". So we need select all products (setMaxPerPage
) except first N.
In order to avoid the potential count query for pagers the Drupal project uses a common pattern
since quite a while which allows you to skip the count query in the first place.
The basic idea is to query always for one more item than you want. If there is one more item, we know that there is another page, otherwise there is none.
This can be a huge performance boost for big sites.
Do you plan to provide support for such a pager?
Tbh. I haven't used pagerfanta to be able to suggest anything but it seems to be that we could split up the adapter interface into one providing count and one without count. This then would require quite some work on the View side as well.
Currently DoctrineORM is fetching results as entities (default).
Is it possible to change the hydration mode for a specific paginator to Doctrine\ORM\Query::HYDRATE_ARRAY ?
Hey guys there is an style problem with bootstrap 3, is there a variable to determinate the bootstrap version?
FraGoTe/chamilo-lms@129095f
This issue is pertinent to Pagerfanta\Adapter\DoctrineORMAdapter.
I've run into performance problems with the way that the 'count' part of the pagination query is being constructed as referenced in the following issues (across multiple projects) (using MySQL):
KnpLabs/knp-components#77
doctrine/orm#298
KnpLabs/knp-components#65
KnpLabs/KnpPaginatorBundle#202
beberlei/DoctrineExtensions#59
This issue will be relevant to anyone using the paginator with MySQL and anything approaching a large number of rows in a database (for me 80k) - when it can take > 100 seconds to execute the count part of the query on a modest amount of data.
My goal here is to simplify the poorly performing query being generated, given that I'm not performing any join or group conditions (and I appreciate why the below structure may be required if this were the case), I have no need for either the 'distinct' subquery, nor the inner subquery it selects from. I'm trying to get from this:
SELECT
COUNT(*) AS dctrn_count
FROM
(
SELECT
DISTINCT id0
FROM
(
SELECT
o0_.id AS id0,
o0_.ordr_id AS ordr_id1,
...etc
FROM
ordr_status o0_
WHERE
some_property = 'something'
) dctrn_result
) dctrn_table
to this:
SELECT COUNT(*) AS dctrn_count
FROM ordr_status o0_
WHERE some_property = 'something'
or this (I don't care about the DISTINCT as it doesn't seem to hurt performance):
SELECT COUNT(DISTINCT id0) AS dctrn_count
FROM ordr_status o0_
WHERE some_property = 'something'
It seems the way to do this is to avoid using the 'Doctrine\ORM\Tools\Pagination\CountOutputWalker' within the Doctrine paginator.
I've tried a variety of changing query walkers, query hints, and changing options in the paginator, and I've found I can achieve what I want by doing this in the DoctrineORMAdapter constructor:
$this->paginator = new DoctrinePaginator($query, false);
$this->paginator->setUseOutputWalkers(false);
So:
Could/Should the option to disable use of output walker be available in the adapter constructor:
public function __construct($query, $fetchJoinCollection = true, $useOutputWalkers = true)
{
if (class_exists('Doctrine\ORM\Tools\Pagination\Paginator')) {
$this->paginator = new DoctrinePaginator($query, $fetchJoinCollection);
if (!$useOutputWalkers) {
$this->paginator->setUseOutputWalkers(false);
}
} else {
$this->paginator = new LegacyPaginator($query, $fetchJoinCollection);
}
}
OR is there an alternative way to get this behaviour (such as setting a hint on the query before passing it to the adapter) that I've missed.
I'm trying integrate FOSUserBundle with the admingenerator and i have the next error :
[1/2] ErrorException: Notice: Undefined offset: 0 in /media/OS/admingen/vendor/doctrine/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php line 1048 -+
in /media/OS/admingen/vendor/symfony/src/Symfony/Component/HttpKernel/Debug/ErrorHandler.php at line 65 -+
}
if (error_reporting() & $level && $this->level & $level) {
throw new \ErrorException(sprintf('%s: %s in %s line %d', isset($this->levels[$level]) ? $this->levels[$level] : $level, $message, $file, $line));
}
return false;
at ErrorHandler ->handle ('8', 'Undefined offset: 0', '/media/OS/admingen/vendor/doctrine/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php', '1048', array())
in /media/OS/admingen/vendor/doctrine/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php at line 1048 -+
at ClassMetadataInfo ->getSingleIdentifierFieldName ()
in /media/OS/admingen/vendor/pagerfanta/src/Pagerfanta/Adapter/DoctrineORM/CountWalker.php at line 53 -+
at CountWalker ->walkSelectStatement (object(SelectStatement))
in /media/OS/admingen/vendor/doctrine/lib/Doctrine/ORM/Query/TreeWalkerChain.php at line 71 -+
at TreeWalkerChain ->walkSelectStatement (object(SelectStatement))
in /media/OS/admingen/vendor/doctrine/lib/Doctrine/ORM/Query/Parser.php at line 315 -+
at Parser ->parse ()
in /media/OS/admingen/vendor/doctrine/lib/Doctrine/ORM/Query.php at line 213 -+
at Query ->_parse ()
in /media/OS/admingen/vendor/doctrine/lib/Doctrine/ORM/Query.php at line 234 -+
at Query ->_doExecute ()
in /media/OS/admingen/vendor/doctrine/lib/Doctrine/ORM/AbstractQuery.php at line 584 -+
at AbstractQuery ->execute (array(), '3')
in /media/OS/admingen/vendor/doctrine/lib/Doctrine/ORM/AbstractQuery.php at line 436 -+
at AbstractQuery ->getScalarResult ()
in /media/OS/admingen/vendor/pagerfanta/src/Pagerfanta/Adapter/DoctrineORMAdapter.php at line 87 -+
at DoctrineORMAdapter ->getNbResults ()
in /media/OS/admingen/vendor/pagerfanta/src/Pagerfanta/Pagerfanta.php at line 167 -+
at Pagerfanta ->getNbResults ()
at call_user_func_array (array(object(Pagerfanta), 'getnbResults'), array())
in kernel.root_dir/cache/dev/classes.php at line 8242 -+
at Twig_Template ->getAttribute (object(Pagerfanta), 'nbResults', array(), 'any', false)
in kernel.root_dir/cache/dev/twig/4d/e9/f3a08f2aa62f910902280fb93940.php at line 77 -
I use {{ pagerfanta(Users, 'admingenerator') }}
, my view class is here : https://github.com/cedriclombardot/AdmingeneratorGeneratorBundle/blob/master/Pagerfanta/View/AdmingenratorView.php
And my getPager is :
<?php
protected function getPager()
{
$paginator = new Pagerfanta(new PagerAdapter($this->getQuery()));
$paginator->setMaxPerPage(10);
$paginator->setCurrentPage($this->getPage(), false, true);
return $paginator;
}
The resultset in Solarium has additional methods to get things like the facetset. The visibility of getResultSet() is private which means you can't access these without doing another query.
Perhaps just change the getResultSet() visibility to public?
hi,
I try to use order by whit a not mapped field, like this :
Select AVG(xxx) as alias From ... Where ... Order By alias
in LimitSubqueryWalker :
$item->expression->identificationVariable,
$item->expression->field
this properties dont exists for an order by whit not mapped field and make an error.
But when I bypass the code (just for test) I have a SQLwalker error.
Problem appear when we use fetch joined collections and not mapped field in order by, the subquery generation fail.
I have a previous query Hint (from the Translatable extension) that is not copied when pagerfanta DoctrineORMAdapter clones the original query. It copies the params via setParams, but the previously set hints are lost
You should add twig helpers to make the rendering simpler:
{{ pagerfanta(data, options) }}
It should contain a factory to decide how data is transformed into an adapter.
Maybe have views be defined as container services by name and allow specifying them in the pagerfanta helper.
After the vendors update today I've got the following error message:
Argument #2 is not an array in ....../PagerfantaBundle/Twig/PagerfantaExtension.php line 73
The issue seem to be related to a recent commit:
sampart/WhiteOctoberPagerfantaBundle@0162c30#comments
..
I'm closing the issue as I figured out that the following would work as expected:
[WhiteOctoberPagerfantaBundle]
git=http://github.com/whiteoctober/WhiteOctoberPagerfantaBundle.git
target=/bundles/WhiteOctober/PagerfantaBundle
version=origin/symfony2.0
in the Pagerfanta.php:
public function getNbResults()
{
if (null === $this->nbResults) {
$this->nbAllResults = $this->getAdapter()->getNbResults();
}
return $this->nbAllResults;
}
should be:
public function getNbResults()
{
if (null === $this->nbResults) {
$this->nbResults = $this->getAdapter()->getNbResults();
}
return $this->nbResults;
}
Why $pagerfanta->getNbResults() return null ?
I use the doctrine2 master version and doctrine-common 3
Thanks
Bertrand
I have been looking at this for 2 hours and cannot figure out why this wont work
This is in my controller
$pager = new Pagerfanta(new DoctrineORMAdapter($query));
try {
$pager
->setMaxPerPage($max)
->setCurrentpage($page);
} catch (OutOfRangeCurrentPageException $e) {
throw $this->createNotFoundException($e->getMessage());
}
return $this->render($template, array('pager' => $pager));
This is in my template
{{ pagerfanta(pager, 'twitter_bootstrap_translated') }}
This is my response:
ContextErrorException: Warning: array_merge(): Argument #2 is not an array in site/vendor/white-october/pagerfanta-bundle/WhiteOctober/PagerfantaBundle/Twig/PagerfantaExtension.php line 119
I'm receiving this exception when trying to get current page results :
Single id is not allowed on composite primary key in entity Nk\PlayerBundle\Entity\Message_Player
I need theses 2 @id I've in my Entity @manytoone associations to other Entities.
Can you help me ?
Thanks!
With latest Doctrine I'm getting Fatal error: Call to undefined method Doctrine\ORM\Query\AST\PathExpression::isSimpleArithmeticExpression() in vendor\doctrine\lib\Doctrine\ORM\Query\SqlWalker.php on line 2018
. It's still working with 931bebe.
I think, TemplateInterface needs to be imported as it's not defined in the same folder as DefaultView.
https://github.com/whiteoctober/Pagerfanta/blob/master/src/Pagerfanta/View/DefaultView.php#L33
Assuming the current page is set to 1 by default, and that setCurrentPage(1)
is allowed when there is no result, I think getNbPages
should also return 1 when there is no result.
I think there is always 1 page (even an empty one).
I'm asking this because I use something like this:
$pagerfanta->setCurrentPage(min($page, $pagerfanta->getNbPages()));
Where $page
is coming from the request. If there is no result, I get a LessThan1CurrentPageException
.
At least, $pagerfanta->setCurrentPage($pagerfanta->getNbPages());
should work flawlessly even if there is no result.
Could u please implement repo version tags?
I don't know if this is a real issue, but I think must tell you.
First, I use Pagerfanta on Symfony 2.0.X.
The best way is an example, I use a query like this:
$q = $em->createQueryBuilder();
$q->select('a, b, c');
$q->from('AcmeBundle:Aaa','a JOIN a.bbb b LEFT JOIN b.ccc c');
$q->addOrderBy('c.foo', 'ASC');
I use an "order by" in a field that is aggregate in an "left join".
This cause the result of the query (that search the id's in the getIterator() method) add the "c.foo" field to the select stament, and this miss the distinct of a.id, because now the select stament is "DISTINCT a.id, c.foo" and this must be only "DISTINCT a.id".
The problem is: id's obtained is a repetition of "a.id" for each "c.foo" distinct element, this break the count of the paginator.
I think the query that search id's will be similar to the query that get the count (except the count function), only where clause's and one field on select stament.
The order by clause is only required in the last query that get the final result (I think).
My query builder looks like this:
$queryBuilder = new QueryBuilder($db);
$queryBuilder
->select('i.*', 'u.name', '(SELECT count(v.id) FROM my_vote v WHERE v.image_id = i.id) AS votes')
->from('my_image', 'i')
->leftJoin('i', 'my_user', 'u', 'i.user_id = u.id')
;
I want to order by the number of votes so I add
$queryBuilder->orderBy('votes', 'DESC');
With a statement object and fetchAll this works fine, but when given to pagerfanta, the column is not found and a PDO exception is thrown
Uncaught exception 'PDOException' with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'votes' in 'order clause''
hi,
how i can add class in the ?
thank.
Why did pager need all submodules ? Deps have to be in application side. Doesn't ?
Enabling PhpAnalyzer in Scrutinizer to perform static analysis of the code would make scrutinizer much more useful than it is currently, by detecting more issues
You can add a doctrine collection adapter for the doctrine\Common\Collections\Collection interface. The implementations would be count($this->collection); and $this->collection->slice($offset, $length);
Very simple. But with 2.1 Extra Lazy collections this would even be very efficient for Doctrine ORM.
I saw recently that the PagerfantaInterface was deprecated, but the ViewInterface still uses that deprecated interface. Should this be modified too?
Link to the master version of ViewInterface:
https://github.com/whiteoctober/Pagerfanta/blob/master/src/Pagerfanta/View/ViewInterface.php
this project is under MIT but this two files claim to be "new BSD" with a link to "GPL2" :)
https://github.com/whiteoctober/Pagerfanta/blob/master/src/Pagerfanta/Adapter/DoctrineORM/LimitSubqueryWalker.php#L26
https://github.com/whiteoctober/Pagerfanta/blob/master/src/Pagerfanta/Adapter/DoctrineORM/WhereInWalker.php#L35
The view option 'proximity' cannot be defined to 0. When defined to 0, It seems that the proximity is automatically pushed to 2. This is a really hard constraint to use pagerfanta on mobile templates...
In Solarium v3 there are two ways to set the endpoint (afaik): $client->setDefaultEndpoint() (or it uses the first in the configuration) and $client->execute($query, $endpoint). With the SolariumAdapter, there is no way to set that.
I propose adding a public method SolariumAdapter::setEndpoint() and a property $endpoint.
Then change return $this->client->select($this->query);
to return $this->client->select($this->query, $this->endpoint);
The getFetchJoinCollection
method has no return statement...
nt
Seriously? :-)
Just integrate this code please: https://github.com/beberlei/DoctrineExtensions/tree/master/lib/DoctrineExtensions/Paginate
Hello,
I have a Doctrine query builder that include a COUNT :
$qb = $this->createQueryBuilder('i');
$qb->select('i','COUNT(c.id) as number')
with different option for ordering the datas :
By ID :
$qb->addOrderBy('i.id', 'DESC');
By Number
$qb->addOrderBy('nombre', 'DESC');
In the first case, no issue.
Is the second one, i get this error :
Notice: Trying to get property of non-object in /vendor/doctrine/orm/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php line 174
When I execute this command :
$pagerfanta->getCurrentPageResults();
Do you have any ideas about this issue ?
How can I resolve it ?
Thank you,
Pierre
Hi,
I encountered a hard to debug problem. I have a total number of content of 4, I want 1 result per page. So I have something like :
$myContentRepository()
->findByMyCriteria($criteria)
->setCurrentPage(2)
->setMaxPerPage(4);
Which leads to Page "2" does not exist. The currentPage must be inferior to "1". 500 Internal Server Error - OutOfRangeCurrentPageException
.
I have to invert the order of the setters for the query to work, like :
$myContentRepository()
->findByMyCriteria($criteria)
->setMaxPerPage(4)
->setCurrentPage(2);
I understand it's logical to set the maxPerPage before the currentPage, otherwise PagerFanta can't know how many pages there are. Seeing how much time I spent finding this, I think it would be nice to explicit this point in documentation. Or maybe the check for the number of pages happen too early.
Have found an issue in the default view, not sure whether also implies to other views.
Function calculateStartAndEndPage set the endpage to 0 when having 0 results.
range() makes it an array of pages : 1, 0
My fix is to check whether the ending page is not less then the starting page;
Original code ~ line 110 - 126:
private function calculateStartAndEndPage()
{
$startPage = $this->currentPage - $this->proximity;
$endPage = $this->currentPage + $this->proximity;
if ($this->startPageUnderflow($startPage)) {
$endPage = $this->calculateEndPageForStartPageUnderflow($startPage, $endPage);
$startPage = 1;
}
if ($this->endPageOverflow($endPage)) {
$startPage = $this->calculateStartPageForEndPageOverflow($startPage, $endPage);
$endPage = $this->nbPages;
}
$this->startPage = $startPage;
$this->endPage = $endPage;
}
Altered code:
private function calculateStartAndEndPage()
{
$startPage = $this->currentPage - $this->proximity;
$endPage = $this->currentPage + $this->proximity;
if ($this->startPageUnderflow($startPage)) {
$endPage = $this->calculateEndPageForStartPageUnderflow($startPage, $endPage);
$startPage = 1;
}
if ($this->endPageOverflow($endPage)) {
$startPage = $this->calculateStartPageForEndPageOverflow($startPage, $endPage);
$endPage = $this->nbPages;
}
$endPage = $endPage < $startPage ? $startPage : $endPage;
$this->startPage = $startPage;
$this->endPage = $endPage;
}
The MongoAdapter does not clone the MongoCursor before applying the limit and offset on it. this means that calling getSlice
before calling getNbResults
will break it (counting the results will then count the results on the current page instead of all of them).
this is exactly why the Doctrine ORM pagination is cloning the query before paginating it for instance
/cc @sergponomaryov
Hello
i am using Zend framework 2 and Doctrine 2 . i just downloaded the zip module for Pagefanta and then uploaded the module to my vendor folder.
i also added the Pagefanta to my config file. however, i then received teh following message:
Fatal error: Uncaught exception 'Zend\ModuleManager\Exception\RuntimeException' with message 'Module (Pagerfanta) could not be initialized.'
i would be really grateful if you could give me any advise on how to load this module.
also, are there any tutorials on how to use Pagefanta. i found a tutorial on how to use it for symphony: https://waaave.com/tutorial/symfony2/install-and-manage-pagerfanta-in-symfony2/
, but non for zend framework 2.
warm regards
Paul
I wanted to raise that I'm not convinced of the design decision that setCurrentPage() actually does a check for whether the provided page number exists in the eventual result set up front. To my mind, setCurrentPage() is something that is done before the query is made/ results are requested, and in practice you can normally assume that the page exists (as the chances are that if you're requesting the second page of a pagination, you've been linked by an explicit pagination link). An exception could be thrown if, once the result has been fetched, it can be established from that that the page does not exist. I can't see the practical benefit of an up-front check.
There are consequences of this also such as, for example, causing two separate queries using the Solarium adapter, with one of these queries (the one that is only used to fetch the number of results) fetching back by default a larger result set than the one whose result documents we are actually to iterate.
I could write PRs, but just wanted to raise the issue for discussion first, in case there's a better argument why you might want to check out-of-range up front.
I have a query which returns all my images with the amount of votes they have.
my_vote has a FK with my_vote.image_id which points to my_image.id.
$queryBuilder = new QueryBuilder($db);
$queryBuilder
->select('i.*', 'u.name', 'COUNT(v.id)')
->from('my_image', 'i')
->leftJoin('i', 'my_user', 'u', 'i.user_id = u.id')
->leftJoin('i', 'my_vote', 'v', 'v.image_id = i.id')
->groupBy('i.id')
;
The SQL looks like this:
SELECT i.*, u.name, COUNT(v.id) FROM my_image i LEFT JOIN my_user u ON i.user_id = u.id LEFT JOIN my_vote v ON v.image_id = i.id GROUP BY i.id
Unfortunately even though I should have three pages of results, I only get one page. The groupBy seems to be the one causing this. My count modifier looks like this:
$countQueryModifier = function ($queryBuilder) {
$queryBuilder
->select('COUNT(DISTINCT i.id) AS total_results')
->setMaxResults(1)
;
};
For some reason the groupBy is causing only one page to be shown. I guess the total results amount becomes messed up for some reason.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.