Source for file ResultPrinter.abstract.php

Documentation is available at ResultPrinter.abstract.php

  1. <?php
  2. /**
  3. * @since 12/7/05
  4. * @package polyphony.resultprinter
  5. *
  6. * @copyright Copyright &copy; 2005, Middlebury College
  7. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  8. *
  9. * @version $Id: ResultPrinter.abstract.php,v 1.7 2007/09/19 14:04:49 adamfranco Exp $
  10. */
  11.  
  12. /**
  13. * This abstract class provides common methods for child classes
  14. *
  15. * @since 12/7/05
  16. * @package polyphony.resultprinter
  17. *
  18. * @copyright Copyright &copy; 2005, Middlebury College
  19. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  20. *
  21. * @version $Id: ResultPrinter.abstract.php,v 1.7 2007/09/19 14:04:49 adamfranco Exp $
  22. */
  23. class ResultPrinter {
  24.  
  25. /**
  26. * Answer the number of the first asset on our current page
  27. *
  28. * @return integer 1 through the total number of items
  29. * @access public
  30. * @since 5/11/06
  31. */
  32. function getStartingNumber () {
  33. if (isset($this->_namespace) && is_string($this->_namespace)) {
  34. $harmoni = Harmoni::instance();
  35. $harmoni->request->startNamespace($this->_namespace);
  36. }
  37. if (RequestContext::value('starting_number'))
  38. $num = RequestContext::value('starting_number');
  39. else if (isset($this->_startingNumber))
  40. $num = $this->_startingNumber;
  41. else
  42. $num = 1;
  43. if (isset($this->_namespace) && is_string($this->_namespace))
  44. $harmoni->request->endNamespace();
  45. return $num;
  46. }
  47. /**
  48. * Set the starting number to use if none is passed
  49. *
  50. * @param integer $startingNumber
  51. * @return void
  52. * @access public
  53. * @since 5/15/06
  54. */
  55. function setStartingNumber ($startingNumber) {
  56. $this->_startingNumber = $startingNumber;
  57. }
  58. /**
  59. * Answer the parameter name used to pass the starting number
  60. * (for inclusion in other urls).
  61. *
  62. * @return string
  63. * @access public
  64. * @since 5/11/06
  65. */
  66. function startingNumberParam () {
  67. return RequestContext::name('starting_number');
  68. }
  69. /**
  70. * Set the namespace to use for page links, this is to limit conflict with
  71. * other result printers on the page.
  72. *
  73. * @param string $namespace
  74. * @return void
  75. * @access public
  76. * @since 9/18/06
  77. */
  78. function setNamespace ($namespace) {
  79. ArgumentValidator::validate($namespace, StringValidatorRule::getRule());
  80. $this->_namespace = $namespace;
  81. }
  82. /**
  83. * Return a string containing HTML links to other pages of the iterator.
  84. * if all items fit on one page, an empty string will be returned.
  85. *
  86. * @param integer $startingNumber The item number to start with.
  87. * @param integer $numItems The total number of Items.
  88. * @return string
  89. * @access public
  90. * @since 12/7/05
  91. */
  92. function getPageLinks ($startingNumber, $numItems) {
  93. if ($numItems > $this->_pageSize) {
  94. $harmoni = Harmoni::instance();
  95. if (isset($this->_namespace) && is_string($this->_namespace))
  96. $harmoni->request->startNamespace($this->_namespace);
  97. ob_start();
  98. print "\n<table width='100%'>";
  99. print "\n\t<tr>";
  100. print "\n\t\t<td>";
  101. $numPages = ceil($numItems/$this->_pageSize);
  102. if ($this->_pageSize > 1)
  103. $currentPage = floor($startingNumber/$this->_pageSize)+1; // add one for 1-based counting
  104. else
  105. $currentPage = $startingNumber;
  106. $pagesAround = 2;
  107. $firstPage = $currentPage - $pagesAround;
  108. if ($firstPage <= 1)
  109. $firstPage = 1;
  110. else if ($firstPage > ($numPages - (2 * $pagesAround))) {
  111. $firstPage = $numPages - (2 * $pagesAround);
  112. if ($firstPage <= 1)
  113. $firstPage = 1;
  114. }
  115. $url =$harmoni->request->mkURLWithPassthrough();
  116. $lastPage = $firstPage + (2 * $pagesAround);
  117. if ($lastPage > $numPages)
  118. $lastPage = $numPages;
  119. if ($currentPage == 1) {
  120. // print "&lt;&lt; \n";
  121. } else {
  122. $url->setValue("starting_number", 1);
  123. // print "<a href='";
  124. // print $url->write();
  125. // print "'>&lt;&lt;</a> \n";
  126. if ($firstPage > 1) {
  127. print "<a href='";
  128. print $url->write();
  129. print "'>1</a> ";
  130. if ($firstPage > 2)
  131. print " ... \n";
  132. }
  133. }
  134. for ($i = $firstPage; $i <= $lastPage; $i++) {
  135. print " ";
  136. if ($i != $currentPage) {
  137. $url->setValue("starting_number", (($i-1)*$this->_pageSize+1));
  138. print "<a href='";
  139. print $url->write();
  140. print "'>";
  141. }
  142. print $i;
  143. if ($i != $currentPage)
  144. print "</a>\n";
  145. }
  146. if ($currentPage == $numPages) {
  147. // print " &gt;&gt;\n";
  148. } else {
  149. $url->setValue("starting_number", (($numPages-1)*$this->_pageSize+1));
  150. if ($lastPage < $numPages) {
  151. if ($lastPage < $numPages - 1)
  152. print " ... ";
  153. print "<a href='";
  154. print $url->write();
  155. print "'>".$numPages."</a> \n";
  156. }
  157. // print " <a href='";
  158. // print $url->write();
  159. // print "'>&gt;&gt;</a>\n";
  160. }
  161. print "\n\t\t</td>";
  162. if ($numPages > 2*$pagesAround + 3) {
  163. print "\n\t\t<td style='text-align: center'>";
  164. } else {
  165. print "\n\t\t<td style='text-align: right'>";
  166. }
  167. print "(";
  168. print $startingNumber;
  169. print "-";
  170. print ($startingNumber + $this->_pageSize - 1);
  171. print " "._("of")." ".$numItems." "._("items").")";
  172. if ($numPages > 2*$pagesAround + 3) {
  173. print "\n\t\t</td>\n\t\t<td style='text-align: right'>\n\t\t\t"._("Go to page:")." \n\t\t\t<select onchange='Javascript:jumpToPage(this);'>\n";
  174. for ($i = 1; $i <= $numPages; $i++) {
  175. $value = ($i-1)*$this->_pageSize + 1;
  176. print "\t<option value='".$value."'";
  177. if ($i == $currentPage)
  178. print " selected='selected'";
  179. print ">".$i."</option>\n";
  180. }
  181. print "</select>\n";
  182. $url->setValue("starting_number", "__________");
  183. $urlString = str_replace("__________", "' + inputField.value + '",
  184. str_replace('&amp;', '&', $url->write()));
  185. print "\n<script type='text/javascript'>\n//<![CDATA[";
  186. print "\n function jumpToPage(inputField) {";
  187. print "\n window.location = '".$urlString."'";
  188. print "\n }";
  189. print "\n//]]>\n</script>\n";
  190. }
  191. print "\n\t\t</td>";
  192. print "\n\t</tr>";
  193. print "\n</table>";
  194. $html = ob_get_contents();
  195. ob_end_clean();
  196. if (isset($this->_namespace) && is_string($this->_namespace))
  197. $harmoni->request->endNamespace();
  198. return $html;
  199. } else {
  200. return "";
  201. }
  202. }
  203. }
  204.  
  205. ?>

Documentation generated on Wed, 19 Sep 2007 10:26:05 -0400 by phpDocumentor 1.3.0RC3