Ignore:
Timestamp:
Jun 3, 2006 7:47:48 PM (18 years ago)
Author:
scdev
Message:

Q - Merged branches/2.0singleton into trunk. Completed updating classes to use singleton methods. Implemented tests. Fixed some bugs. Changed some interfaces.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/PageNumbers.inc.php

    r111 r136  
    44 * Code by Strangecode :: www.strangecode.com :: This document contains copyrighted information
    55 *
    6  * The PageNumbers:: class provides a common abstracted interface to the
     6 * The PageNumbers class provides a common abstracted interface to the
    77 * multiple pages features. It sets the various numbers needed to display items
    88 * on a page, and includes functions for working with these numbers.
     
    7272    function setPerPage($per_page, $default=25, $save_value=true)
    7373    {
    74         // (1) By provided argument, if valid.
     74        $prefs =& Prefs::getInstance();
     75   
     76        // (1) By provided argument, if valid.
    7577        // (2) By saved preference, if available.
    7678        // (3) Set to default value if provided and valid.
     
    7981            $this->_per_page = $per_page;
    8082            if ($save_value) {
    81                 Prefs::setValue('items_per_page', $this->_per_page, $_SERVER['PHP_SELF']);
    82             }
    83         } else if ($save_value && Prefs::exists('items_per_page', $_SERVER['PHP_SELF'])) {
    84             $this->_per_page = (int)Prefs::getValue('items_per_page', $_SERVER['PHP_SELF']);
     83                $prefs->set('items_per_page', $this->_per_page, $_SERVER['PHP_SELF']);
     84            }
     85        } else if ($save_value && $prefs->exists('items_per_page', $_SERVER['PHP_SELF'])) {
     86            $this->_per_page = (int)$prefs->get('items_per_page', $_SERVER['PHP_SELF']);
    8587        } else if (is_numeric($default) && $default > 0) {
    8688            $this->_per_page = $default;
     
    9496    function setPageNumber($page_number, $save_value=true)
    9597    {
    96         // (1) By provided argument, if valid.
     98        $prefs =& Prefs::getInstance();
     99   
     100    // (1) By provided argument, if valid.
    97101        // (2) By saved preference, if available.
    98102        // (3) Don't change from what was provided at class instantiation.
     
    105109            }
    106110            if ($save_value) {
    107                 Prefs::setValue('page_number', $this->current_page, $_SERVER['PHP_SELF']);
    108             }
    109         } else if ($save_value && Prefs::exists('page_number', $_SERVER['PHP_SELF'])) {
    110             $this->current_page = (int)Prefs::getValue('page_number', $_SERVER['PHP_SELF']);
     111                $prefs->set('page_number', $this->current_page, $_SERVER['PHP_SELF']);
     112            }
     113        } else if ($save_value && $prefs->exists('page_number', $_SERVER['PHP_SELF'])) {
     114            $this->current_page = (int)$prefs->get('page_number', $_SERVER['PHP_SELF']);
    111115        }
    112116        $this->set_page_number_initialized = true;
     
    137141    function calculate()
    138142    {
     143        $app =& App::getInstance();
     144
    139145        if (!$this->set_per_page_initialized) {
    140             App::logMsg(sprintf('set_per_page not initialized'), LOG_ERR, __FILE__, __LINE__);
     146            $app->logMsg(sprintf('set_per_page not initialized'), LOG_ERR, __FILE__, __LINE__);
    141147        }
    142148        if (!$this->set_page_number_initialized) {
    143             App::logMsg(sprintf('set_page_number not initialized'), LOG_ERR, __FILE__, __LINE__);
     149            $app->logMsg(sprintf('set_page_number not initialized'), LOG_ERR, __FILE__, __LINE__);
    144150        }
    145151        if (!$this->set_total_items_initialized) {
    146             App::logMsg(sprintf('set_total_items not initialized'), LOG_ERR, __FILE__, __LINE__);
     152            $app->logMsg(sprintf('set_total_items not initialized'), LOG_ERR, __FILE__, __LINE__);
    147153        }
    148154
     
    189195    function getLimitSQL()
    190196    {
     197        $app =& App::getInstance();
     198        $db =& DB::getInstance();
     199
    191200        if (is_numeric($this->first_item) && is_numeric($this->_per_page)) {
    192             return ' LIMIT ' . DB::escapeString($this->first_item) . ', ' . DB::escapeString($this->_per_page) . ' ';
    193         } else {
    194             App::logMsg(sprintf('Could not find SQL to LIMIT by %s %s.', $this->first_item, $this->_per_page), LOG_WARNING, __FILE__, __LINE__);
     201            return ' LIMIT ' . $db->escapeString($this->first_item) . ', ' . $db->escapeString($this->_per_page) . ' ';
     202        } else {
     203            $app->logMsg(sprintf('Could not find SQL to LIMIT by %s %s.', $this->first_item, $this->_per_page), LOG_WARNING, __FILE__, __LINE__);
    195204            return '';
    196205        }
     
    204213    function printPerPageLinks($query_key='per_page')
    205214    {
     215        $app =& App::getInstance();
     216
    206217        $sp = '';
    207218        for ($i=0; $i<sizeof($this->per_page_options); $i++) {
     
    209220                printf('%s<a href="%s">%s</a>',
    210221                    $sp,
    211                     App::oHREF($_SERVER['PHP_SELF'] . '?' . $query_key . '=' . $this->per_page_options[$i]),
     222                    $app->oHREF($_SERVER['PHP_SELF'] . '?' . $query_key . '=' . $this->per_page_options[$i]),
    212223                    $this->per_page_options[$i]
    213224                );
     
    220231
    221232    /**
    222      * Outputs an App::oHREF compatible url that goes to the page $page_number.
     233     * Outputs an $app->oHREF compatible url that goes to the page $page_number.
    223234     * Depends on $this->base_url to build the url onto. This is used in the
    224235     * page_number.ihtml template.
     
    232243    function getPageNumURL($page_number, $carry_args=null)
    233244    {
    234         return App::oHREF($this->url_base . $page_number, $carry_args);
     245        $app =& App::getInstance();
     246
     247        return $app->oHREF($this->url_base . $page_number, $carry_args);
    235248    }
    236249    function printPageNumURL($page_number, $carry_args=null)
Note: See TracChangeset for help on using the changeset viewer.