Friday 1st February 2008

by Sajith M.R

If you are a symfony programmer, just read this. Otherwise you can skip this topic. We all know that one of the useful thing in every website creation is the pagination. Symfony uses propel pagination for showing database records page by page.

But suppose the case of showing records from different table . You cannot use normal pager class of propel to show the results form multiple table. For that purpose you need to get the results as result set and have to create custom pagination by adding setLimit to the criteria.

But when i develop mobshare search page, the requirement is that when a key or pattern is search , the first page needed to contain all the results, means mixed results from photos, videos and users. But the data are stored in three different tables : Photos , Videos and Users.

So i created a turing machine like structure. Its geographical structure is like three tapes aligned in parellel and a head and level tracker read the data from these three tapes simultaneously . These tapes represents each pager. Head is the reader and level indicates which tape is currently reading . These tapes are arrange in small to high manner in the order of number of results of each pager.

Propel multiple pager

Click read more:

See the code i have made:


$ObjectRsArray = array();
$PagerArray = array();

if($this->UserPager->getLastPage() >= $this->getRequestParameter(’page’,1) )
{
$ObjectRsArray[] = $this->UserPager->getResults();
$PagerArray[]=$this->UserPager;
}

if($this->PhotosPager->getLastPage() >= $this->getRequestParameter(’page’,1) )
{
$ObjectRsArray[] = $this->PhotosPager->getResults();
$PagerArray[]=$this->PhotosPager;

}

if($this->VideosPager->getLastPage() >= $this->getRequestParameter(’page’,1) )
{
$ObjectRsArray[] = $this->VideosPager->getResults();
$PagerArray[]=$this->VideosPager;
}

$this->ObjectRsArray = math::SortObjects($ObjectRsArray);

$this->MainPager = math::getBigPager( $PagerArray );

//The math lib is as below:

 count($a[$j]) )
list ($a[$j],$a[$i]) = array($a[$i],$a[$j]);

return $a;

}

public function getBigPager($a)
{
for($i=0;$igetResults() ) > count($a[$j]->getResults() ) )
list ($a[$j],$a[$i]) = array($a[$i],$a[$j]);

return end($a);

}
}

//These all happen in the action area. Now in the template, user normal pagination for the big pager, because big pager contains the maximum pages.

//And for showing mixed results use the below code (turing machine implementation ):

//Here the record is $ObjectRsArray[$reader][$head].

//You can use this object to show your results. eg: $ObjectRsArray[$reader][$head]->getId()

//etc.

Tags:

· · · ◊ ◊ ◊ · · ·

2 Responses to “Symfony (Propel) Pagination on Multiple Tables”

  1. Sean Dundon says:

    Hey man, half of your math class is missing. I can see the <?php tag in the source, but mozilla must be preventing rendering or something. Good work, though, and I appreciate your effort. Saved me a lot of time.

  2. Ganesh says:

    Hello Sajit,

    I am symfony programer, i have use symfony, but when i propel pagination for showing database records page by page. i found that suppose i want to show 10 records out 50 records at that time pager fetch all 50 records and show only 10 records.
    This makes page to take more time when it loads.Actually it has to fetch only 10 records and to show them.

    Do you have solution for this.
    any suggestion from you will help me.

· · · ◊ ◊ ◊ · · ·

Leave a Reply

وظائف 2011 تحويل العملات برامج برنامج تسريع التحميل برنامج الفلاش برنامج محول الصوتيات عربي hotel 2011 زيادة رواتب العساكر 1431