PageRenderTime 50ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Pager/Range.php

https://github.com/MichelCarroll/LifeManager
PHP | 170 lines | 45 code | 18 blank | 107 comment | 2 complexity | da7ff7fb464f4922cf312ae33a6e9752 MD5 | raw file
Possible License(s): ISC, AGPL-3.0, LGPL-2.1, BSD-3-Clause, LGPL-3.0
  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. * Doctrine_Pager_Range
  23. *
  24. * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
  25. * @package Doctrine
  26. * @subpackage Pager
  27. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  28. * @version $Revision$
  29. * @link www.doctrine-project.org
  30. * @since 0.9
  31. */
  32. abstract class Doctrine_Pager_Range
  33. {
  34. /**
  35. * @var array $_options Custom Doctrine_Pager_Range implementation options
  36. */
  37. protected $_options;
  38. /**
  39. * @var Doctrine_Pager $pager Doctrine_Pager object related to the pager range
  40. */
  41. private $pager;
  42. /**
  43. * __construct
  44. *
  45. * @param array $options Custom subclass implementation options.
  46. * Default is a blank array
  47. * @param Doctrine_Pager $pager Optional Doctrine_Pager object to be associated
  48. * @return void
  49. */
  50. final public function __construct($options = array(), $pager = null)
  51. {
  52. $this->_setOptions($options);
  53. if ($pager !== null) {
  54. $this->setPager($pager);
  55. }
  56. }
  57. /**
  58. * getPager
  59. *
  60. * Returns the Doctrine_Pager object related to the pager range
  61. *
  62. * @return Doctrine_Pager Doctrine_Pager object related to the pager range
  63. */
  64. public function getPager()
  65. {
  66. return $this->pager;
  67. }
  68. /**
  69. * setPager
  70. *
  71. * Defines the Doctrine_Pager object related to the pager range and
  72. * automatically (re-)initialize Doctrine_Pager_Range
  73. *
  74. * @param $pager Doctrine_Pager object related to the pager range
  75. * @return void
  76. */
  77. public function setPager($pager)
  78. {
  79. $this->pager = $pager;
  80. // Lazy-load initialization. It only should be called when all
  81. // needed information data is ready (this can only happens when we have
  82. // options stored and a Doctrine_Pager assocated)
  83. $this->_initialize();
  84. }
  85. /**
  86. * getOptions
  87. *
  88. * Returns the custom Doctrine_Pager_Range implementation options
  89. *
  90. * @return array Custom Doctrine_Pager_Range implementation options
  91. */
  92. public function getOptions()
  93. {
  94. return $this->_options;
  95. }
  96. /**
  97. * getOption
  98. *
  99. * Returns the custom Doctrine_Pager_Range implementation offset option
  100. *
  101. * @return array Custom Doctrine_Pager_Range implementation options
  102. */
  103. public function getOption($option)
  104. {
  105. if (isset($this->_options[$option])) {
  106. return $this->_options[$option];
  107. }
  108. throw new Doctrine_Pager_Exception(
  109. 'Cannot access unexistent option \'' . $option . '\' in Doctrine_Pager_Range class'
  110. );
  111. }
  112. /**
  113. * _setOptions
  114. *
  115. * Defines the subclass implementation options
  116. *
  117. * @param $options Custom Doctrine_Pager_Range implementation options
  118. * @return void
  119. */
  120. protected function _setOptions($options)
  121. {
  122. $this->_options = $options;
  123. }
  124. /**
  125. * isInRange
  126. *
  127. * Check if a given page is in the range
  128. *
  129. * @param $page Page to be checked
  130. * @return boolean
  131. */
  132. public function isInRange($page)
  133. {
  134. return (array_search($page, $this->rangeAroundPage()) !== false);
  135. }
  136. /**
  137. * _initialize
  138. *
  139. * Initialize Doctrine_Page_Range subclass which does custom class definitions
  140. *
  141. * @return void
  142. */
  143. abstract protected function _initialize();
  144. /**
  145. * rangeAroundPage
  146. *
  147. * Calculate and returns an array representing the range around the current page
  148. *
  149. * @return array
  150. */
  151. abstract public function rangeAroundPage();
  152. }