This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use the new forum.
Home » development » Feature requests » sfpager::getPage();
sfpager::getPage(); [message #82372] Wed, 22 July 2009 23:07 Go to next message
misch  is currently offline misch
Messages: 3
Registered: July 2009
Junior Member
Hi!

I am studing the sfpager object to extend it to my needs. And in the course of it I had the following idea:

Additional to the normal page numbers I have buttons +10, +50,-10, -50 in my pagination. Now it would be easier to get the correct values for [-/+10] and [-/+50] near an end of list, if the getPage function would be extended in the following way:

public function getPage($relMovement = 0)
{

  if( $this->getPage() + $relMovement < $this->getFirstPage() )
    return -$this->getPage();

  if( $this->getPage() + $relMovement > $this->getLastPage() )
    return  $this->getLastPage() - $this->getPage();

  return $this->getPage();
}


It's not much, it's not a big thing, but it's making the world a better one Wink

regards,

Michael

p.s.: Symfony is the first php framework I learned, but it's what I was looking for for years. Great work.

[Updated on: Wed, 22 July 2009 23:17]


http://www.kineticarm.com
http://www.dikeytus.com
http://www.lueftenegger.at
Re: sfpager::getPage(); [message #82374 is a reply to message #82372 ] Wed, 22 July 2009 23:19 Go to previous messageGo to next message
misch  is currently offline misch
Messages: 3
Registered: July 2009
Junior Member
Hi!

Ok, I have seen this doesn't work. You would get the relative movement, but no absolute target page for the url.

I think it's definitly too late to code today. Sorry.

Michael


http://www.kineticarm.com
http://www.dikeytus.com
http://www.lueftenegger.at
Re: sfpager::getPage(); [message #82393 is a reply to message #82372 ] Thu, 23 July 2009 09:36 Go to previous message
misch  is currently offline misch
Messages: 3
Registered: July 2009
Junior Member
Good morning!

A new day brings a new try Wink

public function getPage($relMovement = 0)
{

  // if no parameter is given the function is backward compatible
  if($relMovement == 0)
    retuen $this->getPage();

  // if a parameter is defined the function returns a hash with "label" and "page"
  // for relative movement in the list.
  // Example with current page = 3:
  /*
   * $tmp = getPage(-10);
   *
   * echo $tmp["label"]; // echos -3
   * echo $tmp["page"];  // echos 1
  */
  
  if( $this->getPage() + $relMovement < $this->getFirstPage() )
    return array( "label" => -$this->getPage(), "page" => max( $this->getPage()+$relMovement, $this->getFirstPage) );

  if( $this->getPage() + $relMovement > $this->getLastPage() )
    return array( "label" => $this->getLastPage() - $this->getPage(), "page" => min( $this->getPage()+$relMovement, $this->getLastPage ) );

  return array( "label" => $this->getPage() + $relMovement, "page" => $this->getPage() + $relMovement );
  
}


Advantages:
The calculation of the relative movement is done in the pager class and the user doesn't have to care about it.

Disadvantages:
I think it's bad practice to vary the return value.
The function is much bigger.

Another version could be to add a getLabel function.

public function getLabel($relMovement = 0)
{

  if( $this->getPage() + $relMovement < $this->getFirstPage() )
    return -$this->getPage();

  if( $this->getPage() + $relMovement > $this->getLastPage() )
    return  $this->getLastPage() - $this->getPage();

  return $this->getPage()+$relMovement;
}

public function getPage($relMovement = 0)
{

  if( $this->getPage() + $relMovement < $this->getFirstPage() )
    return max( $this->getPage()+$relMovement, $this->getFirstPage) );

  if( $this->getPage() + $relMovement > $this->getLastPage() )
    return min( $this->getPage()+$relMovement, $this->getLastPage ) )

  return $this->getPage() + $relMovement;
  
}


While writing it I see the second version makes more sense and looks much better.

regards,

Michael


http://www.kineticarm.com
http://www.dikeytus.com
http://www.lueftenegger.at
Previous Topic:sfActions : renderJson
Next Topic:Data Table Descriptor
Goto Forum:
  

powered by FUDforum - copyright ©2001-2004 FUD Forum Bulletin Board Software