1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Pagerfanta package. |
5
|
|
|
* |
6
|
|
|
* (c) Pablo Díez <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Pagerfanta\Adapter; |
13
|
|
|
|
14
|
|
|
use Doctrine\ORM\Tools\Pagination\Paginator as DoctrinePaginator; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* DoctrineORMAdapter. |
18
|
|
|
* |
19
|
|
|
* @author Christophe Coevoet <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
class DoctrineORMAdapter implements AdapterInterface |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var \Doctrine\ORM\Tools\Pagination\Paginator |
25
|
|
|
*/ |
26
|
|
|
private $paginator; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Constructor. |
30
|
|
|
* |
31
|
|
|
* @param \Doctrine\ORM\Query|\Doctrine\ORM\QueryBuilder $query A Doctrine ORM query or query builder. |
32
|
|
|
* @param boolean $fetchJoinCollection Whether the query joins a collection (true by default). |
33
|
|
|
* @param boolean|null $useOutputWalkers Whether to use output walkers pagination mode |
34
|
|
|
*/ |
35
|
8 |
|
public function __construct($query, $fetchJoinCollection = true, $useOutputWalkers = null) |
36
|
|
|
{ |
37
|
8 |
|
$this->paginator = new DoctrinePaginator($query, $fetchJoinCollection); |
38
|
8 |
|
$this->paginator->setUseOutputWalkers($useOutputWalkers); |
39
|
8 |
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Returns the query |
43
|
|
|
* |
44
|
|
|
* @return \Doctrine\ORM\Query |
45
|
|
|
*/ |
46
|
|
|
public function getQuery() |
47
|
|
|
{ |
48
|
|
|
return $this->paginator->getQuery(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Returns whether the query joins a collection. |
53
|
|
|
* |
54
|
|
|
* @return boolean Whether the query joins a collection. |
55
|
|
|
*/ |
56
|
|
|
public function getFetchJoinCollection() |
57
|
|
|
{ |
58
|
|
|
return $this->paginator->getFetchJoinCollection(); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* {@inheritdoc} |
63
|
|
|
*/ |
64
|
6 |
|
public function getNbResults() |
65
|
|
|
{ |
66
|
6 |
|
return count($this->paginator); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* {@inheritdoc} |
71
|
|
|
*/ |
72
|
6 |
|
public function getSlice($offset, $length) |
73
|
|
|
{ |
74
|
6 |
|
$this->paginator |
75
|
6 |
|
->getQuery() |
76
|
6 |
|
->setFirstResult($offset) |
77
|
6 |
|
->setMaxResults($length); |
78
|
|
|
|
79
|
6 |
|
return $this->paginator->getIterator(); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|