Source for file SimpleFieldModule.class.php

Documentation is available at SimpleFieldModule.class.php

  1. <?php
  2. /**
  3. * @package polyphony.repository.search
  4. *
  5. * @copyright Copyright &copy; 2005, Middlebury College
  6. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  7. *
  8. * @version $Id: SimpleFieldModule.class.php,v 1.9 2007/09/19 14:04:49 adamfranco Exp $
  9. */
  10.  
  11. /**
  12. * Search Modules generate forms for and collect/format the subitions of said forms
  13. * for various Digital Repository search types.
  14. *
  15. * @package polyphony.repository.search
  16. *
  17. * @copyright Copyright &copy; 2005, Middlebury College
  18. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  19. *
  20. * @version $Id: SimpleFieldModule.class.php,v 1.9 2007/09/19 14:04:49 adamfranco Exp $
  21. */
  22.  
  23. class SimpleFieldModule {
  24. /**
  25. * Constructor
  26. *
  27. * @param string $fieldName
  28. * @return object
  29. * @access public
  30. * @since 10/28/04
  31. */
  32. function SimpleFieldModule ( $fieldName ) {
  33. $this->_fieldname = $fieldName;
  34. $this->_initilaized = false;
  35. }
  36. /**
  37. * Initialize this object
  38. *
  39. * @return void
  40. * @access public
  41. * @since 5/15/06
  42. */
  43. function init () {
  44. if (!$this->_initilaized) {
  45. $harmoni = Harmoni::instance();
  46. $harmoni->request->startNamespace('SimpleFieldModule');
  47. $this->_contextFieldName = RequestContext::name($this->_fieldname);
  48. if (RequestContext::value($this->_fieldname))
  49. $this->_value = RequestContext::value($this->_fieldname);
  50. else
  51. $this->_value = null;
  52. $harmoni->request->endNamespace();
  53. $this->_initilaized = true;
  54. }
  55. }
  56. /**
  57. * Create a form for searching.
  58. *
  59. * @param string $action The destination on form submit.
  60. * @return string
  61. * @access public
  62. * @since 10/19/04
  63. */
  64. function createSearchForm ($repository, $action ) {
  65. ob_start();
  66. print "<form action='$action' method='post'>\n<div>\n";
  67. $this->createSearchFields($repository);
  68. print "\t<input type='submit' />\n";
  69. print "</div>\n</form>";
  70. $form = ob_get_contents();
  71. ob_end_clean();
  72. return $form;
  73. }
  74. /**
  75. * Create the fields (without form tags) for searching
  76. *
  77. * @param object Repository $repository
  78. * @return string
  79. * @access public
  80. * @since 4/26/06
  81. */
  82. function createSearchFields ($repository) {
  83. $this->init();
  84. return "\t<input type='text' name='".$this->_contextFieldName."' value=\"".$this->_value."\" />\n";
  85. }
  86. /**
  87. * Get the formatted search terms based on the submissions of the form
  88. *
  89. * @param object Repository $repository
  90. * @return mixed
  91. * @access public
  92. * @since 10/28/04
  93. */
  94. function getSearchCriteria ( $repository ) {
  95. $this->init();
  96. return $this->_value;
  97. }
  98. /**
  99. * Get an array of the current values to be added to a url. The keys of the
  100. * arrays are the field-names in the appropriate context.
  101. *
  102. * @return array
  103. * @access public
  104. * @since 04/25/06
  105. */
  106. function getCurrentValues () {
  107. $this->init();
  108. if ($this->_value)
  109. return array($this->_contextFieldName => $this->_value);
  110. else
  111. return array();
  112. }
  113. /**
  114. * Update the current values with data (maybe stored in the session for instance.
  115. * The keys of the arrays are the field-names in the appropriate context.
  116. * This could have been originally fetched via getCurrentValues
  117. *
  118. * @param array $values
  119. * @return void
  120. * @access public
  121. * @since 04/25/06
  122. */
  123. function setCurrentValues ($values) {
  124. $this->init();
  125. if (isset($values[$this->_contextFieldName])) {
  126. $this->_value = $values[$this->_contextFieldName];
  127. }
  128. }
  129. }
  130.  
  131. ?>

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