views:

182

answers:

2

I would like to disregard the first n items in a pager list of items. I.e. they are being used elsewhere in the design.

So my pager list needs to be as such:

Page 1: Items  8 - 17
Page 2: Items 18 - 27
Page 3: Items 28 - 37
...

However, setting an offset or limit in the criteria object does nothing. I presume they are used by the pager itself.

Is it possible to add a offset to the pager class in some other way?

A: 

Ok, I have got around the problem by modifying sfPropelPager.class.php and putting it into a new class file which I have named atPropelPagerOffset.class.php

It works in exactly the same way apart from it takes an extra parameter, $offset

So the top of the file looks like:

  protected
    $criteria               = null,
    $peer_method_name       = 'doSelect',
    $peer_count_method_name = 'doCount',
    $offset                 = 0;

  public function __construct($class, $maxPerPage = 10, $offset = 0)
  {
    parent::__construct($class, $maxPerPage);

    $this->setCriteria(new Criteria());
    $this->tableName = constant($class.'Peer::TABLE_NAME');
    $this->offset = $offset;
  }

Then I have made this tiny change around line 50

  $c->setOffset($offset+$this->offset);

Works a treat!

Jon Winstanley
A: 

Simpler solution would be a custom select method:

$pager->setPeerMethod('doSelectCustom');

and then put your logic in the model Peer Class:

public static function doSelectCustom($c)
{
   $c2 = clone $c;
   $offset = $c2->getOffset();
   $limit = $c2->getLimit();
   $someCustomVar = someClass::someMethod();
   if ($offset == 0) // we are in the first page 
   {
      $c2->setLimit($limit - $someCustomVar);
      $c2->add(self::SOMECOLUMN, false);
   } else $c2->setOffset($offset - $someCustomVar);
   return self::doSelectRS($c2); // or doSelect if you wanna retrieve objects
}
danieli