Source for file UsersGroup.class.php

Documentation is available at UsersGroup.class.php

  1. <?php
  2.  
  3. require_once(dirname(__FILE__)."/HarmoniGroup.class.php");
  4. require_once(dirname(__FILE__)."/HarmoniAgentIterator.class.php");
  5.  
  6. /**
  7. * The Everyone Group contains all other Agents and Groups in the system,
  8. * including the Anonymous Agent. Agents and Groups cannot be added or removed
  9. * from this group as they are always in it.
  10. *
  11. * <p>
  12. * OSID Version: 2.0
  13. * </p>
  14. *
  15. * @package harmoni.osid_v2.agent
  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: UsersGroup.class.php,v 1.11 2007/09/13 16:04:17 adamfranco Exp $
  21. */
  22. class UsersGroup
  23. extends HarmoniGroup
  24. {
  25.  
  26. /**
  27. * The constructor.
  28. *
  29. * @param integer dbIndex The database connection as returned by the DBHandler.
  30. * @access public
  31. */
  32. function UsersGroup() {
  33. $idManager = Services::getService("Id");
  34. $this->_id = $idManager->getId("edu.middlebury.agents.users");
  35. $this->_idString = $this->_id->getIdString();
  36. $this->_type = new Type("Agents", "edu.middlebury.harmoni", "Any/Anonymous",
  37. _("Special group for only users that can be authenticated."));
  38. $this->_displayName = _("Users");
  39. $this->_description = _("The Users group contains all Agents that can be authenticated.");
  40. // $this->_propertiesArray = array();
  41. // $propertiesType = new HarmoniType('Agents', 'Harmoni', 'Agent Properties',
  42. // 'Properties known to the Harmoni Agents System.');
  43. // $propertiesArray[0] = new HarmoniProperties($propertiesType);
  44. }
  45. /**
  46. * Get the name of this Agent.
  47. *
  48. * @return string
  49. *
  50. * @throws object AgentException An exception with one of the
  51. * following messages defined in org.osid.agent.AgentException may
  52. * be thrown: {@link }
  53. * org.osid.agent.AgentException#OPERATION_FAILED
  54. * OPERATION_FAILED}, {@link }
  55. * org.osid.agent.AgentException#PERMISSION_DENIED
  56. * PERMISSION_DENIED}, {@link }
  57. * org.osid.agent.AgentException#CONFIGURATION_ERROR
  58. * CONFIGURATION_ERROR}, {@link }
  59. * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED}
  60. *
  61. * @access public
  62. */
  63. function getDisplayName () {
  64. return $this->_displayName;
  65. }
  66. /**
  67. * Get the Description of this Group.
  68. *
  69. * @return string
  70. *
  71. * @throws object AgentException An exception with one of the
  72. * following messages defined in org.osid.agent.AgentException may
  73. * be thrown: {@link }
  74. * org.osid.agent.AgentException#OPERATION_FAILED
  75. * OPERATION_FAILED}, {@link }
  76. * org.osid.agent.AgentException#PERMISSION_DENIED
  77. * PERMISSION_DENIED}, {@link }
  78. * org.osid.agent.AgentException#CONFIGURATION_ERROR
  79. * CONFIGURATION_ERROR}, {@link }
  80. * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED}
  81. *
  82. * @access public
  83. */
  84. function getDescription () {
  85. return $this->_description;
  86. }
  87.  
  88. /**
  89. * Get the id of this Agent.
  90. *
  91. * @return object Id
  92. *
  93. * @throws object AgentException An exception with one of the
  94. * following messages defined in org.osid.agent.AgentException may
  95. * be thrown: {@link }
  96. * org.osid.agent.AgentException#OPERATION_FAILED
  97. * OPERATION_FAILED}, {@link }
  98. * org.osid.agent.AgentException#PERMISSION_DENIED
  99. * PERMISSION_DENIED}, {@link }
  100. * org.osid.agent.AgentException#CONFIGURATION_ERROR
  101. * CONFIGURATION_ERROR}, {@link }
  102. * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED}
  103. *
  104. * @access public
  105. */
  106. function getId () {
  107. return $this->_id;
  108. }
  109.  
  110. /**
  111. * Get the type of this Agent.
  112. *
  113. * @return object Type
  114. *
  115. * @throws object AgentException An exception with one of the
  116. * following messages defined in org.osid.agent.AgentException may
  117. * be thrown: {@link }
  118. * org.osid.agent.AgentException#OPERATION_FAILED
  119. * OPERATION_FAILED}, {@link }
  120. * org.osid.agent.AgentException#PERMISSION_DENIED
  121. * PERMISSION_DENIED}, {@link }
  122. * org.osid.agent.AgentException#CONFIGURATION_ERROR
  123. * CONFIGURATION_ERROR}, {@link }
  124. * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED}
  125. *
  126. * @access public
  127. */
  128. function getType () {
  129. return $this->_type;
  130. }
  131. /**
  132. * Update the Description of this Group.
  133. *
  134. * @param string $description
  135. *
  136. * @throws object AgentException An exception with one of the
  137. * following messages defined in org.osid.agent.AgentException may
  138. * be thrown: {@link }
  139. * org.osid.agent.AgentException#OPERATION_FAILED
  140. * OPERATION_FAILED}, {@link }
  141. * org.osid.agent.AgentException#PERMISSION_DENIED
  142. * PERMISSION_DENIED}, {@link }
  143. * org.osid.agent.AgentException#CONFIGURATION_ERROR
  144. * CONFIGURATION_ERROR}, {@link }
  145. * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED},
  146. * {@link org.osid.agent.AgentException#NULL_ARGUMENT}
  147. * NULL_ARGUMENT}
  148. *
  149. * @access public
  150. */
  151. function updateDescription ( $description ) {
  152. throwError(new Error(AgentException::PERMISSION_DENIED(),"UsersGroup",true));
  153. }
  154.  
  155. /**
  156. * Add an Agent or a Group to this Group. The Agent or Group will not be
  157. * added if it already exists in the group.
  158. *
  159. * @param object Agent $memberOrGroup
  160. *
  161. * @throws object AgentException An exception with one of the
  162. * following messages defined in org.osid.agent.AgentException may
  163. * be thrown: {@link }
  164. * org.osid.agent.AgentException#OPERATION_FAILED
  165. * OPERATION_FAILED}, {@link }
  166. * org.osid.agent.AgentException#PERMISSION_DENIED
  167. * PERMISSION_DENIED}, {@link }
  168. * org.osid.agent.AgentException#CONFIGURATION_ERROR
  169. * CONFIGURATION_ERROR}, {@link }
  170. * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED},
  171. * {@link org.osid.agent.AgentException#ALREADY_ADDED}
  172. * ALREADY_ADDED}, {@link }
  173. * org.osid.agent.AgentException#NULL_ARGUMENT NULL_ARGUMENT}
  174. *
  175. * @access public
  176. */
  177. function add ( $memberOrGroup ) {
  178. throwError(new Error(AgentException::PERMISSION_DENIED(),"UsersGroup",true));
  179. }
  180.  
  181. /**
  182. * An implementation-specific public method that does exactly the same as add(),
  183. * but does not insert into the database.
  184. * @access public
  185. * @param object memberOrGroup
  186. * @throws object AgentException An exception with one of the
  187. * following messages defined in org.osid.agent.AgentException may
  188. * be thrown: {@link }
  189. * org.osid.agent.AgentException#OPERATION_FAILED
  190. * OPERATION_FAILED}, {@link }
  191. * org.osid.agent.AgentException#PERMISSION_DENIED
  192. * PERMISSION_DENIED}, {@link }
  193. * org.osid.agent.AgentException#CONFIGURATION_ERROR
  194. * CONFIGURATION_ERROR}, {@link }
  195. * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED},
  196. * {@link org.osid.agent.AgentException#ALREADY_ADDED}
  197. * ALREADY_ADDED}, {@link }
  198. * org.osid.agent.AgentException#NULL_ARGUMENT NULL_ARGUMENT}
  199. *
  200. */
  201. function attach( $memberOrGroup) {
  202. throwError(new Error(AgentException::PERMISSION_DENIED(),"UsersGroup",true));
  203. }
  204. /**
  205. * Remove an Agent member or a Group from this Group. If the Agent or Group
  206. * is not in this group no action is taken and no exception is thrown.
  207. *
  208. * @param object Agent $memberOrGroup
  209. *
  210. * @throws object AgentException An exception with one of the
  211. * following messages defined in org.osid.agent.AgentException may
  212. * be thrown: {@link }
  213. * org.osid.agent.AgentException#OPERATION_FAILED
  214. * OPERATION_FAILED}, {@link }
  215. * org.osid.agent.AgentException#PERMISSION_DENIED
  216. * PERMISSION_DENIED}, {@link }
  217. * org.osid.agent.AgentException#CONFIGURATION_ERROR
  218. * CONFIGURATION_ERROR}, {@link }
  219. * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED},
  220. * {@link org.osid.agent.AgentException#UNKNOWN_ID UNKNOWN_ID},
  221. * {@link org.osid.agent.AgentException#NULL_ARGUMENT}
  222. * NULL_ARGUMENT}
  223. *
  224. * @access public
  225. */
  226. function remove ( $memberOrGroup ) {
  227. throwError(new Error(AgentException::PERMISSION_DENIED(),"UsersGroup",true));
  228. }
  229.  
  230. /**
  231. * Get all the Members of this group and optionally all the Members from
  232. * all subgroups. Duplicates are not returned.
  233. *
  234. * @param boolean $includeSubgroups
  235. *
  236. * @return object AgentIterator
  237. *
  238. * @throws object AgentException An exception with one of the
  239. * following messages defined in org.osid.agent.AgentException may
  240. * be thrown: {@link }
  241. * org.osid.agent.AgentException#OPERATION_FAILED
  242. * OPERATION_FAILED}, {@link }
  243. * org.osid.agent.AgentException#PERMISSION_DENIED
  244. * PERMISSION_DENIED}, {@link }
  245. * org.osid.agent.AgentException#CONFIGURATION_ERROR
  246. * CONFIGURATION_ERROR}, {@link }
  247. * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED}
  248. *
  249. * @access public
  250. */
  251. function getMembers ( $includeSubgroups ) {
  252. $agentManager = Services::getService("Agent");
  253. $ids = Services::getService("Id");
  254. $obj = new UsersGroupIterator($agentManager->getAgents());
  255. return $obj;
  256. }
  257.  
  258. /**
  259. * Get all the Groups in this group and optionally all the subgroups in
  260. * this group. Note since Groups subclass Agents, we are returning an
  261. * AgentIterator and there is no GroupIterator.
  262. *
  263. * @param boolean $includeSubgroups
  264. *
  265. * @return object AgentIterator
  266. *
  267. * @throws object AgentException An exception with one of the
  268. * following messages defined in org.osid.agent.AgentException may
  269. * be thrown: {@link }
  270. * org.osid.agent.AgentException#OPERATION_FAILED
  271. * OPERATION_FAILED}, {@link }
  272. * org.osid.agent.AgentException#PERMISSION_DENIED
  273. * PERMISSION_DENIED}, {@link }
  274. * org.osid.agent.AgentException#CONFIGURATION_ERROR
  275. * CONFIGURATION_ERROR}, {@link }
  276. * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED}
  277. *
  278. * @access public
  279. */
  280. function getGroups ( $includeSubgroups ) {
  281. $groups = array();
  282. $obj = new HarmoniAgentIterator($groups);
  283. return $obj;
  284. }
  285.  
  286. /**
  287. * Return <code>true</code> if the Member or Group is in the Group,
  288. * optionally including subgroups, <code>false</code> otherwise.
  289. *
  290. * @param object Agent $memberOrGroup
  291. * @param boolean $searchSubgroups
  292. *
  293. * @return boolean
  294. *
  295. * @throws object AgentException An exception with one of the
  296. * following messages defined in org.osid.agent.AgentException may
  297. * be thrown: {@link }
  298. * org.osid.agent.AgentException#OPERATION_FAILED
  299. * OPERATION_FAILED}, {@link }
  300. * org.osid.agent.AgentException#PERMISSION_DENIED
  301. * PERMISSION_DENIED}, {@link }
  302. * org.osid.agent.AgentException#CONFIGURATION_ERROR
  303. * CONFIGURATION_ERROR}, {@link }
  304. * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED},
  305. * {@link org.osid.agent.AgentException#NULL_ARGUMENT}
  306. * NULL_ARGUMENT}
  307. *
  308. * @access public
  309. */
  310. function contains ( $memberOrGroup, $searchSubgroups ) {
  311. // we are going to ignore the Everyone group and the Anonymous agent
  312. // otherwise they are in the group
  313. $ids = Services::getService("Id");
  314. $ignore = array("edu.middlebury.agents.users","edu.middlebury.agents.everyone","edu.middlebury.agents.anonymous");
  315. foreach ($igonre as $id) {
  316. $rId = $ids->getId($id);
  317. if ($rId->isEqual($memberOrGroup->getId())) return false;
  318. }
  319. return true;
  320. }
  321. }
  322.  
  323. /**
  324. * The UsersGroupIterator takes an AgentIterator and filters out the Anonymous user.
  325. *
  326. * <p>
  327. * OSID Version: 2.0
  328. * </p>
  329. *
  330. * @package harmoni.osid_v2.agent
  331. *
  332. * @copyright Copyright &copy; 2005, Middlebury College
  333. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  334. *
  335. * @version $Id: UsersGroup.class.php,v 1.11 2007/09/13 16:04:17 adamfranco Exp $
  336. */
  337.  
  338. class UsersGroupIterator extends HarmoniAgentIterator {
  339. var $_iterator;
  340. var $_next;
  341. var $_ignore;
  342. function UsersGroupIterator($agentIterator) {
  343. $this->_iterator = $agentIterator;
  344. $this->_next = null;
  345. $ids = Services::getService("Id");
  346. $this->_ignore = $ids->getId("edu.middlebury.agents.anonymous");
  347. $this->_getNext();
  348. }
  349. function _getNext() {
  350. if (!$this->_iterator->hasNext()) {
  351. $this->_next = null;
  352. return;
  353. }
  354. $this->_next = $this->_iterator->next();
  355. if ($this->_ignore->isEqual($this->_next->getId()))
  356. $this->_getNext();
  357. }
  358. function hasNext() {
  359. return $this->_next?true:false;
  360. }
  361. function next() {
  362. if ($this->_next) {
  363. $next = $this->_next;
  364. $this->_getNext();
  365. return $next;
  366. }
  367. return null;
  368. }
  369. }
  370.  
  371. ?>

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