Changeset 571 for branches/1.1dev/lib


Ignore:
Timestamp:
Nov 5, 2016 10:53:54 PM (8 years ago)
Author:
anonymous
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/1.1dev/lib/PageNumbers.inc.php

    r82 r571  
    1919 * @version   1.6
    2020 */
    21  
     21
    2222require_once dirname(__FILE__) . '/App.inc.php';
    2323require_once dirname(__FILE__) . '/Utilities.inc.php';
     
    2525
    2626class PageNumbers {
    27    
     27
    2828    var $total_items;       // Total quantity of items.
    2929    var $total_pages;       // The total number of pages.
     
    3939    var $set_page_number_initialized = false;
    4040    var $set_total_items_initialized = false;
    41    
     41
    4242    // These are initialized in the constructor.
    4343    var $per_page_options;
     
    5050    var $right_dbl_arrow;
    5151    var $right_dbl_arrow_disabled;
    52        
     52
    5353    /**
    5454     * PageNumbers constructor. All arguments are depreciated. Use set* functions instead.
     
    5858        // Default options for the quantity per page links.
    5959        $this->per_page_options = array(25, 50, 100, 200);
    60        
     60
    6161        // Default options for the page number links.
    6262        $this->left_arrow = _("back");
     
    6868        $this->right_dbl_arrow = '<strong>&raquo;</strong>';
    6969        $this->right_dbl_arrow_disabled = '<span style="color: #aaaaaa;"><strong>&raquo;</strong></span>';
    70        
    71         // Default url base. This will be set manually after instantiation 
     70
     71        // Default url base. This will be set manually after instantiation
    7272        // in special cases like using a /my/page/# scheme.
    7373        $this->url_base = $_SERVER['PHP_SELF'] . '?page_number=';
    7474    }
    75    
     75
    7676    /**
    7777     * Set the number of items per page.
     
    9595        $this->set_per_page_initialized = true;
    9696    }
    97    
     97
    9898    /**
    9999     * Set the current page number.
     
    119119        $this->set_page_number_initialized = true;
    120120    }
    121    
     121
    122122    /**
    123123     * Set the total number of items.
     
    126126    {
    127127        if (is_numeric($total_items) && $total_items > 0) {
    128             $this->total_items = $total_items;       
    129         } else {
    130             $this->total_items = 0;       
     128            $this->total_items = $total_items;
     129        } else {
     130            $this->total_items = 0;
    131131        }
    132132        $this->set_total_items_initialized = true;
    133133    }
    134    
     134
    135135    /**
    136136     * After $total_items or other options are set, this function calculates
    137      * all the other numbers needed. If you set any variables manually, 
     137     * all the other numbers needed. If you set any variables manually,
    138138     * for example if $page_number comes from
    139139     * some place other than the GET or POST array, you should call this
     
    153153            logMsg(sprintf('set_total_items not initialized'), LOG_DEBUG, __FILE__, __LINE__);
    154154        }
    155    
    156         // If the specified page exceedes total pages or is less than 1, set the page to 1.
     155
     156        // If the specified page exceeds total pages or is less than 1, set the page to 1.
    157157        if ($this->_per_page * $this->current_page >= $this->total_items + $this->_per_page || $this->_per_page * $this->current_page < 1) {
    158158            $this->current_page = 1;
    159159        }
    160        
     160
    161161        // The first item to be shown on this page.
    162162        $this->first_item = ($this->current_page - 1) * $this->_per_page;
    163        
     163
    164164        // The last item to be shown on this page.
    165165        if ($this->total_items < $this->current_page * $this->_per_page) {
     
    168168            $this->last_item = $this->current_page * $this->_per_page - 1;
    169169        }
    170        
     170
    171171        // Zeroing. Just in case. Paranoia. Yeah, negative numbers perturb me.
    172172        if ($this->first_item < 1) {
     
    179179            $this->total_items = 0;
    180180        }
    181                
     181
    182182        // The total number of pages.
    183183        $this->total_pages = ceil($this->total_items / $this->_per_page);
    184        
     184
    185185        // Figure out how many page number links to print.
    186186        if ($this->total_pages >= $this->max_num_links) {
     
    190190        }
    191191    }
    192    
     192
    193193    /**
    194194     * Returns the SQL code to limit query to items that are on current page.
     
    202202            return '';
    203203        }
    204     } 
     204    }
    205205
    206206    /**
     
    214214        for ($i=0; $i<sizeof($this->per_page_options); $i++) {
    215215            if ($this->_per_page != $this->per_page_options[$i]) {
    216                 echo $sp . '<a href="' 
    217                 . ohref($_SERVER['PHP_SELF'] . '?' . $query_key . '=' . $this->per_page_options[$i]) 
     216                echo $sp . '<a href="'
     217                . ohref($_SERVER['PHP_SELF'] . '?' . $query_key . '=' . $this->per_page_options[$i])
    218218                . '">' . $this->per_page_options[$i] . '</a>';
    219219            } else {
     
    226226    /**
    227227     * Outputs an oHREF compatible url that goes to the page $page_number.
    228      * Depends on $this->base_url to build the url onto. This is used in the 
     228     * Depends on $this->base_url to build the url onto. This is used in the
    229229     * page_number.ihtml template.
    230230     *
     
    252252    {
    253253        $page_numbers = array();
    254        
     254
    255255//         if ($this->current_page > $this->total_pages - floor($this->_num_links / 2)) {
    256256//             $high_num = $this->total_pages;
     
    263263//             $high_num = $low_num + $this->_num_links - 1;
    264264//         }
    265 //         
     265//
    266266//         for ($i = $low_num; $i < $this->current_page; $i++) {
    267267//             $page_numbers[] = array(
     
    271271//             );
    272272//         }
    273 //         
     273//
    274274//         if ($this->_num_links > 0) {
    275275//             // Print the current page number.
     
    280280//                 );
    281281//         }
    282 //         
     282//
    283283//         // Print links to specific page numbers after the current page.
    284284//         for ($i = $this->current_page + 1; $i <= $high_num; $i++) {
     
    289289//             );
    290290//         }
    291        
     291
    292292        for ($i = 1; $i <= $this->total_pages; $i++) {
    293293            $page_numbers[] = array(
     
    297297            );
    298298        }
    299        
     299
    300300        return $page_numbers;
    301301    }
     
    309309    {
    310310        $page_numbers_string = '';
    311        
     311
    312312        if ($this->current_page > $this->total_pages - floor($this->_num_links / 2)) {
    313313            $high_num = $this->total_pages;
     
    320320            $high_num = $low_num + $this->_num_links - 1;
    321321        }
    322        
     322
    323323        if ($this->current_page != 1) {
    324324            // Print "first" and "previous" page links.
     
    341341            }
    342342        }
    343        
     343
    344344        if ($this->_num_links > 0) {
    345345            // Print the current page number.
    346346            $page_numbers_string .= sprintf('<strong>%s</strong>&nbsp;', $this->current_page);
    347347        }
    348        
     348
    349349        if ($this->current_page < $this->total_pages) {
    350350            // Print links to specific page numbers after the current page.
     
    367367            }
    368368        }
    369        
     369
    370370        return $page_numbers_string;
    371371    }
    372    
     372
    373373    function printPageNumbers($carry_args=null)
    374374    {
    375375        echo $this->getPageNumbers($carry_args);
    376376    }
    377    
     377
    378378}
    379379
Note: See TracChangeset for help on using the changeset viewer.