Source for file HarmoniGroup.class.php

Documentation is available at HarmoniGroup.class.php

  1. <?php
  2.  
  3. require_once(dirname(__FILE__)."/GroupsOnlyFromTraversalIterator.class.php");
  4. require_once(OKI2."/osid/agent/Group.php");
  5.  
  6. /**
  7. * Group contains members that are either Agents or other Groups. There are
  8. * management methods for adding, removing, and getting members and Groups.
  9. * There are also methods for testing if a Group or member is contained in a
  10. * Group, and returning all members in a Group, all Groups in a Group, or all
  11. * Groups containing a specific member. Many methods include an argument that
  12. * specifies whether to include all subgroups or not. This allows for more
  13. * flexible maintenance and interrogation of the structure. Note that there is
  14. * no specification for persisting the Group or its content -- this detail is
  15. * left to the implementation.
  16. *
  17. * <p>
  18. * OSID Version: 2.0
  19. * </p>
  20. *
  21. * @package harmoni.osid_v2.agent
  22. *
  23. * @copyright Copyright &copy; 2005, Middlebury College
  24. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  25. *
  26. * @version $Id: HarmoniGroup.class.php,v 1.23 2007/08/22 14:45:44 adamfranco Exp $
  27. */
  28. class HarmoniGroup
  29. extends HarmoniAgent
  30. implements Group
  31. {
  32.  
  33. /**
  34. * Get the Description of this Group.
  35. *
  36. * @return string
  37. *
  38. * @throws object AgentException An exception with one of the
  39. * following messages defined in org.osid.agent.AgentException may
  40. * be thrown: {@link }
  41. * org.osid.agent.AgentException#OPERATION_FAILED
  42. * OPERATION_FAILED}, {@link }
  43. * org.osid.agent.AgentException#PERMISSION_DENIED
  44. * PERMISSION_DENIED}, {@link }
  45. * org.osid.agent.AgentException#CONFIGURATION_ERROR
  46. * CONFIGURATION_ERROR}, {@link }
  47. * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED}
  48. *
  49. * @access public
  50. */
  51. function getDescription () {
  52. return $this->_node->getDescription();
  53. }
  54.  
  55. /**
  56. * Update the Description of this Group.
  57. *
  58. * @param string $description
  59. *
  60. * @throws object AgentException An exception with one of the
  61. * following messages defined in org.osid.agent.AgentException may
  62. * be thrown: {@link }
  63. * org.osid.agent.AgentException#OPERATION_FAILED
  64. * OPERATION_FAILED}, {@link }
  65. * org.osid.agent.AgentException#PERMISSION_DENIED
  66. * PERMISSION_DENIED}, {@link }
  67. * org.osid.agent.AgentException#CONFIGURATION_ERROR
  68. * CONFIGURATION_ERROR}, {@link }
  69. * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED},
  70. * {@link org.osid.agent.AgentException#NULL_ARGUMENT}
  71. * NULL_ARGUMENT}
  72. *
  73. * @access public
  74. */
  75. function updateDescription ( $description ) {
  76. $this->_node->updateDescription($description);
  77. }
  78.  
  79. /**
  80. * Add an Agent or a Group to this Group. The Agent or Group will not be
  81. * added if it already exists in the group.
  82. *
  83. * @param object Agent $memberOrGroup
  84. *
  85. * @throws object AgentException An exception with one of the
  86. * following messages defined in org.osid.agent.AgentException may
  87. * be thrown: {@link }
  88. * org.osid.agent.AgentException#OPERATION_FAILED
  89. * OPERATION_FAILED}, {@link }
  90. * org.osid.agent.AgentException#PERMISSION_DENIED
  91. * PERMISSION_DENIED}, {@link }
  92. * org.osid.agent.AgentException#CONFIGURATION_ERROR
  93. * CONFIGURATION_ERROR}, {@link }
  94. * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED},
  95. * {@link org.osid.agent.AgentException#ALREADY_ADDED}
  96. * ALREADY_ADDED}, {@link }
  97. * org.osid.agent.AgentException#NULL_ARGUMENT NULL_ARGUMENT}
  98. *
  99. * @access public
  100. */
  101. function add ( $memberOrGroup ) {
  102. // ** parameter validation
  103. ArgumentValidator::validate($memberOrGroup, ExtendsValidatorRule::getRule("Agent"), true);
  104. // ** end of parameter validation
  105. // The way groups are currently implemented, it isn't possible to
  106. // add an LdapGroup to a HarmoniGroup. That should be updated to
  107. // make this work.
  108. if (!isset($memberOrGroup->_node)) {
  109. throw new Exception("The way groups are currently implemented, it isn't possible to add an LdapGroup to a HarmoniGroup. That should be updated to make this work.");
  110. }
  111. // print "<div style='border: 1px dotted;, margin: 10px; padding: 10px; background-color: #faa;'>";
  112. // printpre("<strong>Adding agent, ".$memberOrGroup->getDisplayName().", to group, ".$this->getDisplayName().".</strong>");
  113. $memberOrGroup->_node->addParent($this->getId());
  114. // print "</div>";
  115. }
  116. /**
  117. * Remove an Agent member or a Group from this Group. If the Agent or Group
  118. * is not in this group no action is taken and no exception is thrown.
  119. *
  120. * @param object Agent $memberOrGroup
  121. *
  122. * @throws object AgentException An exception with one of the
  123. * following messages defined in org.osid.agent.AgentException may
  124. * be thrown: {@link }
  125. * org.osid.agent.AgentException#OPERATION_FAILED
  126. * OPERATION_FAILED}, {@link }
  127. * org.osid.agent.AgentException#PERMISSION_DENIED
  128. * PERMISSION_DENIED}, {@link }
  129. * org.osid.agent.AgentException#CONFIGURATION_ERROR
  130. * CONFIGURATION_ERROR}, {@link }
  131. * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED},
  132. * {@link org.osid.agent.AgentException#UNKNOWN_ID UNKNOWN_ID},
  133. * {@link org.osid.agent.AgentException#NULL_ARGUMENT}
  134. * NULL_ARGUMENT}
  135. *
  136. * @access public
  137. */
  138. function remove ( $memberOrGroup ) {
  139. // ** parameter validation
  140. ArgumentValidator::validate($memberOrGroup, ExtendsValidatorRule::getRule("Agent"), true);
  141. // ** end of parameter validation
  142. $memberOrGroup->_node->removeParent($this->getId());
  143. }
  144.  
  145. /**
  146. * Get all the Members of this group and optionally all the Members from
  147. * all subgroups. Duplicates are not returned.
  148. *
  149. * @param boolean $includeSubgroups
  150. *
  151. * @return object AgentIterator
  152. *
  153. * @throws object AgentException An exception with one of the
  154. * following messages defined in org.osid.agent.AgentException may
  155. * be thrown: {@link }
  156. * org.osid.agent.AgentException#OPERATION_FAILED
  157. * OPERATION_FAILED}, {@link }
  158. * org.osid.agent.AgentException#PERMISSION_DENIED
  159. * PERMISSION_DENIED}, {@link }
  160. * org.osid.agent.AgentException#CONFIGURATION_ERROR
  161. * CONFIGURATION_ERROR}, {@link }
  162. * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED}
  163. *
  164. * @access public
  165. */
  166. function getMembers ( $includeSubgroups ) {
  167. // ** parameter validation
  168. ArgumentValidator::validate($includeSubgroups, BooleanValidatorRule::getRule(), true);
  169. // ** end of parameter validation
  170. if ($includeSubgroups)
  171. $levels = Hierarchy::TRAVERSE_LEVELS_ALL();
  172. else
  173. $levels = 1;
  174. $traversalIterator = $this->_hierarchy->traverse($this->getId(),
  175. Hierarchy::TRAVERSE_MODE_DEPTH_FIRST(), Hierarchy::TRAVERSE_DIRECTION_DOWN(),
  176. $levels);
  177. $members = new MembersOnlyFromTraversalIterator($traversalIterator);
  178. return $members;
  179. }
  180.  
  181. /**
  182. * Get all the Groups in this group and optionally all the subgroups in
  183. * this group. Note since Groups subclass Agents, we are returning an
  184. * AgentIterator and there is no GroupIterator.
  185. *
  186. * @param boolean $includeSubgroups
  187. *
  188. * @return object AgentIterator
  189. *
  190. * @throws object AgentException An exception with one of the
  191. * following messages defined in org.osid.agent.AgentException may
  192. * be thrown: {@link }
  193. * org.osid.agent.AgentException#OPERATION_FAILED
  194. * OPERATION_FAILED}, {@link }
  195. * org.osid.agent.AgentException#PERMISSION_DENIED
  196. * PERMISSION_DENIED}, {@link }
  197. * org.osid.agent.AgentException#CONFIGURATION_ERROR
  198. * CONFIGURATION_ERROR}, {@link }
  199. * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED}
  200. *
  201. * @access public
  202. */
  203. function getGroups ( $includeSubgroups ) {
  204. // ** parameter validation
  205. ArgumentValidator::validate($includeSubgroups, BooleanValidatorRule::getRule(), true);
  206. // ** end of parameter validation
  207. if ($includeSubgroups)
  208. $levels = Hierarchy::TRAVERSE_LEVELS_ALL();
  209. else
  210. $levels = 1;
  211. $traversalIterator = $this->_hierarchy->traverse($this->getId(),
  212. Hierarchy::TRAVERSE_MODE_DEPTH_FIRST(), Hierarchy::TRAVERSE_DIRECTION_DOWN(),
  213. $levels);
  214. $groups = new GroupsOnlyFromTraversalIterator($traversalIterator, $this->getId());
  215. return $groups;
  216. }
  217.  
  218. /**
  219. * Return <code>true</code> if the Member or Group is in the Group,
  220. * optionally including subgroups, <code>false</code> otherwise.
  221. *
  222. * @param object Agent $memberOrGroup
  223. * @param boolean $searchSubgroups
  224. *
  225. * @return boolean
  226. *
  227. * @throws object AgentException An exception with one of the
  228. * following messages defined in org.osid.agent.AgentException may
  229. * be thrown: {@link }
  230. * org.osid.agent.AgentException#OPERATION_FAILED
  231. * OPERATION_FAILED}, {@link }
  232. * org.osid.agent.AgentException#PERMISSION_DENIED
  233. * PERMISSION_DENIED}, {@link }
  234. * org.osid.agent.AgentException#CONFIGURATION_ERROR
  235. * CONFIGURATION_ERROR}, {@link }
  236. * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED},
  237. * {@link org.osid.agent.AgentException#NULL_ARGUMENT}
  238. * NULL_ARGUMENT}
  239. *
  240. * @access public
  241. */
  242. function contains ( $memberOrGroup, $searchSubgroups ) {
  243. // ** parameter validation
  244. ArgumentValidator::validate($memberOrGroup, ExtendsValidatorRule::getRule("Agent"), true);
  245. ArgumentValidator::validate($searchSubgroups, BooleanValidatorRule::getRule(), true);
  246. // ** end of parameter validation
  247. $id = $memberOrGroup->getId();
  248.  
  249. if ($includeSubgroups)
  250. $levels = Hierarchy::TRAVERSE_LEVELS_ALL();
  251. else
  252. $levels = 1;
  253. $traversalIterator = $this->_hierarchy->traverse($this->getId(),
  254. Hierarchy::TRAVERSE_MODE_DEPTH_FIRST(), Hierarchy::TRAVERSE_DIRECTION_DOWN(),
  255. $levels);
  256. while ($traversalIterator->hasNext()) {
  257. $info = $traversalIterator->next();
  258. if ($id->isEqual($info->getNodeId()))
  259. return true;
  260. }
  261. return FALSE;
  262. }
  263. /**
  264. * Answer true if this Agent is an Group
  265. *
  266. * WARNING: NOT IN OSID
  267. *
  268. * @return boolean
  269. * @access public
  270. * @since 12/7/06
  271. */
  272. function isGroup () {
  273. return true;
  274. }
  275. }
  276.  
  277. ?>

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