splitPageResults Class Reference

List of all members.

Public Member Functions

Public Attributes


Detailed Description

Definition at line 13 of file split_page_results.php.


Member Function Documentation

splitPageResults::display_count ( text_output  ) 

Definition at line 117 of file split_page_results.php.

00117                                          {
00118       $to_num = ($this->number_of_rows_per_page * $this->current_page_number);
00119       if ($to_num > $this->number_of_rows) $to_num = $this->number_of_rows;
00120 
00121       $from_num = ($this->number_of_rows_per_page * ($this->current_page_number - 1));
00122 
00123       if ($to_num == 0) {
00124         $from_num = 0;
00125       } else {
00126         $from_num++;
00127       }
00128 
00129       return sprintf($text_output, $from_num, $to_num, $this->number_of_rows);
00130     }

splitPageResults::display_links ( max_page_links,
parameters = '' 
)

Definition at line 79 of file split_page_results.php.

00079                                                               {
00080       global  $request_type;
00081       $display_links_string = '';
00082 
00083       if (tep_not_null($parameters) && (substr($parameters, -1) != '&')) $parameters .= '&';
00084 
00085 // previous button - not displayed on first page
00086       if ($this->current_page_number > 1) $display_links_string .= '<a href="' . tep_href_link(basename($_SERVER['SCRIPT_FILENAME']), $parameters . $this->page_name . '=' . ($this->current_page_number - 1), $request_type) . '" title=" ' . PREVNEXT_TITLE_PREVIOUS_PAGE . ' ">' . PREVNEXT_BUTTON_PREV . '</a>';
00087 
00088 // check if number_of_pages > $max_page_links
00089       $cur_window_num = intval($this->current_page_number / $max_page_links);
00090       if ($this->current_page_number % $max_page_links) $cur_window_num++;
00091 
00092       $max_window_num = intval($this->number_of_pages / $max_page_links);
00093       if ($this->number_of_pages % $max_page_links) $max_window_num++;
00094 
00095 // previous window of pages
00096       if ($cur_window_num > 1) $display_links_string .= '<a href="' . tep_href_link(basename($_SERVER['SCRIPT_FILENAME']), $parameters . $this->page_name . '=' . (($cur_window_num - 1) * $max_page_links), $request_type) . '" title=" ' . sprintf(PREVNEXT_TITLE_PREV_SET_OF_NO_PAGE, $max_page_links) . ' ">...</a>';
00097 
00098 // page nn button
00099       for ($jump_to_page = 1 + (($cur_window_num - 1) * $max_page_links); ($jump_to_page <= ($cur_window_num * $max_page_links)) && ($jump_to_page <= $this->number_of_pages); $jump_to_page++) {
00100         if ($jump_to_page == $this->current_page_number) {
00101           $display_links_string .= '<span class="jump">' . $jump_to_page . '</span>';
00102         } else {
00103           $display_links_string .= '<a href="' . tep_href_link(basename($_SERVER['SCRIPT_FILENAME']), $parameters . $this->page_name . '=' . $jump_to_page, $request_type) . '" title=" ' . sprintf(PREVNEXT_TITLE_PAGE_NO, $jump_to_page) . ' ">' . $jump_to_page . '</a>';
00104         }
00105       }
00106 
00107 // next window of pages
00108       if ($cur_window_num < $max_window_num) $display_links_string .= '<a href="' . tep_href_link(basename($_SERVER['SCRIPT_FILENAME']), $parameters . $this->page_name . '=' . (($cur_window_num) * $max_page_links + 1), $request_type) . '" title=" ' . sprintf(PREVNEXT_TITLE_NEXT_SET_OF_NO_PAGE, $max_page_links) . ' ">...</a>';
00109 
00110 // next button
00111       if (($this->current_page_number < $this->number_of_pages) && ($this->number_of_pages != 1)) $display_links_string .= '<a href="' . tep_href_link(basename($_SERVER['SCRIPT_FILENAME']), $parameters . 'page=' . ($this->current_page_number + 1), $request_type) . '" title=" ' . PREVNEXT_TITLE_NEXT_PAGE . ' ">' . PREVNEXT_BUTTON_NEXT . '</a>';
00112 
00113       return $display_links_string;
00114     }

splitPageResults::splitPageResults ( query,
max_rows,
count_key = '*',
page_holder = 'page' 
)

Definition at line 22 of file split_page_results.php.

00022                                                                                           {
00023       global $_GET, $_POST;
00024 
00025       $this->sql_query = $query;
00026       $this->SQL_QUERY = strtoupper($query);
00027       $this->page_name = $page_holder;
00028 
00029       if (isset($_GET[$page_holder])) {
00030         $page = $_GET[$page_holder];
00031       } elseif (isset($_POST[$page_holder])) {
00032         $page = $_POST[$page_holder];
00033       } else {
00034         $page = '';
00035       }
00036 
00037       if (empty($page) || !is_numeric($page)) $page = 1;
00038       $this->current_page_number = $page;
00039 
00040       $this->number_of_rows_per_page = $max_rows;
00041 
00042       $pos_to = strlen($this->sql_query);
00043       $pos_from = strpos($this->SQL_QUERY, ' FROM', 0);
00044 
00045       $pos_group_by = strpos($this->SQL_QUERY, ' GROUP BY', $pos_from);
00046       if (($pos_group_by < $pos_to) && ($pos_group_by != false)) $pos_to = $pos_group_by;
00047 
00048       $pos_having = strpos($this->SQL_QUERY, ' HAVING', $pos_from);
00049       if (($pos_having < $pos_to) && ($pos_having != false)) $pos_to = $pos_having;
00050 
00051       $pos_order_by = strpos($this->SQL_QUERY, ' ORDER BY', $pos_from);
00052       if (($pos_order_by < $pos_to) && ($pos_order_by != false)) $pos_to = $pos_order_by;
00053 
00054       $count_string = ' '.tep_db_input($count_key).'';
00055 
00056 
00057       if (strpos($this->SQL_QUERY, 'DISTINCT') || strpos($this->SQL_QUERY, 'GROUP BY')) $sql="SELECT DISTINCT COUNT(" . $count_string . ") AS total " . substr($this->sql_query, $pos_from, ($pos_to - $pos_from));
00058       else $sql="SELECT COUNT(" . $count_string . ") AS total " . substr($this->sql_query, $pos_from, ($pos_to - $pos_from));
00059 
00060       $count_query = tep_db_query($sql);
00061 
00062       $this->number_of_rows = tep_db_num_rows($count_query);
00063 
00064       $this->number_of_pages = ceil($this->number_of_rows / $this->number_of_rows_per_page);
00065 
00066       if ($this->current_page_number > $this->number_of_pages && $this->number_of_pages > 0 ) {
00067         $this->current_page_number = $this->number_of_pages;
00068       }
00069 
00070       $offset = ($this->number_of_rows_per_page * ($this->current_page_number - 1));
00071 
00072       $this->sql_query .= " LIMIT " . $offset . ", " . $this->number_of_rows_per_page;
00073 
00074     }


Member Data Documentation

splitPageResults::$current_page_number

Definition at line 16 of file split_page_results.php.

splitPageResults::$number_of_pages

Definition at line 17 of file split_page_results.php.

splitPageResults::$number_of_rows

Definition at line 15 of file split_page_results.php.

splitPageResults::$number_of_rows_per_page

Definition at line 18 of file split_page_results.php.

splitPageResults::$page_name

Definition at line 19 of file split_page_results.php.

splitPageResults::$sql_query

Definition at line 14 of file split_page_results.php.


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