Permalink
Browse files

[Opc trunk] Work on docs (Class, Paginator, Visit and Visit_UserAgent)

[Opc trunk] New paginator decorator: "Range Slider"
  • Loading branch information...
eXtreme committed Aug 10, 2009
1 parent 53de6be commit de47f159f229a1d6390f76a5c31dc27c33bc349f
View
@@ -16,9 +16,9 @@
$pager = Opc_Paginator::create(1000, 13); // returns Opc_Paginator_Pager;
$pager->all = 1000;
$pager->page = isset($_GET['page']) ? $_GET['page'] : 1;
- //$pager->offset = 13;
+ //$pager->offset = 174;
+
-
echo "<ul>";
foreach(new LimitIterator(new ArrayIterator(range(1, $pager->all)), $pager->offset, $pager->limit) as $i)
{
@@ -116,6 +116,35 @@
}
echo '</p>';
+
+ $pager->decorator = 'range_slider';
+ $pager->decorator->range = 10;
+
+ echo '<p>';
+ foreach($pager as $page)
+ {
+ switch($page['item'])
+ {
+ case 'current': echo ' <strong>['.$page['number'].']</strong> '; break;
+ case 'number': echo ' <a href="?page='.$page['number'].'">'.$page['number'].'</a> '; break;
+ }
+ }
+ echo '</p>';
+
+ $pager->decorator = 'range_slider';
+ $pager->decorator->range = 9;
+
+ echo '<p>';
+ foreach($pager as $page)
+ {
+ switch($page['item'])
+ {
+ case 'current': echo ' <strong>['.$page['number'].']</strong> '; break;
+ case 'number': echo ' <a href="?page='.$page['number'].'">'.$page['number'].'</a> '; break;
+ }
+ }
+ echo '</p>';
+
echo '<p>';
$first = $pager->first;
@@ -0,0 +1,53 @@
+Title: Opc_Class
+
+---
+
+The main class for **Open Power Classes**. It contains few factories for some classes and some default configuration options for them.
+
+Some of OPC classes also require the existance of `Opc_Class` instance in the code.
+
+ [php]
+ $opc = new Opc_Class;
+
+> [important]
+> It is suggested to create an instance of `Opc_Class` even you use a class which does not require it.
+
+Default configurations
+======================
+
+With `$opc` instance we can now configure some default option values for some classes.
+
+### For `Opc_View_Cache`
+
+`cacheDir`
+: Default cache directory.
+
+`expiryTime`
+: Cache expiry time. Default: **3600**.
+
+### For `Opc_Paginator`
+
+`itemsPerPage`
+: Default value for Opc_Paginator_Range->limit - the items per page number. Default: **10**.
+
+`paginatorDecorator`
+: Default paginator decorator. Defualt: `all`.
+
+`paginatorDecoratorOptions`
+: Default options for default decorator.
+
+Example usage
+-------------
+
+~~~
+[php]
+$opc->cacheDir = dirname(__FILE__).'/cache/';
+$opc->expiryTime = 86400;
+
+$opc->itemsPerPage = 15;
+$opc->paginatorDecorator = 'slider';
+$opc->paginatorDecoratorOptions = array(
+ 'chunk' => 5,
+ 'around' => 3
+);
+~~~
@@ -30,7 +30,7 @@ foreach($pager as $page)
echo ' <strong>['.$page['number'].']</strong> '; break;
case 'number':
echo ' <a href="?page='.$page['number'].'">'.$page['number'].'</a> '; break;
- }
+ }
}
echo '</p>';
~~~~
@@ -0,0 +1,50 @@
+Title: Range Slider
+
+---
+
+Range slider is a next variation of ["slider"][classes.paginator.decorators.slider] decorator. It allways returns a defined number of pages, even if the current is at the beginning, in the middle or at the end.
+
+Settings
+========
+
+Name | Type | Default | Description
+------- | ------- | ------- |:-----------
+`range` | integer | 9 | Number of pages in range.
+
+Returned elements
+=================
+
+Item | Keys | Description
+--------- | -------- |:-----------
+`current` | `number` | Current page number.
+ | `offset` | The offset of current number.
+`number` | `number` | Current page number.
+ | `offset` | The offset of current number.
+
+Sample usage
+============
+
+~~~~
+[php]
+$pager->decorator = 'range_slider';
+$pager->decorator->range = 9;
+
+echo '<p>';
+foreach($pager as $page)
+{
+ switch($page['item'])
+ {
+ case 'current':
+ echo ' <strong>['.$page['number'].']</strong> '; break;
+ case 'number':
+ echo ' <a href="?page='.$page['number'].'">'.$page['number'].'</a> '; break;
+ }
+}
+echo '</p>';
+~~~~
+
+> #### The results:
+>
+> [1](#none) **[2]** [3](#none) [4](#none) [5](#none) [6](#none) [7](#none) [8](#none) [9](#none)
+
+> [27](#none) [28](#none) [29](#none) [30](#none) **[31]** [32](#none) [33](#none) [34](#none) [35](#none)
@@ -2,6 +2,23 @@ Title: Decorators overview
----
-Decorator is a class, which is used by the paginator to create a list of pages.
+Decorator is a class, which is used by the paginator to create a range pages.
-Opc_Paginator provides 5 built-in decorators.
+Opc_Paginator provides 6 built-in decorators.
+
+Name | Alias | Class name
+:-------------- |:----------------- |:----------
+All | `all` | `Opc_Paginator_Decorator_All`
+Jumper | `jumper` | `Opc_Paginator_Decorator_Jumper`
+Slider | `slider` | `Opc_Paginator_Decorator_Slider`
+Dotting Slider | `dotting_slider` | `Opc_Paginator_Decorator_DottingSlider`
+Range Slider | `range_slider` | `Opc_Paginator_Decorator_RangeSlider`
+Stepping Slider | `stepping_slider` | `Opc_Paginator_Decorator_SteppingSlider`
+
+Registering an alias of custom decorator
+========================================
+
+~~~
+[php]
+Opc_Paginator::registerDecorator($aliasName, $className);
+~~~
@@ -2,3 +2,67 @@ Title: Integration with Open Power Template 2
----
+Using `Opc_Paginator` with **Open Power Template 2** is really easy. You don't need to add any adapter of change the class. The only work you need to do in the PHP side is to define data formats:
+
+~~~
+[php]
+$view = new Opt_View('news.tpl');
+
+$pager = Opc_Paginator::create(1000, 13);
+$pager->page = isset($_GET['page']) ? $_GET['page'] : 1;
+
+$view->pager = $pager;
+$view->setFormat('pager', 'Objective/Array');
+$view->setFormat('pager.decorator', 'Objective');
+~~~
+
+> [important]
+> As OPC is in early development stage, setting dataformats isn't "user-friendly". We will later work on custom "Paginator" dataformat. But by now it must be defined in this way.
+
+On the template side `Opc_Paginator` excellently works with `opt:selector` instruction. It is also easy to change a decorator and set it's options.
+
+~~~
+[xml]
+<p>
+{$pager.decorator is 'slider'}
+{$pager.decorator.chunk is 5}
+<opt:selector name="pager">
+ <opt:number> <a parse:href="'?page='~$pager.number">{$pager.number}</a> </opt:number>
+ <opt:current> <strong>[{$pager.number}]</strong> </opt:current>
+ <opt:gap> ... </opt:gap>
+</opt:selector>
+</p>
+~~~
+
+Item types become `<opt:itemName>` nodes.
+
+Working with snippets
+=====================
+
+It isn't necessary to repeat the design for decorators all the time, because OPT2 provides a system called "snippets". Snippets are pieces of code which can be reused in different contextes.
+
+~~~
+[xml]
+<opt:snippet name="pagerSlider">
+ <opt:number> <a parse:href="'?page='~$pagerSlider.number">{$pagerSlider.number}</a> </opt:number>
+ <opt:current> <strong>[{$pagerSlider.number}]</strong> </opt:current>
+ <opt:gap> ... </opt:gap>
+</opt:snippet>
+
+<opt:snippet name="pagerSteppingSlider">
+ <opt:number> <a parse:href="'?page='~$pagerSteppingSlider.number">{$pagerSteppingSlider.number}</a> </opt:number>
+ <opt:current> <strong>[{$pagerSteppingSlider.number}]</strong> </opt:current>
+ <opt:step> <a parse:href="'?page='~$pagerSteppingSlider.number"><small>{$pagerSteppingSlider.number}</small></a> </opt:step>
+</opt:snippet>
+~~~
+
+Then we can use those snippets with pagers:
+
+~~~
+[xml]
+{$pager1.decorator is 'slider'}
+<p><opt:selector name="pager1" opt:use="pagerSlider" /></p>
+
+{$pager2.decorator is 'stepping_slider'}
+<p><opt:selector name="pager2" opt:use="pagerSteppingSlider" /></p>
+~~~
@@ -2,4 +2,9 @@ Title: Opc_Paginator
----
-`Opc_Paginator` is a class for paginating on data sets.
+`Opc_Paginator` is a class for paginating on data sets.
+
+1. `Opc_Paginator` is datasource-independent - no need to create any adapters for arrays, iterators, database etc.
+2. The class provides 6 built-in page range decorators.
+3. Paging outputs are fully customizable.
+4. The class can be easily integrated with Open Power Template 2.
Oops, something went wrong.

0 comments on commit de47f15

Please sign in to comment.