Source for file SetManager.class.php

Documentation is available at SetManager.class.php

  1. <?php
  2.  
  3. require_once(dirname(__FILE__)."/PersistentOrderedSet.class.php");
  4.  
  5. /**
  6. * The SetManager maintains a configuration and retreives Sets with that
  7. * configuration.
  8. *
  9. * @package harmoni.sets
  10. *
  11. * @copyright Copyright &copy; 2005, Middlebury College
  12. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  13. *
  14. * @version $Id: SetManager.class.php,v 1.13 2007/09/04 20:25:49 adamfranco Exp $
  15. */
  16. class SetManager {
  17. /**
  18. * @var integer $_dbIndex; The index of the database connection to use.
  19. * @access private
  20. */
  21. var $_dbIndex;
  22. /**
  23. * @var array $_sets; An array of created Set objects
  24. * @access private
  25. */
  26. var $_persistentSets;
  27. /**
  28. * The constructor
  29. *
  30. * @param integer $dbIndex The database index to use
  31. * @access public
  32. * @since 6/28/04
  33. */
  34. function SetManager () {
  35. $this->_persistentSets = array ();
  36. if (!isset($_SESSION['__temporarySets'])
  37. || !is_array($_SESSION['__temporarySets']))
  38. {
  39. $_SESSION['__temporarySets'] = array();
  40. }
  41. }
  42.  
  43. /**
  44. * Assign the configuration of this Manager. Valid configuration options are as
  45. * follows:
  46. * database_index integer
  47. * database_name string
  48. *
  49. * @param object Properties $configuration (original type: java.util.Properties)
  50. *
  51. * @throws object OsidException An exception with one of the following
  52. * messages defined in org.osid.OsidException: {@link }
  53. * org.osid.OsidException#OPERATION_FAILED OPERATION_FAILED},
  54. * {@link org.osid.OsidException#PERMISSION_DENIED}
  55. * PERMISSION_DENIED}, {@link }
  56. * org.osid.OsidException#CONFIGURATION_ERROR
  57. * CONFIGURATION_ERROR}, {@link }
  58. * org.osid.OsidException#UNIMPLEMENTED UNIMPLEMENTED}, {@link }
  59. * org.osid.OsidException#NULL_ARGUMENT NULL_ARGUMENT}
  60. *
  61. * @access public
  62. */
  63. function assignConfiguration ( $configuration ) {
  64. $this->_configuration =$configuration;
  65. $dbIndex =$configuration->getProperty('database_index');
  66. // ** parameter validation
  67. ArgumentValidator::validate($dbIndex, IntegerValidatorRule::getRule(), true);
  68. // ** end of parameter validation
  69. $this->_dbIndex = $dbIndex;
  70. }
  71.  
  72. /**
  73. * Return context of this OsidManager.
  74. *
  75. * @return object OsidContext
  76. *
  77. * @throws object OsidException
  78. *
  79. * @access public
  80. */
  81. function getOsidContext () {
  82. return $this->_osidContext;
  83. }
  84.  
  85. /**
  86. * Assign the context of this OsidManager.
  87. *
  88. * @param object OsidContext $context
  89. *
  90. * @throws object OsidException An exception with one of the following
  91. * messages defined in org.osid.OsidException: {@link }
  92. * org.osid.OsidException#NULL_ARGUMENT NULL_ARGUMENT}
  93. *
  94. * @access public
  95. */
  96. function assignOsidContext ( $context ) {
  97. $this->_osidContext =$context;
  98. }
  99. /**
  100. * Get a Set object of the specified Id. The Set does not have to have been
  101. * created previously and any changes to the set will be persisted
  102. * automatically.
  103. *
  104. * @param object Id $id The Id of the set to get.
  105. * @return object SetInterface
  106. * @access public
  107. * @since 6/28/04
  108. */
  109. function getPersistentSet ( $id ) {
  110. ArgumentValidator::validate($id, ExtendsValidatorRule::getRule("Id"), true);
  111. if (!isset($this->_persistentSets[$id->getIdString()])) {
  112. $this->_persistentSets[$id->getIdString()] = new PersistentOrderedSet(
  113. $id, $this->_dbIndex);
  114. }
  115. return $this->_persistentSets[$id->getIdString()];
  116. }
  117. /**
  118. * Remove all of the items from the set, thereby deleting it.
  119. *
  120. * @param object Id $id The Id of the Set to delete.
  121. * @return void
  122. * @access public
  123. * @since 6/28/04
  124. */
  125. function deletePersistentSet ( $id ) {
  126. $set =$this->getPersistentSet($id);
  127. $set->removeAllItems();
  128. }
  129. /**
  130. * Get a Set object of the specified Id. The Set does not have to have been
  131. * created previously and any changes to the set will be persisted
  132. * automatically for the remainder of the SESSION.
  133. *
  134. * @param object Id $id The Id of the set to get.
  135. * @return object SetInterface
  136. * @access public
  137. * @since 6/28/04
  138. */
  139. function getTemporarySet ( $id ) {
  140. ArgumentValidator::validate($id, ExtendsValidatorRule::getRule("Id"), true);
  141. if (!isset($_SESSION['__temporarySets'][$id->getIdString()])) {
  142. $_SESSION['__temporarySets'][$id->getIdString()] = new OrderedSet($id);
  143. }
  144. return $_SESSION['__temporarySets'][$id->getIdString()];
  145. }
  146. /**
  147. * Remove all of the items from the set, thereby deleting it.
  148. *
  149. * @param object Id $id The Id of the Set to delete.
  150. * @return void
  151. * @access public
  152. * @since 6/28/04
  153. */
  154. function deleteTemporarySet ( $id ) {
  155. $set =$this->getTemporarySet($id);
  156. $set->removeAllItems();
  157. }
  158. /**
  159. * Persist a Set and return the new persistent version of it. If A persistent
  160. * Set of the same Id already exists, the new one will replace it.
  161. *
  162. * @param object OrderedSet $set
  163. * @return object PersistentOrderedSet
  164. * @access public
  165. * @since 8/5/05
  166. */
  167. function persist ( $set ) {
  168. $persistentSet =$this->getPersistentSet($set->getId());
  169. if ($persistentSet->isNotEqualTo($set)) {
  170. $persistentSet->removeAllItems();
  171. $set->reset();
  172. while($set->hasNext()) {
  173. $persistentSet->addItem($set->next());
  174. }
  175. }
  176. return $persistentSet;
  177. }
  178. }
  179.  
  180. ?>

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