/usr/share/php/propel/util/PropelModelPager.php is in php-propel-runtime 1.6.9-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 | <?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
/**
* Implements a pager based on a ModelCriteria
* The code from this class heavily borrows from symfony's sfPager class
*
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @author François Zaninotto
* @version $Revision$
* @package propel.runtime.query
*/
class PropelModelPager implements IteratorAggregate, Countable
{
protected
$query = null,
$page = 1,
$maxPerPage = 10,
$lastPage = 1,
$nbResults = 0,
$objects = null,
$parameters = array(),
$currentMaxLink = 1,
$parameterHolder = null,
$maxRecordLimit = false,
$results = null,
$resultsCounter = 0,
$con = null;
public function __construct(ModelCriteria $query, $maxPerPage = 10)
{
$this->setQuery($query);
$this->setMaxPerPage($maxPerPage);
}
public function setQuery(ModelCriteria $query)
{
$this->query = $query;
}
public function getQuery()
{
return $this->query;
}
public function init($con = null)
{
$this->con = $con;
$hasMaxRecordLimit = ($this->getMaxRecordLimit() !== false);
$maxRecordLimit = $this->getMaxRecordLimit();
$qForCount = clone $this->getQuery();
$count = $qForCount
->offset(0)
->limit(0)
->count($this->con);
$this->setNbResults($hasMaxRecordLimit ? min($count, $maxRecordLimit) : $count);
$q = $this->getQuery()
->offset(0)
->limit(0);
if (($this->getPage() == 0 || $this->getMaxPerPage() == 0)) {
$this->setLastPage(0);
} else {
$this->setLastPage((int) ceil($this->getNbResults() / $this->getMaxPerPage()));
$offset = ($this->getPage() - 1) * $this->getMaxPerPage();
$q->offset($offset);
if ($hasMaxRecordLimit) {
$maxRecordLimit = $maxRecordLimit - $offset;
if ($maxRecordLimit > $this->getMaxPerPage()) {
$q->limit($this->getMaxPerPage());
} else {
$q->limit($maxRecordLimit);
}
} else {
$q->limit($this->getMaxPerPage());
}
}
}
/**
* Get the collection of results in the page
*
* @return PropelCollection A collection of results
*/
public function getResults()
{
if (null === $this->results) {
$this->results = $this->getQuery()
->find($this->con);
}
return $this->results;
}
public function getCurrentMaxLink()
{
return $this->currentMaxLink;
}
public function getMaxRecordLimit()
{
return $this->maxRecordLimit;
}
public function setMaxRecordLimit($limit)
{
$this->maxRecordLimit = $limit;
}
public function getLinks($nb_links = 5)
{
$links = array();
$tmp = $this->page - floor($nb_links / 2);
$check = $this->lastPage - $nb_links + 1;
$limit = ($check > 0) ? $check : 1;
$begin = ($tmp > 0) ? (($tmp > $limit) ? $limit : $tmp) : 1;
$i = (int) $begin;
while (($i < $begin + $nb_links) && ($i <= $this->lastPage)) {
$links[] = $i++;
}
$this->currentMaxLink = count($links) ? $links[count($links) - 1] : 1;
return $links;
}
/**
* Test whether the number of results exceeds the max number of results per page
*
* @return boolean true if the pager displays only a subset of the results
*/
public function haveToPaginate()
{
return (($this->getMaxPerPage() != 0) && ($this->getNbResults() > $this->getMaxPerPage()));
}
/**
* Get the index of the first element in the page
* Returns 1 on the first page, $maxPerPage +1 on the second page, etc
*
* @return int
*/
public function getFirstIndex()
{
if ($this->page == 0) {
return 1;
} else {
return ($this->page - 1) * $this->maxPerPage + 1;
}
}
/**
* Get the index of the last element in the page
* Always less than or eaqual to $maxPerPage
*
* @return int
*/
public function getLastIndex()
{
if ($this->page == 0) {
return $this->nbResults;
} else {
if (($this->page * $this->maxPerPage) >= $this->nbResults) {
return $this->nbResults;
} else {
return ($this->page * $this->maxPerPage);
}
}
}
/**
* Get the total number of results of the query
* This can be greater than $maxPerPage
*
* @return int
*/
public function getNbResults()
{
return $this->nbResults;
}
/**
* Set the total number of results of the query
*
* @param int $nb
*/
protected function setNbResults($nb)
{
$this->nbResults = $nb;
}
/**
* Check whether the current page is the first page
*
* @return boolean true if the current page is the first page
*/
public function isFirstPage()
{
return $this->getPage() == $this->getFirstPage();
}
/**
* Get the number of the first page
*
* @return int Always 1
*/
public function getFirstPage()
{
return 1;
}
/**
* Check whether the current page is the last page
*
* @return boolean true if the current page is the last page
*/
public function isLastPage()
{
return $this->getPage() == $this->getLastPage();
}
/**
* Get the number of the last page
*
* @return int
*/
public function getLastPage()
{
return $this->lastPage;
}
/**
* Set the number of the first page
*
* @param int $page
*/
protected function setLastPage($page)
{
$this->lastPage = $page;
if ($this->getPage() > $page) {
$this->setPage($page);
}
}
/**
* Get the number of the current page
*
* @return int
*/
public function getPage()
{
return $this->page;
}
/**
* Set the number of the current page
*
* @param int $page
*/
public function setPage($page)
{
$this->page = intval($page);
if ($this->page <= 0) {
// set first page, which depends on a maximum set
$this->page = $this->getMaxPerPage() ? 1 : 0;
}
}
/**
* Get the number of the next page
*
* @return int
*/
public function getNextPage()
{
return min($this->getPage() + 1, $this->getLastPage());
}
/**
* Get the number of the previous page
*
* @return int
*/
public function getPreviousPage()
{
return max($this->getPage() - 1, $this->getFirstPage());
}
/**
* Get the maximum number results per page
*
* @return int
*/
public function getMaxPerPage()
{
return $this->maxPerPage;
}
/**
* Set the maximum number results per page
*
* @param int $max
*/
public function setMaxPerPage($max)
{
if ($max > 0) {
$this->maxPerPage = $max;
if ($this->page == 0) {
$this->page = 1;
}
} elseif ($max == 0) {
$this->maxPerPage = 0;
$this->page = 0;
} else {
$this->maxPerPage = 1;
if ($this->page == 0) {
$this->page = 1;
}
}
}
/**
* Check whether the internal pointer is at the beginning of the list
* @see PropelCollection
*
* @return boolean
*/
public function isFirst()
{
return $this->getResults()->isFirst();
}
/**
* Check whether the internal pointer is at the end of the list
* @see PropelCollection
*
* @return boolean
*/
public function isLast()
{
return $this->getResults()->isLast();
}
/**
* Check if the collection is empty
* @see PropelCollection
*
* @return boolean
*/
public function isEmpty()
{
return $this->getResults()->isEmpty();
}
/**
* Check if the current index is an odd integer
* @see PropelCollection
*
* @return boolean
*/
public function isOdd()
{
return $this->getResults()->isOdd();
}
/**
* Check if the current index is an even integer
* @see PropelCollection
*
* @return boolean
*/
public function isEven()
{
return $this->getResults()->isEven();
}
public function getIterator()
{
return $this->getResults()->getIterator();
}
/**
* Returns the total number of results.
*
* @see Countable
* @return int
*/
public function count()
{
return $this->getNbResults();
}
}
|