Source for file RepositorySearchModuleManager.class.php

Documentation is available at RepositorySearchModuleManager.class.php

  1. <?php
  2. /**
  3. *
  4. * @package polyphony.repository.search
  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: RepositorySearchModuleManager.class.php,v 1.11 2007/09/19 14:04:48 adamfranco Exp $
  10. */
  11.  
  12. /**
  13. * Require our modules
  14. *
  15. */
  16. require_once(dirname(__FILE__)."/modules/SimpleFieldModule.class.php");
  17. require_once(dirname(__FILE__)."/modules/PartAndValuesModule.class.php");
  18.  
  19. /**
  20. * The RepositorySearchModuleManager is responcible for sending requests for search forms
  21. * to the appropriate RepositorySearchModule based on their types.
  22. *
  23. * @package polyphony.repository.search
  24. * @version $Id: RepositorySearchModuleManager.class.php,v 1.11 2007/09/19 14:04:48 adamfranco Exp $
  25. * @since $Date: 2007/09/19 14:04:48 $
  26. * @copyright 2004 Middlebury College
  27. */
  28.  
  29. class RepositorySearchModuleManager {
  30.  
  31. /**
  32. * Constructor, set up the relations of the Types to Modules
  33. *
  34. * @return object
  35. * @access public
  36. * @since 10/19/04
  37. */
  38. function RepositorySearchModuleManager () {
  39. $this->_modules = array();
  40. $this->_modules["Repository::edu.middlebury.harmoni::Keyword"] = new SimpleFieldModule("Keyword");
  41. $this->_modules["Repository::edu.middlebury.harmoni::DisplayName"] = new SimpleFieldModule("DisplayName");
  42. $this->_modules["Repository::edu.middlebury.harmoni::Authoritative Values"] = new PartAndValuesModule("PartId", "AuthValue");
  43. $this->_modules["Repository::edu.middlebury.harmoni::AssetType"] = new SimpleFieldModule("AssetType");
  44. $this->_modules["Repository::edu.middlebury.harmoni::RootAssets"] = new SimpleFieldModule("RootAssets");
  45. $this->_modules["Repository::edu.middlebury.harmoni::Description"] = new SimpleFieldModule("Description");
  46. $this->_modules["Repository::edu.middlebury.harmoni::Content"] = new SimpleFieldModule("Content");
  47. $this->_modules["Repository::edu.middlebury.harmoni::AllCustomStructures"] = new SimpleFieldModule("AllCustomStructures");
  48. }
  49. /**
  50. * Assign the configuration of this Manager. Valid configuration options are as
  51. * follows:
  52. * database_index integer
  53. * database_name string
  54. *
  55. * @param object Properties $configuration (original type: java.util.Properties)
  56. *
  57. * @throws object OsidException An exception with one of the following
  58. * messages defined in org.osid.OsidException: {@link }
  59. * org.osid.OsidException#OPERATION_FAILED OPERATION_FAILED},
  60. * {@link org.osid.OsidException#PERMISSION_DENIED}
  61. * PERMISSION_DENIED}, {@link }
  62. * org.osid.OsidException#CONFIGURATION_ERROR
  63. * CONFIGURATION_ERROR}, {@link }
  64. * org.osid.OsidException#UNIMPLEMENTED UNIMPLEMENTED}, {@link }
  65. * org.osid.OsidException#NULL_ARGUMENT NULL_ARGUMENT}
  66. *
  67. * @access public
  68. */
  69. function assignConfiguration ( $configuration ) {
  70. $this->_configuration =$configuration;
  71. }
  72.  
  73. /**
  74. * Return context of this OsidManager.
  75. *
  76. * @return object OsidContext
  77. *
  78. * @throws object OsidException
  79. *
  80. * @access public
  81. */
  82. function getOsidContext () {
  83. return $this->_osidContext;
  84. }
  85.  
  86. /**
  87. * Assign the context of this OsidManager.
  88. *
  89. * @param object OsidContext $context
  90. *
  91. * @throws object OsidException An exception with one of the following
  92. * messages defined in org.osid.OsidException: {@link }
  93. * org.osid.OsidException#NULL_ARGUMENT NULL_ARGUMENT}
  94. *
  95. * @access public
  96. */
  97. function assignOsidContext ( $context ) {
  98. $this->_osidContext =$context;
  99. }
  100.  
  101. /**
  102. * Create a form for searching.
  103. *
  104. * @param object Repository $repository
  105. * @param object $searchType
  106. * @param string $action The destination on form submit.
  107. * @return string
  108. * @access public
  109. * @since 10/19/04
  110. */
  111. function createSearchForm ( $repository, $searchType, $action) {
  112. ArgumentValidator::validate($repository, new ExtendsValidatorRule("Repository"));
  113. ArgumentValidator::validate($searchType, new ExtendsValidatorRule("Type"));
  114. ArgumentValidator::validate($action, new StringValidatorRule);
  115. $typeKey = $searchType->getDomain()
  116. ."::".$searchType->getAuthority()
  117. ."::".$searchType->getKeyword();
  118. if (!is_object($this->_modules[$typeKey]))
  119. throwError(new Error("Unsupported Search Type, '$typeKey'", "RepositorySearchModuleManager", true));
  120. return $this->_modules[$typeKey]->createSearchForm($repository, $action);
  121. }
  122. /**
  123. * Create a form for searching.
  124. *
  125. * @param object Repository $repository
  126. * @param object $searchType
  127. * @param string $action The destination on form submit.
  128. * @return string
  129. * @access public
  130. * @since 10/19/04
  131. */
  132. function createSearchFields ( $repository, $searchType) {
  133. ArgumentValidator::validate($repository, new ExtendsValidatorRule("Repository"));
  134. ArgumentValidator::validate($searchType, new ExtendsValidatorRule("Type"));
  135. $typeKey = $searchType->getDomain()
  136. ."::".$searchType->getAuthority()
  137. ."::".$searchType->getKeyword();
  138. if (!is_object($this->_modules[$typeKey]))
  139. throwError(new Error("Unsupported Search Type, '$typeKey'", "RepositorySearchModuleManager", true));
  140. return $this->_modules[$typeKey]->createSearchFields($repository);
  141. }
  142. /**
  143. * Get the formatted search terms based on the submissions of the form
  144. *
  145. * @param object $searchType
  146. * @return mixed
  147. * @access public
  148. * @since 10/28/04
  149. */
  150. function getSearchCriteria ( $repository, $searchType ) {
  151. ArgumentValidator::validate($searchType, new ExtendsValidatorRule("Type"));
  152. $typeKey = $searchType->getDomain()
  153. ."::".$searchType->getAuthority()
  154. ."::".$searchType->getKeyword();
  155. if (!is_object($this->_modules[$typeKey]))
  156. throwError(new Error("Unsupported Search Type, '$typeKey'", "RepositorySearchModuleManager", true));
  157. return $this->_modules[$typeKey]->getSearchCriteria($repository);
  158. }
  159. /**
  160. * Get an array of the current values to be added to a url. The keys of the
  161. * arrays are the field-names in the appropriate context.
  162. *
  163. * @param object $searchType
  164. * @return array
  165. * @access public
  166. * @since 10/28/04
  167. */
  168. function getCurrentValues ( $searchType ) {
  169. ArgumentValidator::validate($searchType, new ExtendsValidatorRule("Type"));
  170. $typeKey = $searchType->getDomain()
  171. ."::".$searchType->getAuthority()
  172. ."::".$searchType->getKeyword();
  173. if (!is_object($this->_modules[$typeKey]))
  174. throwError(new Error("Unsupported Search Type, '$typeKey'", "RepositorySearchModuleManager", true));
  175. return $this->_modules[$typeKey]->getCurrentValues();
  176. }
  177. /**
  178. * Update the current values with data (maybe stored in the session for instance.
  179. * The keys of the arrays are the field-names in the appropriate context.
  180. * This could have been originally fetched via getCurrentValues
  181. *
  182. * @param object $searchType
  183. * @param array $values
  184. * @return array
  185. * @access public
  186. * @since 10/28/04
  187. */
  188. function setCurrentValues ( $searchType, $values ) {
  189. ArgumentValidator::validate($searchType, new ExtendsValidatorRule("Type"));
  190. $typeKey = $searchType->getDomain()
  191. ."::".$searchType->getAuthority()
  192. ."::".$searchType->getKeyword();
  193. if (!is_object($this->_modules[$typeKey]))
  194. throwError(new Error("Unsupported Search Type, '$typeKey'", "RepositorySearchModuleManager", true));
  195. return $this->_modules[$typeKey]->setCurrentValues($values);
  196. }
  197. }
  198.  
  199. ?>

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