TKPagedView Class Reference
[Components]

Data paginator for TK. More...

Inheritance diagram for TKPagedView:

Inheritance graph
[legend]

List of all members.

Public Member Functions

 __construct ($name, $callback, $useAjax=false, $saveState=false)
 Creates new Paged View object.
 handleAjax ()
 Handles Ajax updates.

Protected Member Functions

 build ()
 Generates the view.
 buildButtonBox ($start, $end, $total, $number)
 Creates the navigation button boxes.
 buildTable ($data)
 Generates table of paged date.
 renderContainer ($class, $style, $events, $id)
 Renders this view.

Private Member Functions

 buildAjax ($offset, $perPage=null)
 Creates JavaScript call to initiate Ajax page transition.
 buildURL ($offset)
 Creates URL for non-Ajax transitions.


Detailed Description

Data paginator for TK.

This class implements a data paginator. Data is fed to this object via a callback. All of the navigation between pages is handled by this object. It provides a few other features, such as Ajax transitions, scroll view the internal table and animations.

The basic way to use the paginator, without Ajax, is the following:

 // Create the paginator
 $pv = new TKPagedView('test', 'populateView');

 // Initialize the paginator (set the headers and the title)
 $pv->headers = array('Column One', 'Column Two');
 $pv->title = 'Test Paged View';
 // Could optionally change the table class as well
 //$pv->tableObjectClass = 'TKIPlusTable';

 // Build the component (fills in data, etc.)
 $pv->build();

 // Add to the page and print
 $prm->add($pv);

 $prm->renderPrint();

 // This is the callback, it takes three parameters:
 //  $name - name of the TKPagedView object (in this case, it will be 'test')
 //  $offset - start data at this offset
 //  $perPage - and produce up to this many results
 // The callback returns an array with the first element being the 2D array of data
 // to ppopulate the table with, and the second being the total number of results in
 // the data set
 function populateView($name, $offset, $perPage) {
     $data = array();

     for($i = $offset + 1; $i < $perPage + $offset + 1; $i++)
          $data[] = array($i, "This is some data");

     return array($data, 100);
 }

If you want to use Ajax, you just set the third parameter to the constructor to true and then call handleAjax() on the object before calling build(). It will take care of the rest of the details:

 $pv = new TKPagedView('test', 'populateView', true);

 // Initialize the paginator (set the headers and the title)
 $pv->headers = array('Column One', 'Column Two');
 $pv->title = 'Test Paged View';

 // Could optionally change the table class as well
 //$pv->tableObjectClass = 'TKIPlusTable';

 // we may also want the Ajax to animate
 $pv->animate = true;

 // Handle the Ajax
 $pv->handleAjax();

 // Build the component (fills in data, etc.)
 $pv->build();

 ... (same as before)

Definition at line 73 of file TKPagedView.php5.


Constructor & Destructor Documentation

TKPagedView::__construct ( name,
callback,
useAjax = false,
saveState = false 
)

Creates new Paged View object.

You must create the paged view object before calling handleAjax() if you are using Ajax page transitions.

Parameters:
$name [string]: name of this paged view (used to distinguish different paged views on the same page)
$callback [callback]: function to call to populate the table
$useAjax [boolean]: if true, use Ajax for paging, rather than a page refresh

Definition at line 90 of file TKPagedView.php5.

References TKComponent::addProperty(), and TKComponent::setId().


Member Function Documentation

TKPagedView::build (  )  [protected]

Generates the view.

This method is to be called before the object is to be rendered. Any configuration options set after build() are likely to be ignored. This method calls the callback specified in the costructor. This method is not called automatically when rendering to make it so that the population of data can be done when the user requires it, rather than at a possibly late point in script execution (rendering).

Returns:
[boolean]: success or failure

Definition at line 158 of file TKPagedView.php5.

References TKContainer::addText(), buildButtonBox(), buildTable(), Toolkit::classToString(), and SObject::setError().

Referenced by renderContainer().

TKPagedView::buildAjax ( offset,
perPage = null 
) [private]

Creates JavaScript call to initiate Ajax page transition.

For internal use only.

The JavaScript call just calls a function which does the Ajax and transition, providing enough information to update the view.

Parameters:
$offset [int]: page offset
$perPage [int]: Results per page
Returns:
[string]: JavaScript to go into onclick handler

Definition at line 417 of file TKPagedView.php5.

References TKComponent::$id, and TKComponent::getId().

TKPagedView::buildButtonBox ( start,
end,
total,
number 
) [protected]

Creates the navigation button boxes.

For internal use only.

Parameters:
$start [int]: start offset
$end [int]: final index to be displayed on this page
$total [int]: total number of items across all pages
$number [int]: Increment this each time the function is called to ensure unique tag ids
Returns:
[TKHBox]: navigation button box

Definition at line 235 of file TKPagedView.php5.

Referenced by build().

TKPagedView::buildTable ( data  )  [protected]

Generates table of paged date.

For internal use only.

This method takes the data retrieves from the callback and puts it into a table. The class of the table is specified with the tableObjectClass property.

Parameters:
$data [array]: two-dimensional array of data to put into table
Returns:
[TKTable]: table object

Definition at line 436 of file TKPagedView.php5.

Referenced by build().

TKPagedView::buildURL ( offset  )  [private]

Creates URL for non-Ajax transitions.

For internal use only.

The URL is constructed by updating (or adding) a NAME_offset request variable to the URL.

Parameters:
$offset [int]: offset that the URL should request
Returns:
[string]: complete URL that links to another page in the view

Definition at line 375 of file TKPagedView.php5.

TKPagedView::handleAjax (  ) 

Handles Ajax updates.

Call this method after initializing the view object. If the script was invoked to get an Ajax response, this method will take care of building and rendering the result and exiting the script. If Ajax is disabled, or there is no Ajax request to process, this method does nothing, so it is always safe to have it.

Definition at line 582 of file TKPagedView.php5.

References TKComponent::$html, STimer::enable(), and TKComponent::render().

TKPagedView::renderContainer ( class,
style,
events,
id 
) [protected]

Renders this view.

For internal use only.

Other than rendering the children added by build(), this method also adds the Ajax JavaScript, if Ajax is enabled.

Parameters:
$class [array]: class info
$style [array]: style info
$events [string]: JS events
$id [string]: object id
Returns:
[string]: rendered HTML

Reimplemented from TKContainer.

Definition at line 517 of file TKPagedView.php5.

References TKComponent::$html, build(), TKContainer::getChildrenBySlot(), TKComponent::getId(), Toolkit::globalAddExtraJS(), and Toolkit::issetJS().


The documentation for this class was generated from the following file:

Generated on Wed Nov 24 02:07:03 2010 for Common by  doxygen 1.5.6