ultimix

- Main Page
- Data Structures
- Files
- Examples

- File List
- Globals

paginator.php
Go to the documentation of this file.
1 <?php
2
3 /*
4 * This source code is a part of the Ultimix Project.
5 * It is distributed under BSD license. All other third side source code (like tinyMCE) is distributed under
6 * it's own license wich could be found from the corresponding files or sources.
7 * This source code is provided "as is" without any warranties or garanties.
8 *
9 * Have a nice day!
10 *
11 * @url http://ultimix.sorceforge.net
12 *
13 * @author Alexey "gdever" Dodonov
14 */
15
26 class paginator_1_0_0{
27
38 var $CachedMultyFS = false;
39
54 function __construct()
55 {
56 try
57 {
58 $this->CachedMultyFS = get_package( 'cached_multy_fs' , 'last' , __FILE__ );
59 }
60 catch( Exception $e )
61 {
62 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
63 }
64 }
65
88 private function get_record_count( &$Settings )
89 {
90 try
91 {
92 $Query = $Settings->get_setting( 'count_query' );
93
94 $Database = get_package( 'database' , 'last' , __FILE__ );
95
96 $Result = $Database->query( $Query );
97
98 $Records = $Database->fetch_results( $Result );
99
100 return( get_field( $Records[ 0 ] , 'record_count' ) );
101 }
102 catch( Exception $e )
103 {
104 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
105 }
106 }
107
130 function compile_paginator( &$Settings )
131 {
132 try
133 {
134 $Code = '';
135 $RecordCount = $this->get_record_count( $Settings );
136 $RecordsPerPage = $Settings->get_setting( 'records_per_page' , 25 );
137 $PageField = $Settings->get_setting( 'page_field' , 'page' );
138
139 if( $RecordCount > $RecordsPerPage )
140 {
141 $Pages = ceil( $RecordCount / $RecordsPerPage );
142
143 for( $i = 1 ; $i <= $Pages ; $i++ )
144 {
145 $Code .= $this->CachedMultyFS->get_template( __FILE__ , 'paginator_item.tpl' );
146 $Code .= $i != $Pages ? '&nbsp;' : '';
147 $Code = str_replace( array( '{i}' , '{field}' ) , array( $i , $PageField ) , $Code );
148 }
149 }
150
151 return( $Code );
152 }
153 catch( Exception $e )
154 {
155 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
156 }
157 }
158 }
159
160 ?>