Exemple #1
0
 public function render($columns = array())
 {
     if ($columns) {
         $this->columns = $columns;
     }
     $link = new A_Pagination_Helper_Link($this->pager, $this->url);
     $links = array();
     foreach ($this->columns as $column => $label) {
         $links[] = $column ? $link->order($column, $label) : $label;
     }
     return implode($this->separator, $links);
 }
include 'config.php';
include dirname(__FILE__) . '/../../A/autoload.php';
// initialize an array for testing
for ($i = 0; $i <= 750; ++$i) {
    $myarray[$i]['title'] = 'This is row ' . $i;
    $myarray[$i]['month'] = date('F', time() + $i * 60 * 60 * 24 * 30);
}
// create a data object that has the interface needed by the Pager object
$datasource = new Datasource($myarray);
// create a request processor to set pager from GET parameters
$pager = new A_Pagination_Request($datasource);
// set range (number of links on either side of current page) and process core based on request
// pass superglobal directly
$pager->setRangeSize(3)->process($_GET);
// create a new link helper
$link = new A_Pagination_Helper_Link($pager);
// retrieve items on current page
$rows = $pager->getItems();
// create links using helper directly
$links = '';
$links .= $link->previous('Previous');
$links .= $link->first();
$links .= $link->range();
$links .= $link->last();
$links .= $link->next('Next');
// display the data
echo "<div>{$links}</div>";
echo '<table border="1">';
echo '<tr><th>' . $link->order('', 'Row') . '</th><th>' . $link->order('title', 'Title') . '</th><th>' . $link->order('month', 'Month') . '</th></tr>';
$n = 1;
foreach ($rows as $value) {
include 'config.php';
include dirname(__FILE__) . '/../../A/autoload.php';
// initialize an array for testing
for ($i = 0; $i <= 750; ++$i) {
    $myarray[$i]['title'] = 'This is row ' . $i;
    $myarray[$i]['month'] = date('F', time() + $i * 60 * 60 * 24 * 30);
}
#$myarray = null;
// create a data object that has the interface needed by the Pager object
$datasource = new Datasource($myarray);
// create a request processor to set pager from GET parameters
$pager = new A_Pagination_Request($datasource);
// set range (number of links on either side of current page) and process core based on request
$pager->setRangeSize(3)->process();
// create a new link helper
$link = new A_Pagination_Helper_Link($pager);
// create a new order link helper
$order = new A_Pagination_Helper_Order($pager, $url, array('' => 'Row', 'title' => 'Title', 'month' => 'Month'));
// retrieve items on current page
$rows = $pager->getItems();
// display the paging links ... should this go in a template?
$links = '';
$links .= $link->first('First');
$links .= $link->previous('Previous');
$links .= $link->range();
$links .= $link->next('Next');
$links .= $link->last('Last');
// display the data
echo "<div>{$links}</div>";
echo '<table border="1">';
echo '<tr><th>' . $order->render() . '</th></tr>';
Exemple #4
0
 public function testRangeWithHtmlRenderer()
 {
     $core = $this->createCore();
     $linkHelper = new A_Pagination_Helper_Link($core, new MockUrlHelper());
     $tag = new A_Html_A(array('class' => 'foobar'));
     $linkHelper->setRenderer($tag);
     $linkHelper->alwaysShowFirstLast(true);
     $this->assertEqual($linkHelper->first('baz'), '<a class="foobar" href="foo">baz</a> ');
 }