This file is indexed.

/usr/share/php/propel/util/PropelPager.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
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
<?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
 */

/**
 *  PropelPager
 *
 *  Example Usage:
 *
 *  require_once 'propel/util/PropelPager.php';
 *  require_once 'PEACH/Propel/Poem/poemPeer.php';
 *
 *  $c = new Criteria();
 *  $c->addDescendingOrderByColumn(poemPeer::SID);
 *
 *  // with join
 *  $pager = new PropelPager($c, 'poemPeer', 'doSelectJoinPoemUsers', 1, 50);
 *
 *  // without Join
 *
 *  $pager = new PropelPager($c, 'poemPeer', 'doSelect', 1, 50);
 *
 * Some template:
 *
 * <p>
 * Total Pages: <?=$pager->getTotalPages()?>  Total Records: <?=$pager->getTotalRecordCount()?>
 * </p>
 * <table>
 * <tr>
 * <td>
 * <?if ($link = $pager->getFirstPage):?>
 * <a href="somescript?page=<?=$link?>"><?=$link?></a>|
 * <?endif?>
 * </td>
 * <td>
 * <?if ($link = $pager->getPrev()):?>
 * <a href="somescript?page=<?=$link?>">Previous</a>|
 * <?endif?>
 * </td>
 * <td>
 * <?foreach ($pager->getPrevLinks() as $link):?>
 * <a href="somescript?page=<?=$link?>"><?=$link?></a>|
 * <?endforeach?>
 * </td>
 * <td><?=$pager->getPage()?></td>
 * <td>
 * <?foreach ($pager->getNextLinks() as $link):?>
 * | <a href="somescript?page=<?=$link?>"><?=$link?></a>
 * <?endforeach?>
 * </td>
 * <td>
 * <?if ($link = $pager->getNext()):?>
 * <a href="somescript?page=<?=$link?>">Last</a>|
 * <?endif?>
 * </td>
 * <td>
 * <?if ($link = $pager->getLastPage()):?>
 * <a href="somescript?page=<?=$link?>"><?=$link?></a>|
 * <?endif?>
 * </td>
 * </tr>
 * </table>
 * <table id="latestPoems">
 * <tr>
 * <th>Title</th>
 * <th>Auteur</th>
 * <th>Date</th>
 * <th>comments</th>
 * </tr>
 * <?foreach ($pager->getResult() as $poem):?>
 * <tr>
 * <td><?=$poem->getTitle()?></td>
 * <td><?=$poem->getPoemUsers()->getUname()?></td>
 * <td><?=$poem->getTime()?></td>
 * <td><?=$poem->getComments()?></td>
 * </tr>
 * <?endforeach?>
 * </table>
 *
 *
 * @author     Rob Halff <info@rhalff.com>
 * @author	   Niklas Närhinen <niklas@narhinen.net>
 * @version    $Revision$
 * @copyright  Copyright (c) 2004 Rob Halff: LGPL - See LICENCE
 * @package    propel.runtime.util
 */
class PropelPager implements Countable, Iterator
{

    private $recordCount;
    private $pages;
    private $peerClass;
    private $peerSelectMethod;
    private $peerCountMethod;
    private $criteria;
    private $countCriteria;
    private $page;
    private $rs = null;

    //Iterator vars
    private $currentKey = 0;

    /** @var        int Start row (offset) */
    protected $start = 0;

    /** @var        int Max rows to return (0 means all) */
    protected $max = 0;

    /**
     * Create a new Propel Pager.
     * @param Criteria $c
     * @param string   $peerClass        The name of the static Peer class.
     * @param string   $peerSelectMethod The name of the static method for selecting content from the Peer class.
     * @param int      $page             The current page (1-based).
     * @param int      $rowsPerPage      The number of rows that should be displayed per page.
     */
    public function __construct($c = null, $peerClass = null, $peerSelectMethod = null, $page = 1, $rowsPerPage = 25)
    {
        if (!isset($c)) {
            $c = new Criteria();
        }
        $this->setCriteria($c);
        $this->setPeerClass($peerClass);
        $this->setPeerSelectMethod($peerSelectMethod);
        $this->guessPeerCountMethod();
        $this->setPage($page);
        $this->setRowsPerPage($rowsPerPage);
    }

    /**
     * Set the criteria for this pager.
     * @param  Criteria $c
     * @return void
     */
    public function setCriteria(Criteria $c)
    {
        $this->criteria = $c;
    }

    /**
     * Return the Criteria object for this pager.
     * @return Criteria
     */
    public function getCriteria()
    {
        return $this->criteria;
    }

    /**
     * Set the Peer Classname
     *
     * @param  string $class
     * @return void
     */
    public function setPeerClass($class)
    {
        $this->peerClass = $class;
    }

    /**
     * Return the Peer Classname.
     * @return string
     */
    public function getPeerClass()
    {
        return $this->peerClass;
    }

    /**
     * Set the Peer select method.
     * This exists for legacy support, please use setPeerSelectMethod().
     * @param  string $method The name of the static method to call on the Peer class.
     * @return void
     * @see        setPeerSelectMethod()
     * @deprecated
     */
    public function setPeerMethod($method)
    {
        $this->setPeerSelectMethod($method);
    }

    /**
     * Return the Peer select method.
     * This exists for legacy support, please use getPeerSelectMethod().
     * @return string
     * @see        getPeerSelectMethod()
     * @deprecated
     */
    public function getPeerMethod()
    {
        return $this->getPeerSelectMethod();
    }

    /**
     * Set the Peer select method.
     *
     * @param  string $method The name of the static method to call on the Peer class.
     * @return void
     */
    public function setPeerSelectMethod($method)
    {
        $this->peerSelectMethod = $method;
    }

    /**
     * Return the Peer select method.
     * @return string
     */
    public function getPeerSelectMethod()
    {
        return $this->peerSelectMethod;
    }

    /**
     * Sets the Count method.
     * This is set based on the Peer method, for example if Peer method is doSelectJoin*() then the
     * count method will be doCountJoin*().
     * @param string $method The name of the static method to call on the Peer class.
     */
    public function setPeerCountMethod($method)
    {
        $this->peerCountMethod = $method;
    }

    /**
     * Return the Peer count method.
     */
    public function getPeerCountMethod()
    {
        return $this->peerCountMethod;
    }

    /**
     * Guesses the Peer count method based on the select method.
     */
    private function guessPeerCountMethod()
    {
        $selectMethod = $this->getPeerSelectMethod();
        if ($selectMethod == 'doSelect') {
            $countMethod = 'doCount';
        } elseif ( ($pos = stripos($selectMethod, 'doSelectJoin')) === 0) {
            $countMethod = 'doCount' . substr($selectMethod, strlen('doSelect'));
        } else {
            // we will fall back to doCount() if we don't understand the join
            // method; however, it probably won't be accurate.  Maybe triggering an error would
            // be appropriate ...
            $countMethod = 'doCount';
        }
        $this->setPeerCountMethod($countMethod);
    }

    /**
     * Get the paged resultset
     *
     * @return mixed $rs
     */
    public function getResult()
    {
        if (!isset($this->rs)) {
            $this->doRs();
        }

        return $this->rs;
    }

    /**
     * Get the paged resultset
     *
     * Main method which creates a paged result set based on the criteria
     * and the requested peer select method.
     *
     */
    private function doRs()
    {
        $this->criteria->setOffset($this->start);
        $this->criteria->setLimit($this->max);
        $this->rs = call_user_func(array($this->getPeerClass(), $this->getPeerSelectMethod()), $this->criteria);
    }

    /**
     * Get the first page
     *
     * For now I can only think of returning 1 always.
     * It should probably return 0 if there are no pages
     *
     * @return int 1
     */
    public function getFirstPage()
    {
        return '1';
    }

    /**
     * Convenience method to indicate whether current page is the first page.
     *
     * @return boolean
     */
    public function atFirstPage()
    {
        return $this->getPage() == $this->getFirstPage();
    }

    /**
     * Get last page
     *
     * @return int $lastPage
     */
    public function getLastPage()
    {
        $totalPages = $this->getTotalPages();
        if ($totalPages == 0) {
            return 1;
        } else {
            return $totalPages;
        }
    }

    /**
     * Convenience method to indicate whether current page is the last page.
     *
     * @return boolean
     */
    public function atLastPage()
    {
        return $this->getPage() == $this->getLastPage();
    }

    /**
     * get total pages
     *
     * @return int $this->pages
     */
    public function getTotalPages()
    {
        if (!isset($this->pages)) {
            $recordCount = $this->getTotalRecordCount();
            if ($this->max > 0) {
                    $this->pages = ceil($recordCount/$this->max);
            } else {
                    $this->pages = 0;
            }
        }

        return $this->pages;
    }

    /**
     * get an array of previous id's
     *
     * @param  int   $range
     * @return array $links
     */
    public function getPrevLinks($range = 5)
    {
        $total = $this->getTotalPages();
        $start = $this->getPage() - 1;
        $end = $this->getPage() - $range;
        $first =  $this->getFirstPage();
        $links = array();
        for ($i=$start; $i>$end; $i--) {
            if ($i < $first) {
                    break;
            }
            $links[] = $i;
        }

        return array_reverse($links);
    }

    /**
     * get an array of next id's
     *
     * @param  int   $range
     * @return array $links
     */
    public function getNextLinks($range = 5)
    {
        $total = $this->getTotalPages();
        $start = $this->getPage() + 1;
        $end = $this->getPage() + $range;
        $last =  $this->getLastPage();
        $links = array();
        for ($i=$start; $i<$end; $i++) {
            if ($i > $last) {
                    break;
            }
            $links[] = $i;
        }

        return $links;
    }

    /**
     * Returns whether last page is complete
     *
     * @return bool Last page complete or not
     */
    public function isLastPageComplete()
    {
        return !($this->getTotalRecordCount() % $this->max);
    }

    /**
     * get previous id
     *
     * @return mixed $prev
     */
    public function getPrev()
    {
        if ($this->getPage() != $this->getFirstPage()) {
                $prev = $this->getPage() - 1;
        } else {
                $prev = false;
        }

        return $prev;
    }

    /**
     * get next id
     *
     * @return mixed $next
     */
    public function getNext()
    {
        if ($this->getPage() != $this->getLastPage()) {
                $next = $this->getPage() + 1;
        } else {
                $next = false;
        }

        return $next;
    }

    /**
     * Set the current page number (First page is 1).
     * @param  int  $page
     * @return void
     */
    public function setPage($page)
    {
        $this->page = $page;
        // (re-)calculate start rec
        $this->calculateStart();
    }

    /**
     * Get current page.
     * @return int
     */
    public function getPage()
    {
        return $this->page;
    }

    /**
     * Set the number of rows per page.
     * @param int $r
     */
    public function setRowsPerPage($r)
    {
        $this->max = $r;
        // (re-)calculate start rec
        $this->calculateStart();
    }

    /**
     * Get number of rows per page.
     * @return int
     */
    public function getRowsPerPage()
    {
        return $this->max;
    }

    /**
     * Calculate startrow / max rows based on current page and rows-per-page.
     * @return void
     */
    private function calculateStart()
    {
        $this->start = ( ($this->page - 1) * $this->max );
    }

    /**
     * Gets the total number of (un-LIMITed) records.
     *
     * This method will perform a query that executes un-LIMITed query.
     *
     * @return int Total number of records - disregarding page, maxrows, etc.
     */
    public function getTotalRecordCount()
    {

                if (!isset($this->rs)) {
                    $this->doRs();
                }

                if (empty($this->recordCount)) {
                        $this->countCriteria = clone $this->criteria;
                        $this->countCriteria->setLimit(0);
                        $this->countCriteria->setOffset(0);

                        $this->recordCount = call_user_func(
                                        array(
                                                $this->getPeerClass(),
                                                $this->getPeerCountMethod()
                                             ),
                                        $this->countCriteria
                                        );

                }

                return $this->recordCount;

    }

    /**
     * Sets the start row or offset.
     * @param int $v
     */
    public function setStart($v)
    {
        $this->start = $v;
    }

    /**
     * Sets max rows (limit).
     * @param  int  $v
     * @return void
     */
    public function setMax($v)
    {
        $this->max = $v;
    }

    /**
     * Returns the count of the current page's records
     * @return int
     */
    public function count()
    {
        return count($this->getResult());
    }

    /**
     * Returns the current element of the iterator
     * @return mixed
     */
    public function current()
    {
        if (!isset($this->rs)) {
            $this->doRs();
        }

        return $this->rs[$this->currentKey];
    }

    /**
     * Returns the current key of the iterator
     * @return int
     */
    public function key()
    {
        return $this->currentKey;
    }

    /**
     * Advances the iterator to the next element
     * @return void
     */
    public function next()
    {
        $this->currentKey++;
    }

    /**
     * Resets the iterator to the first element
     * @return void
     */
    public function rewind()
    {
        $this->currentKey = 0;
    }

    /**
     * Checks if the current key exists in the container
     * @return boolean
     */
    public function valid()
    {
        if (!isset($this->rs)) {
            $this->doRs();
        }

        return in_array($this->currentKey, array_keys($this->rs));
    }

}