Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/*
3
 *  $Id$
4
 *
5
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
6
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
7
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
8
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
9
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
10
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
11
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
12
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
13
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
14
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
15
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
16
 *
17
 * This software consists of voluntary contributions made by many individuals
18
 * and is licensed under the LGPL. For more information, see
19
 * <http://www.doctrine-project.org>.
20
 */
21
 
22
/**
23
 * Doctrine_Pager_Range
24
 *
25
 * @author      Guilherme Blanco <guilhermeblanco@hotmail.com>
26
 * @package     Doctrine
27
 * @subpackage  Pager
28
 * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL
29
 * @version     $Revision$
30
 * @link        www.doctrine-project.org
31
 * @since       0.9
32
 */
33
abstract class Doctrine_Pager_Range
34
{
35
    /**
36
     * @var array $_options     Custom Doctrine_Pager_Range implementation options
37
     */
38
    protected $_options;
39
 
40
    /**
41
     * @var Doctrine_Pager $pager     Doctrine_Pager object related to the pager range
42
     */
43
    private $pager;
44
 
45
 
46
    /**
47
     * __construct
48
     *
49
     * @param array $options     Custom subclass implementation options.
50
     *                           Default is a blank array
51
     * @param Doctrine_Pager $pager     Optional Doctrine_Pager object to be associated
52
     * @return void
53
     */
54
    final public function __construct($options = array(), $pager = null)
55
    {
56
        $this->_setOptions($options);
57
 
58
        if ($pager !== null) {
59
            $this->setPager($pager);
60
        }
61
    }
62
 
63
    /**
64
     * getPager
65
     *
66
     * Returns the Doctrine_Pager object related to the pager range
67
     *
68
     * @return Doctrine_Pager        Doctrine_Pager object related to the pager range
69
     */
70
    public function getPager()
71
    {
72
        return $this->pager;
73
    }
74
 
75
    /**
76
     * setPager
77
     *
78
     * Defines the Doctrine_Pager object related to the pager range and
79
     * automatically (re-)initialize Doctrine_Pager_Range
80
     *
81
     * @param $pager       Doctrine_Pager object related to the pager range
82
     * @return void
83
     */
84
    public function setPager($pager)
85
    {
86
        $this->pager = $pager;
87
 
88
        // Lazy-load initialization. It only should be called when all
89
        // needed information data is ready (this can only happens when we have
90
        // options stored and a Doctrine_Pager assocated)
91
        $this->_initialize();
92
    }
93
 
94
    /**
95
     * getOptions
96
     *
97
     * Returns the custom Doctrine_Pager_Range implementation options
98
     *
99
     * @return array        Custom Doctrine_Pager_Range implementation options
100
     */
101
    public function getOptions()
102
    {
103
        return $this->_options;
104
    }
105
 
106
    /**
107
     * getOption
108
     *
109
     * Returns the custom Doctrine_Pager_Range implementation offset option
110
     *
111
     * @return array        Custom Doctrine_Pager_Range implementation options
112
     */
113
    public function getOption($option)
114
    {
115
        if (isset($this->_options[$option])) {
116
            return $this->_options[$option];
117
        }
118
 
119
        throw new Doctrine_Pager_Exception(
120
            'Cannot access unexistent option \'' . $option . '\' in Doctrine_Pager_Range class'
121
        );
122
    }
123
 
124
    /**
125
     * _setOptions
126
     *
127
     * Defines the subclass implementation options
128
     *
129
     * @param $options       Custom Doctrine_Pager_Range implementation options
130
     * @return void
131
     */
132
    protected function _setOptions($options)
133
    {
134
        $this->_options = $options;
135
    }
136
 
137
    /**
138
     * isInRange
139
     *
140
     * Check if a given page is in the range
141
     *
142
     * @param $page       Page to be checked
143
     * @return boolean
144
     */
145
    public function isInRange($page)
146
    {
147
        return (array_search($page, $this->rangeAroundPage()) !== false);
148
    }
149
 
150
 
151
 
152
    /**
153
     * _initialize
154
     *
155
     * Initialize Doctrine_Page_Range subclass which does custom class definitions
156
     *
157
     * @return void
158
     */
159
    abstract protected function _initialize();
160
 
161
 
162
    /**
163
     * rangeAroundPage
164
     *
165
     * Calculate and returns an array representing the range around the current page
166
     *
167
     * @return array
168
     */
169
    abstract public function rangeAroundPage();
170
}