Source for file HarmoniAgentManager.class.php

Documentation is available at HarmoniAgentManager.class.php

  1. <?php
  2.  
  3. require_once(OKI2."/osid/agent/AgentManager.php");
  4. require_once(OKI2."/osid/agent/AgentException.php");
  5.  
  6. require_once(HARMONI."oki2/agent/HarmoniAgent.class.php");
  7. require_once(HARMONI."oki2/agent/HarmoniEditableAgent.class.php");
  8. require_once(HARMONI."oki2/agent/HarmoniAgentIterator.class.php");
  9. require_once(HARMONI."oki2/agent/GroupsFromNodesIterator.class.php");
  10. require_once(HARMONI."oki2/agent/MembersOnlyFromTraversalIterator.class.php");
  11. require_once(HARMONI."oki2/agent/HarmoniGroup.class.php");
  12. require_once(HARMONI."oki2/agent/AgentSearches/TokenSearch.class.php");
  13. require_once(HARMONI."oki2/agent/AgentSearches/AncestorGroupSearch.class.php");
  14. require_once(HARMONI."oki2/agent/AgentSearches/RootGroupSearch.class.php");
  15.  
  16. require_once(HARMONI."oki2/shared/HarmoniType.class.php");
  17. require_once(HARMONI."oki2/shared/HarmoniTypeIterator.class.php");
  18. require_once(HARMONI."oki2/shared/HarmoniId.class.php");
  19. require_once(HARMONI."oki2/shared/HarmoniTestId.class.php");
  20. require_once(HARMONI."oki2/shared/HarmoniProperties.class.php");
  21. require_once(HARMONI."oki2/agent/UsersGroup.class.php");
  22. require_once(HARMONI."oki2/agent/EveryoneGroup.class.php");
  23.  
  24. /**
  25. * <p>
  26. * AgentManager handles creating, deleting, and getting Agents and Groups.
  27. * Group is a subclass of Agent. Groups contain members. Group members are
  28. * Agents or other Groups.
  29. * </p>
  30. *
  31. * <p>
  32. * All implementations of OsidManager (manager) provide methods for accessing
  33. * and manipulating the various objects defined in the OSID package. A manager
  34. * defines an implementation of an OSID. All other OSID objects come either
  35. * directly or indirectly from the manager. New instances of the OSID objects
  36. * are created either directly or indirectly by the manager. Because the OSID
  37. * objects are defined using interfaces, create methods must be used instead
  38. * of the new operator to create instances of the OSID objects. Create methods
  39. * are used both to instantiate and persist OSID objects. Using the
  40. * OsidManager class to define an OSID's implementation allows the application
  41. * to change OSID implementations by changing the OsidManager package name
  42. * used to load an implementation. Applications developed using managers
  43. * permit OSID implementation substitution without changing the application
  44. * source code. As with all managers, use the OsidLoader to load an
  45. * implementation of this interface.
  46. * </p>
  47. *
  48. * @package harmoni.osid_v2.agent
  49. *
  50. * @copyright Copyright &copy; 2005, Middlebury College
  51. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  52. *
  53. * @version $Id: HarmoniAgentManager.class.php,v 1.48 2007/09/13 16:04:17 adamfranco Exp $
  54. *
  55. * @author Adam Franco
  56. * @author Dobromir Radichkov
  57. */
  58. class HarmoniAgentManager
  59. extends AgentManager
  60. {
  61. /**
  62. * Whether to use plain agents or editable agents. 'Flavor' is used because
  63. * it would be confusing to use the word 'type' because of the specific use
  64. * of the OSID Type concept
  65. * @var string _agentFlavor
  66. * @access private
  67. */
  68. var $_agentFlavor;
  69. /**
  70. * Constructor. Set up any database connections needed.
  71. */
  72. function HarmoniAgentManager() {
  73. $idManager = Services::getService("Id");
  74. $this->_everyoneId = $idManager->getId("edu.middlebury.agents.everyone");
  75. $this->_allGroupsId = $idManager->getId("edu.middlebury.agents.all_groups");
  76. $this->_allAgentsId = $idManager->getId("edu.middlebury.agents.all_agents");
  77. $this->_usersId = $idManager->getId("edu.middlebury.agents.users");
  78. $this->_anonymousId = $idManager->getId("edu.middlebury.agents.anonymous");
  79. $this->_usersGroup = new UsersGroup();
  80. }
  81. /**
  82. * Assign the configuration of this Manager. Valid configuration options are as
  83. * follows:
  84. * database_index integer
  85. * database_name string
  86. *
  87. * @param object Properties $configuration (original type: java.util.Properties)
  88. *
  89. * @throws object OsidException An exception with one of the following
  90. * messages defined in org.osid.OsidException: {@link }
  91. * org.osid.OsidException#OPERATION_FAILED OPERATION_FAILED},
  92. * {@link org.osid.OsidException#PERMISSION_DENIED}
  93. * PERMISSION_DENIED}, {@link }
  94. * org.osid.OsidException#CONFIGURATION_ERROR
  95. * CONFIGURATION_ERROR}, {@link }
  96. * org.osid.OsidException#UNIMPLEMENTED UNIMPLEMENTED}, {@link }
  97. * org.osid.OsidException#NULL_ARGUMENT NULL_ARGUMENT}
  98. *
  99. * @access public
  100. */
  101. function assignConfiguration ( $configuration ) {
  102. $this->_configuration =$configuration;
  103. $hierarchyId =$configuration->getProperty('hierarchy_id');
  104. $agentFlavor =$configuration->getProperty('defaultAgentFlavor');
  105. // ** parameter validation
  106. ArgumentValidator::validate($hierarchyId, StringValidatorRule::getRule(), true);
  107. ArgumentValidator::validate($agentFlavor, StringValidatorRule::getRule(), true);
  108. // ** end of parameter validation
  109. $idManager = Services::getService("Id");
  110. $this->_hierarchyId = $idManager->getId($hierarchyId);
  111. $this->_agentFlavor = $agentFlavor;
  112. $hierarchyManager = Services::getService("Hierarchy");
  113. $hierarchy =$hierarchyManager->getHierarchy($this->_hierarchyId);
  114. // initialize our Agent Search Types
  115. $this->_agentSearches = array ();
  116. $this->_agentSearches["Agent & Group Search::edu.middlebury.harmoni::TokenSearch"] =
  117. new TokenSearch;
  118. // initialize our Group Search Types
  119. $this->_groupSearches = array ();
  120. $this->_groupSearches["Agent & Group Search::edu.middlebury.harmoni::AncestorGroups"] =
  121. new AncestorGroupSearch ($hierarchy);
  122. $this->_groupSearches["Agent & Group Search::edu.middlebury.harmoni::RootGroups"] =
  123. new RootGroupSearch ($hierarchy);
  124. $this->_groupSearches["Agent & Group Search::edu.middlebury.harmoni::TokenSearch"] =$this->_agentSearches["Agent & Group Search::edu.middlebury.harmoni::TokenSearch"];
  125. $this->_everyoneGroup = new EveryoneGroup($hierarchy, $hierarchy->getNode($this->_everyoneId));
  126. }
  127.  
  128. /**
  129. * Return context of this OsidManager.
  130. *
  131. * @return object OsidContext
  132. *
  133. * @throws object OsidException
  134. *
  135. * @access public
  136. */
  137. function getOsidContext () {
  138. return $this->_osidContext;
  139. }
  140.  
  141. /**
  142. * Assign the context of this OsidManager.
  143. *
  144. * @param object OsidContext $context
  145. *
  146. * @throws object OsidException An exception with one of the following
  147. * messages defined in org.osid.OsidException: {@link }
  148. * org.osid.OsidException#NULL_ARGUMENT NULL_ARGUMENT}
  149. *
  150. * @access public
  151. */
  152. function assignOsidContext ( $context ) {
  153. $this->_osidContext =$context;
  154. }
  155.  
  156.  
  157. /*
  158. * WARNING: NOT IN OSID -- USE AT YOUR OWN RISK
  159. * Change the flavor between editable agent and non editable agent
  160. *
  161. * @return boolean
  162. *
  163. * @param string $agentFlavor
  164. *
  165. * @access public
  166. */
  167. function changeAgentFlavor($agentFlavor){
  168. if($agentFlavor!="HarmoniAgent" && $agentFlavor!="HarmoniEditableAgent"){
  169. return false;
  170. }
  171. $this->_agentFlavor = $agentFlavor;
  172. return true;
  173. }
  174. /*
  175. * WARNING: NOT IN OSID -- USE AT YOUR OWN RISK
  176. * Returns the agent flavor
  177. *
  178. * @return string
  179. * @access public
  180. */
  181. function getAgentFlavor(){
  182. return $this->_agentFlavor;
  183. }
  184.  
  185. /**
  186. * Create an Agent with the display name, Type, and Properties specified.
  187. * Whether a HarmoniAgent or HarmoniEditableAgent is created depends on the
  188. * flavor.
  189. *
  190. * @param string $displayName
  191. * @param object Type $agentType
  192. * @param object Properties $properties
  193. * @param optional object Id $id WARNING: NOT IN OSID -- USE AT YOUR OWN RISK
  194. *
  195. * @return object Agent
  196. *
  197. * @throws object AgentException An exception with one of the
  198. * following messages defined in org.osid.agent.AgentException may
  199. * be thrown: {@link }
  200. * org.osid.agent.AgentException#OPERATION_FAILED
  201. * OPERATION_FAILED}, {@link }
  202. * org.osid.agent.AgentException#PERMISSION_DENIED
  203. * PERMISSION_DENIED}, {@link }
  204. * org.osid.agent.AgentException#CONFIGURATION_ERROR
  205. * CONFIGURATION_ERROR}, {@link }
  206. * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED},
  207. * {@link org.osid.agent.AgentException#NULL_ARGUMENT}
  208. * NULL_ARGUMENT}, {@link }
  209. * org.osid.agent.AgentException#UNKNOWN_TYPE UNKNOWN_TYPE}
  210. *
  211. * @access public
  212. */
  213. function createAgent ( $displayName, $agentType, $properties, $agentId = null ) {
  214. // ** parameter validation
  215. ArgumentValidator::validate($agentType, ExtendsValidatorRule::getRule("Type"), true);
  216. ArgumentValidator::validate($properties, ExtendsValidatorRule::getRule("Properties"), true);
  217. ArgumentValidator::validate($displayName, StringValidatorRule::getRule(), true);
  218. ArgumentValidator::validate($agentId, OptionalRule::getRule(
  219. ExtendsValidatorRule::getRule("Id")), true);
  220. $propertiesArray[] =$properties;
  221. // ** end of parameter validation
  222. // create a new unique id for the agent
  223. if ($agentId == null) {
  224. $idManager = Services::getService("Id");
  225. $agentId =$idManager->createId();
  226. }
  227. // Create a node for the agent
  228. $hierarchyManager = Services::getService("Hierarchy");
  229. $hierarchy =$hierarchyManager->getHierarchy($this->_hierarchyId);
  230. $agentNode =$hierarchy->createNode($agentId, $this->_allAgentsId, $agentType,
  231. $displayName, "");
  232.  
  233.  
  234. // 3. Store the properties of the agent.
  235. $propertyManager = Services::getService("Property");
  236. //properties are grouped by type into typed properties objects which contain all key/value pairs of that type. That's why there's an array of properties objects
  237. foreach($propertiesArray as $property){
  238. $propertyManager->storeProperties($agentId->getIdString(), $property);
  239. }
  240. // create the agent object to return
  241. $agent = new $this->_agentFlavor($hierarchy, $agentNode);
  242. return $agent;
  243. }
  244. /**
  245. * Delete the Agent with the specified unique Id.
  246. *
  247. * @param object Id $id
  248. *
  249. * @throws object AgentException An exception with one of the
  250. * following messages defined in org.osid.agent.AgentException may
  251. * be thrown: {@link }
  252. * org.osid.agent.AgentException#OPERATION_FAILED
  253. * OPERATION_FAILED}, {@link }
  254. * org.osid.agent.AgentException#PERMISSION_DENIED
  255. * PERMISSION_DENIED}, {@link }
  256. * org.osid.agent.AgentException#CONFIGURATION_ERROR
  257. * CONFIGURATION_ERROR}, {@link }
  258. * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED},
  259. * {@link org.osid.agent.AgentException#NULL_ARGUMENT}
  260. * NULL_ARGUMENT}, {@link org.osid.agent.AgentException#UNKNOWN_ID}
  261. * UNKNOWN_ID}
  262. *
  263. * @access public
  264. */
  265. function deleteAgent ( $id ) {
  266. // ** parameter validation
  267. ArgumentValidator::validate($id, ExtendsValidatorRule::getRule("Id"), true);
  268. // ** end of parameter validation
  269. //remove the properties of the agent from the database
  270. $propertyManager = Services::getService("Property");
  271. $propertyManager->deleteAllProperties($id->getIdString());
  272. // Get the node for the agent
  273. $hierarchyManager = Services::getService("Hierarchy");
  274. $hierarchy =$hierarchyManager->getHierarchy($this->_hierarchyId);
  275. $hierarchy->deleteNode($id);
  276. }
  277.  
  278. /**
  279. * Get the Agent with the specified unique Id. Getting an Agent by name is
  280. * not supported since names are not guaranteed to be unique.
  281. *
  282. * @param object Id $id
  283. *
  284. * @return object Agent
  285. *
  286. * @throws object AgentException An exception with one of the
  287. * following messages defined in org.osid.agent.AgentException may
  288. * be thrown: {@link }
  289. * org.osid.agent.AgentException#OPERATION_FAILED
  290. * OPERATION_FAILED}, {@link }
  291. * org.osid.agent.AgentException#PERMISSION_DENIED
  292. * PERMISSION_DENIED}, {@link }
  293. * org.osid.agent.AgentException#CONFIGURATION_ERROR
  294. * CONFIGURATION_ERROR}, {@link }
  295. * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED},
  296. * {@link org.osid.agent.AgentException#NULL_ARGUMENT}
  297. * NULL_ARGUMENT}, {@link org.osid.agent.AgentException#UNKNOWN_ID}
  298. * UNKNOWN_ID}
  299. *
  300. * @access public
  301. */
  302. function getAgent ( $id ) {
  303. // ** parameter validation
  304. ArgumentValidator::validate($id, ExtendsValidatorRule::getRule("Id"), true);
  305. // ** end of parameter validation
  306.  
  307. // Get the node for the agent
  308. $hierarchyManager = Services::getService("Hierarchy");
  309. $hierarchy =$hierarchyManager->getHierarchy($this->_hierarchyId);
  310. if (!$hierarchy->nodeExists($id)) {
  311. throwError(new Error(AgentException::UNKNOWN_ID().", '".$id->getIdString()."'", "AgentManager"));
  312. }
  313. $agentNode = new $this->_agentFlavor($hierarchy, $hierarchy->getNode($id));
  314. return $agentNode;
  315. }
  316.  
  317. /**
  318. * Get all the Agents. The returned iterator provides access to the Agents
  319. * one at a time. Iterators have a method hasNextAgent() which returns
  320. * <code>true</code> if there is an Agent available and a method
  321. * nextAgent() which returns the next Agent.
  322. *
  323. * @return object AgentIterator
  324. *
  325. * @throws object AgentException An exception with one of the
  326. * following messages defined in org.osid.agent.AgentException may
  327. * be thrown: {@link }
  328. * org.osid.agent.AgentException#OPERATION_FAILED
  329. * OPERATION_FAILED}, {@link }
  330. * org.osid.agent.AgentException#PERMISSION_DENIED
  331. * PERMISSION_DENIED}, {@link }
  332. * org.osid.agent.AgentException#CONFIGURATION_ERROR
  333. * CONFIGURATION_ERROR}, {@link }
  334. * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED}
  335. *
  336. * @access public
  337. */
  338. function getAgents () {
  339. $hierarchyManager = Services::getService("Hierarchy");
  340. $hierarchy =$hierarchyManager->getHierarchy($this->_hierarchyId);
  341. $traversalIterator =$hierarchy->traverse($this->_allAgentsId,
  342. Hierarchy::TRAVERSE_MODE_DEPTH_FIRST(), Hierarchy::TRAVERSE_DIRECTION_DOWN(),
  343. Hierarchy::TRAVERSE_LEVELS_ALL());
  344. $agentIterator = new MembersOnlyFromTraversalIterator($traversalIterator);
  345. return $agentIterator;
  346. }
  347. /**
  348. * Get all the Agents with the specified search criteria and search Type.
  349. *
  350. * @param object mixed $searchCriteria (original type: java.io.Serializable)
  351. * @param object Type $agentSearchType
  352. *
  353. * @return object AgentIterator
  354. *
  355. * @throws object AgentException An exception with one of the
  356. * following messages defined in org.osid.agent.AgentException may
  357. * be thrown: {@link }
  358. * org.osid.agent.AgentException#OPERATION_FAILED
  359. * OPERATION_FAILED}, {@link }
  360. * org.osid.agent.AgentException#PERMISSION_DENIED
  361. * PERMISSION_DENIED}, {@link }
  362. * org.osid.agent.AgentException#CONFIGURATION_ERROR
  363. * CONFIGURATION_ERROR}, {@link }
  364. * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED},
  365. * {@link org.osid.agent.AgentException#NULL_ARGUMENT}
  366. * NULL_ARGUMENT}, {@link }
  367. * org.osid.agent.AgentException#UNKNOWN_TYPE UNKNOWN_TYPE}
  368. *
  369. * @access public
  370. */
  371. function getAgentsBySearch ( $searchCriteria, $agentSearchType ) {
  372. $typeString = $agentSearchType->getDomain()
  373. ."::".$agentSearchType->getAuthority()
  374. ."::".$agentSearchType->getKeyword();
  375. // get the Agent Search object
  376. $agentSearch =$this->_agentSearches[$typeString];
  377. if (!is_object($agentSearch))
  378. throwError(new Error(AgentException::UNKNOWN_TYPE(),"AgentManager",true));
  379. return $agentSearch->getAgentsBySearch($searchCriteria);
  380. }
  381. /**
  382. * Get all the agent search Types supported by this implementation.
  383. *
  384. * @return object TypeIterator
  385. *
  386. * @throws object AgentException An exception with one of the
  387. * following messages defined in org.osid.agent.AgentException may
  388. * be thrown: {@link }
  389. * org.osid.agent.AgentException#OPERATION_FAILED
  390. * OPERATION_FAILED}, {@link }
  391. * org.osid.agent.AgentException#PERMISSION_DENIED
  392. * PERMISSION_DENIED}, {@link }
  393. * org.osid.agent.AgentException#CONFIGURATION_ERROR
  394. * CONFIGURATION_ERROR}, {@link }
  395. * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED},
  396. * {@link org.osid.agent.AgentException#NULL_ARGUMENT}
  397. * NULL_ARGUMENT}, {@link }
  398. * org.osid.agent.AgentException#UNKNOWN_TYPE UNKNOWN_TYPE}
  399. *
  400. * @access public
  401. */
  402. function getAgentSearchTypes () {
  403. $types = array();
  404. // Break our search type keys on "::" and create type objects
  405. // to return.
  406. foreach (array_keys($this->_agentSearches) as $typeString) {
  407. $parts = explode("::", $typeString);
  408. $types[] = new HarmoniType($parts[0], $parts[1], $parts[2]);
  409. }
  410. $obj = new HarmoniIterator($types);
  411. return $obj;
  412. }
  413. /**
  414. * Get all the agent Types. The returned iterator provides access to the
  415. * agent Types from this implementation one at a time. Iterators have a
  416. * method hasNext() which returns true if there is an agent Type
  417. * available and a method next() which returns the next agent Type.
  418. *
  419. * @return object TypeIterator
  420. *
  421. * @throws object AgentException An exception with one of the
  422. * following messages defined in org.osid.agent.AgentException may
  423. * be thrown: {@link }
  424. * org.osid.agent.AgentException#OPERATION_FAILED
  425. * OPERATION_FAILED}, {@link }
  426. * org.osid.agent.AgentException#PERMISSION_DENIED
  427. * PERMISSION_DENIED}, {@link }
  428. * org.osid.agent.AgentException#CONFIGURATION_ERROR
  429. * CONFIGURATION_ERROR}, {@link }
  430. * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED}
  431. *
  432. * @access public
  433. */
  434. function getAgentTypes () {
  435. $agents =$this->getAgents();
  436. }
  437. /**
  438. * Get all the property Types. The returned iterator provides access to
  439. * the property Types from this implementation one at a time. Iterators
  440. * have a method hasNext() which returns true if there is another
  441. * property Type available and a method next() which returns the next
  442. * property Type.
  443. *
  444. * @return object TypeIterator
  445. *
  446. * @throws object AgentException An exception with one of the
  447. * following messages defined in org.osid.agent.AgentException may
  448. * be thrown: {@link }
  449. * org.osid.agent.AgentException#OPERATION_FAILED
  450. * OPERATION_FAILED}, {@link }
  451. * org.osid.agent.AgentException#PERMISSION_DENIED
  452. * PERMISSION_DENIED}, {@link }
  453. * org.osid.agent.AgentException#CONFIGURATION_ERROR
  454. * CONFIGURATION_ERROR}, {@link }
  455. * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED}
  456. *
  457. * @access public
  458. */
  459. function getPropertyTypes () {
  460. die ("Method <b>".__FUNCTION__."()</b> declared in interface<b> ".__CLASS__."</b> has not been overloaded in a child class.");
  461. }
  462.  
  463. /**
  464. * Create a Group with the display name, Type, description, and Properties
  465. * specified. All but description are immutable.
  466. *
  467. * @param string $displayName
  468. * @param object Type $groupType
  469. * @param string $description
  470. * @param object Properties $properties
  471. *
  472. * @return object Group
  473. *
  474. * @throws object AgentException An exception with one of the
  475. * following messages defined in org.osid.agent.AgentException may
  476. * be thrown: {@link }
  477. * org.osid.agent.AgentException#OPERATION_FAILED
  478. * OPERATION_FAILED}, {@link }
  479. * org.osid.agent.AgentException#PERMISSION_DENIED
  480. * PERMISSION_DENIED}, {@link }
  481. * org.osid.agent.AgentException#CONFIGURATION_ERROR
  482. * CONFIGURATION_ERROR}, {@link }
  483. * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED},
  484. * {@link org.osid.agent.AgentException#NULL_ARGUMENT}
  485. * NULL_ARGUMENT}, {@link }
  486. * org.osid.agent.AgentException#UNKNOWN_TYPE UNKNOWN_TYPE}
  487. *
  488. * @access public
  489. */
  490. function createGroup ( $displayName, $groupType, $description, $properties, $id = null ) {
  491. // ** parameter validation
  492. ArgumentValidator::validate($groupType, ExtendsValidatorRule::getRule("Type"), true);
  493. ArgumentValidator::validate($displayName, StringValidatorRule::getRule(), true);
  494. ArgumentValidator::validate($description, StringValidatorRule::getRule(), true);
  495. ArgumentValidator::validate($properties, ExtendsValidatorRule::getRule("Properties"), true);
  496. // ensure that we aren't using the type of one of the AuthNTypes
  497. // which would confict with external directories.
  498. // :: Add External Groups
  499. $authNMethodManager = Services::getService("AuthNMethodManager");
  500. $types =$authNMethodManager->getAuthNTypes();
  501. while ($types->hasNext()) {
  502. if ($groupType->isEqual($types->next()))
  503. throwError(new Error(AgentException::PERMISSION_DENIED(),"GroupManager",true));
  504. }
  505. // ** end of parameter validation
  506. // create a new unique id for the group
  507. if (is_object($id) && method_exists($id, 'getIdString')) {
  508. $groupId = $id;
  509. } else {
  510. $idManager = Services::getService("Id");
  511. $groupId =$idManager->createId();
  512. }
  513. // 1. Create the node
  514. $hierarchyManager = Services::getService("Hierarchy");
  515. $hierarchy =$hierarchyManager->getHierarchy($this->_hierarchyId);
  516. $groupNode =$hierarchy->createNode($groupId, $this->_allGroupsId, $groupType,
  517. $displayName, $description);
  518. // 2. Store the properties of the group.
  519. $propertyManager = Services::getService("Property");
  520. $propertiesId = $propertyManager->storeProperties($groupId->getIdString(), $properties);
  521. // create the group object to return
  522. $group = new HarmoniGroup($hierarchy, $groupNode);
  523. // update our cache for isGroup
  524. if (isset($this->_groupTreeIds) && is_array($this->_groupTreeIds)) {
  525. $this->_groupTreeIds[$groupId->getIdString()] =$groupId;
  526. }
  527. return $group;
  528. }
  529.  
  530. /**
  531. * Delete the Group with the specified unique Id.
  532. *
  533. * @param object Id $id
  534. *
  535. * @throws object AgentException An exception with one of the
  536. * following messages defined in org.osid.agent.AgentException may
  537. * be thrown: {@link }
  538. * org.osid.agent.AgentException#OPERATION_FAILED
  539. * OPERATION_FAILED}, {@link }
  540. * org.osid.agent.AgentException#PERMISSION_DENIED
  541. * PERMISSION_DENIED}, {@link }
  542. * org.osid.agent.AgentException#CONFIGURATION_ERROR
  543. * CONFIGURATION_ERROR}, {@link }
  544. * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED},
  545. * {@link org.osid.agent.AgentException#NULL_ARGUMENT}
  546. * NULL_ARGUMENT}, {@link org.osid.agent.AgentException#UNKNOWN_ID}
  547. * UNKNOWN_ID}
  548. *
  549. * @access public
  550. */
  551. function deleteGroup ( $id ) {
  552. // ** parameter validation
  553. ArgumentValidator::validate($id, ExtendsValidatorRule::getRule("Id"), true);
  554. // ** end of parameter validation
  555. //remove the properties of the agent from the database
  556. $propertyManager = Services::getService("Property");
  557. $propertyManager->deleteAllProperties($id->getIdString());
  558. // Get the node for the agent
  559. $hierarchyManager = Services::getService("Hierarchy");
  560. $hierarchy =$hierarchyManager->getHierarchy($this->_hierarchyId);
  561. if (!$hierarchy->nodeExists($id)) {
  562. throwError(new Error(AgentException::PERMISSION_DENIED(),"GroupManager",true));
  563. }
  564. $hierarchy->deleteNode($id);
  565. // update our cache for isGroup
  566. if (is_array($this->_groupTreeIds)) {
  567. unset($this->_groupTreeIds[$id->getIdString()]);
  568. }
  569. }
  570.  
  571. /**
  572. * Gets the Group with the specified unique Id. Getting a Group by name is
  573. * not supported since names are not guaranteed to be unique.
  574. *
  575. * @param object Id $id
  576. *
  577. * @return object Group
  578. *
  579. * @throws object AgentException An exception with one of the
  580. * following messages defined in org.osid.agent.AgentException may
  581. * be thrown: {@link }
  582. * org.osid.agent.AgentException#OPERATION_FAILED
  583. * OPERATION_FAILED}, {@link }
  584. * org.osid.agent.AgentException#PERMISSION_DENIED
  585. * PERMISSION_DENIED}, {@link }
  586. * org.osid.agent.AgentException#CONFIGURATION_ERROR
  587. * CONFIGURATION_ERROR}, {@link }
  588. * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED},
  589. * {@link org.osid.agent.AgentException#NULL_ARGUMENT}
  590. * NULL_ARGUMENT}, {@link org.osid.agent.AgentException#UNKNOWN_ID}
  591. * UNKNOWN_ID}
  592. *
  593. * @access public
  594. */
  595. function getGroup ( $id ) {
  596. // ** parameter validation
  597. ArgumentValidator::validate($id, ExtendsValidatorRule::getRule("Id"), true);
  598. // ** end of parameter validation
  599. if ($id->isEqual($this->_usersId)) {
  600. return $this->_usersGroup;
  601. } else if ($id->isEqual($this->_everyoneId)) {
  602. return $this->_everyoneGroup;
  603. } else {
  604. // Get the node for the agent
  605. $hierarchyManager = Services::getService("Hierarchy");
  606. $hierarchy =$hierarchyManager->getHierarchy($this->_hierarchyId);
  607. $group = false;
  608. if ($hierarchy->nodeExists($id)) {
  609. $group = new HarmoniGroup($hierarchy, $hierarchy->getNode($id));
  610. } else {
  611. // Check external directories
  612. $authNMethodManager = Services::getService("AuthNMethodManager");
  613. $types =$authNMethodManager->getAuthNTypes();
  614. while ($types->hasNext()) {
  615. $type =$types->next();
  616. $authNMethod =$authNMethodManager->getAuthNMethodForType($type);
  617. if ($authNMethod->supportsDirectory() && $authNMethod->isGroup($id)) {
  618. $group =$authNMethod->getGroup($id);
  619. break;
  620. }
  621. }
  622. }
  623. return $group;
  624. }
  625. }
  626. /**
  627. * Get all the Groups. Note since Groups subclass Agents, we are returning
  628. * an AgentIterator and there is no GroupIterator. the returned iterator
  629. * provides access to the Groups one at a time. Iterators have a method
  630. * hasNextAgent() which returns true if there is a Group available and a
  631. * method nextAgent() which returns the next Group.
  632. *
  633. * @return object AgentIterator
  634. *
  635. * @throws object AgentException An exception with one of the
  636. * following messages defined in org.osid.agent.AgentException may
  637. * be thrown: {@link }
  638. * org.osid.agent.AgentException#OPERATION_FAILED
  639. * OPERATION_FAILED}, {@link }
  640. * org.osid.agent.AgentException#PERMISSION_DENIED
  641. * PERMISSION_DENIED}, {@link }
  642. * org.osid.agent.AgentException#CONFIGURATION_ERROR
  643. * CONFIGURATION_ERROR}, {@link }
  644. * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED}
  645. *
  646. * @access public
  647. */
  648. function getGroups () {
  649. $hierarchyManager = Services::getService("Hierarchy");
  650. $hierarchy =$hierarchyManager->getHierarchy($this->_hierarchyId);
  651. $node =$hierarchy->getNode($this->_allGroupsId);
  652. $children =$node->getChildren();
  653. $groups = array();
  654. $groups[] =$this->getGroup($this->_everyoneId);
  655. $groups[] =$this->getGroup($this->_usersId);
  656. $nodeGroups = new GroupsFromNodesIterator($children);
  657. while ($nodeGroups->hasNext()) {
  658. $groups[] =$nodeGroups->next();
  659. }
  660. // :: Add External Groups
  661. $authNMethodManager = Services::getService("AuthNMethodManager");
  662. $types =$authNMethodManager->getAuthNTypes();
  663. while ($types->hasNext()) {
  664. $type =$types->next();
  665. $authNMethod =$authNMethodManager->getAuthNMethodForType($type);
  666. if ($authNMethod->supportsDirectory()) {
  667. $groupsIterator =$authNMethod->getAllGroups();
  668. while ($groupsIterator->hasNext()) {
  669. $groups[] =$groupsIterator->next();
  670. }
  671. }
  672. }
  673. $i = new HarmoniAgentIterator($groups);
  674. return $i;
  675. }
  676. /**
  677. * Get all the groups with the specified search criteria and search Type.
  678. *
  679. * @param object mixed $searchCriteria (original type: java.io.Serializable)
  680. * @param object Type $groupSearchType
  681. *
  682. * @return object AgentIterator
  683. *
  684. * @throws object AgentException An exception with one of the
  685. * following messages defined in org.osid.agent.AgentException may
  686. * be thrown: {@link }
  687. * org.osid.agent.AgentException#OPERATION_FAILED
  688. * OPERATION_FAILED}, {@link }
  689. * org.osid.agent.AgentException#PERMISSION_DENIED
  690. * PERMISSION_DENIED}, {@link }
  691. * org.osid.agent.AgentException#CONFIGURATION_ERROR
  692. * CONFIGURATION_ERROR}, {@link }
  693. * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED},
  694. * {@link org.osid.agent.AgentException#NULL_ARGUMENT}
  695. * NULL_ARGUMENT}, {@link }
  696. * org.osid.agent.AgentException#UNKNOWN_TYPE UNKNOWN_TYPE}
  697. *
  698. * @access public
  699. */
  700. function getGroupsBySearch ( $searchCriteria, $groupSearchType ) {
  701. ArgumentValidator::validate($groupSearchType, ExtendsValidatorRule::getRule("Type"));
  702. $typeString = $groupSearchType->getDomain()
  703. ."::".$groupSearchType->getAuthority()
  704. ."::".$groupSearchType->getKeyword();
  705. // get the Group Search object
  706. $groupSearch =$this->_groupSearches[$typeString];
  707. if (!is_object($groupSearch))
  708. throwError(new Error(AgentException::UNKNOWN_TYPE().", ".Type::typeToString($groupSearchType),"GroupManager",true));
  709. return $groupSearch->getGroupsBySearch($searchCriteria);
  710. }
  711. /**
  712. * Get all the group search types supported by this implementation.
  713. *
  714. * @return object TypeIterator
  715. *
  716. * @throws object AgentException An exception with one of the
  717. * following messages defined in org.osid.agent.AgentException may
  718. * be thrown: {@link }
  719. * org.osid.agent.AgentException#OPERATION_FAILED
  720. * OPERATION_FAILED}, {@link }
  721. * org.osid.agent.AgentException#PERMISSION_DENIED
  722. * PERMISSION_DENIED}, {@link }
  723. * org.osid.agent.AgentException#CONFIGURATION_ERROR
  724. * CONFIGURATION_ERROR}, {@link }
  725. * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED},
  726. * {@link org.osid.agent.AgentException#NULL_ARGUMENT}
  727. * NULL_ARGUMENT}, {@link }
  728. * org.osid.agent.AgentException#UNKNOWN_TYPE UNKNOWN_TYPE}
  729. *
  730. * @access public
  731. */
  732. function getGroupSearchTypes () {
  733. $types = array();
  734. // Break our search type keys on "::" and create type objects
  735. // to return.
  736. foreach (array_keys($this->_groupSearches) as $typeString) {
  737. $parts = explode("::", $typeString);
  738. $types[] = new HarmoniType($parts[0], $parts[1], $parts[2]);
  739. }
  740. $obj = new HarmoniIterator($types);
  741. return $obj;
  742. }
  743. /**
  744. * Get all the group Types. The returned iterator provides access to the
  745. * group Types from this implementation one at a time. Iterators have a
  746. * method hasNext() which returns true if there is a group Type
  747. * available and a method next() which returns the next group Type.
  748. *
  749. * @return object TypeIterator
  750. *
  751. * @throws object AgentException An exception with one of the
  752. * following messages defined in org.osid.agent.AgentException may
  753. * be thrown: {@link }
  754. * org.osid.agent.AgentException#OPERATION_FAILED
  755. * OPERATION_FAILED}, {@link }
  756. * org.osid.agent.AgentException#PERMISSION_DENIED
  757. * PERMISSION_DENIED}, {@link }
  758. * org.osid.agent.AgentException#CONFIGURATION_ERROR
  759. * CONFIGURATION_ERROR}, {@link }
  760. * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED}
  761. *
  762. * @access public
  763. */
  764. function getGroupTypes () {
  765. $hierarchyManager = Services::getService("Hierarchy");
  766. $hierarchy =$hierarchyManager->getHierarchy($this->_hierarchyId);
  767. $node =$hierarchy->getNode($this->_allGroupsId);
  768. $groups =$node->getChildren();
  769. $types = array();
  770. $seen = array();
  771. while($groups->hasNext()) {
  772. $group =$groups->next();
  773. $typeString = Type::typeToString($group->getType());
  774. if (in_array($typeString, $seen)) continue;
  775. $seen[] = $typeString;
  776. $types[] =$group->getType();
  777. }
  778. // Add external directory types
  779. $authNMethodManager = Services::getService("AuthNMethodManager");
  780. $authNTypes =$authNMethodManager->getAuthNTypes();
  781. while ($authNTypes->hasNext()) {
  782. $type =$authNTypes->next();
  783. $authNMethod =$authNMethodManager->getAuthNMethodForType($type);
  784. if ($authNMethod->supportsDirectory())
  785. $types[] =$type;
  786. }
  787. $i = new HarmoniIterator($types);
  788. return $i;
  789. }
  790. /**
  791. * Get all the Agents of the specified Type.
  792. *
  793. * @param object Type $agentType
  794. *
  795. * @return object AgentIterator
  796. *
  797. * @throws object AgentException An exception with one of the
  798. * following messages defined in org.osid.agent.AgentException may
  799. * be thrown: {@link }
  800. * org.osid.agent.AgentException#OPERATION_FAILED
  801. * OPERATION_FAILED}, {@link }
  802. * org.osid.agent.AgentException#PERMISSION_DENIED
  803. * PERMISSION_DENIED}, {@link }
  804. * org.osid.agent.AgentException#CONFIGURATION_ERROR
  805. * CONFIGURATION_ERROR}, {@link }
  806. * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED},
  807. * {@link org.osid.agent.AgentException#NULL_ARGUMENT}
  808. * NULL_ARGUMENT}, {@link }
  809. * org.osid.agent.AgentException#UNKNOWN_TYPE UNKNOWN_TYPE}
  810. *
  811. * @access public
  812. */
  813. function getAgentsByType ( $agentType ) {
  814. die ("Method <b>".__FUNCTION__."()</b> declared in interface<b> ".__CLASS__."</b> has not been overloaded in a child class.");
  815. }
  816.  
  817. /**
  818. * Get all the Groups of the specified Type.
  819. *
  820. * @param object Type $groupType
  821. *
  822. * @return object AgentIterator
  823. *
  824. * @throws object AgentException An exception with one of the
  825. * following messages defined in org.osid.agent.AgentException may
  826. * be thrown: {@link }
  827. * org.osid.agent.AgentException#OPERATION_FAILED
  828. * OPERATION_FAILED}, {@link }
  829. * org.osid.agent.AgentException#PERMISSION_DENIED
  830. * PERMISSION_DENIED}, {@link }
  831. * org.osid.agent.AgentException#CONFIGURATION_ERROR
  832. * CONFIGURATION_ERROR}, {@link }
  833. * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED},
  834. * {@link org.osid.agent.AgentException#NULL_ARGUMENT}
  835. * NULL_ARGUMENT}, {@link }
  836. * org.osid.agent.AgentException#UNKNOWN_TYPE UNKNOWN_TYPE}
  837. *
  838. * @access public
  839. */
  840. function getGroupsByType ( $groupType ) {
  841. die ("Method <b>".__FUNCTION__."()</b> declared in interface<b> ".__CLASS__."</b> has not been overloaded in a child class.");
  842. }
  843. /**
  844. * Return TRUE if the Id specified corresponds to an agent.
  845. *
  846. * WARNING: NOT IN OSID - This method is not part of the OSIDs as of Version 2.0
  847. *
  848. * @param object Id agentId
  849. *
  850. * @return boolean
  851. */
  852. function isAgent( $id) {
  853. // ** parameter validation
  854. ArgumentValidator::validate($id, ExtendsValidatorRule::getRule("Id"), true);
  855. // ** end of parameter validation
  856. if ($id->isEqual($this->_usersId))
  857. return false;
  858. $hierarchyManager = Services::getService("Hierarchy");
  859. $hierarchy =$hierarchyManager->getHierarchy($this->_hierarchyId);
  860. if ($hierarchy->nodeExists($id)) {
  861. $agentNode =$hierarchy->getNode($id);
  862. $parents =$agentNode->getParents();
  863. while($parents->hasNext()) {
  864. $parent =$parents->next();
  865. if ($this->_allAgentsId->isEqual($parent->getId()))
  866. return true;
  867. }
  868. }
  869. return FALSE;
  870. }
  871.  
  872.  
  873. /**
  874. * Returns an {@link Agent} or {@link Group} object, depending on what type of agent the passed id refers to.
  875. *
  876. * WARNING: NOT IN OSID - This method is not part of the OSIDs as of Version 2.0
  877. *
  878. * @param ref object Id
  879. * @return ref object
  880. ***/
  881. function getAgentOrGroup($id)
  882. {
  883. if ($this->isAgent($id)) return $this->getAgent($id);
  884. if ($this->isGroup($id)) return $this->getGroup($id);
  885. $null = null;
  886. return $null;
  887. }
  888. /**
  889. * Return TRUE if the Id specified corresponds to an group.
  890. *
  891. * WARNING: NOT IN OSID - This method is not part of the OSIDs as of Version 2.0
  892. *
  893. * @param object Id agentId
  894. *
  895. * @return boolean
  896. */
  897. function isGroup($id) {
  898. // ** parameter validation
  899. ArgumentValidator::validate($id, ExtendsValidatorRule::getRule("Id"), true);
  900. // ** end of parameter validation
  901. // Agents are determined by being children of the "All Agents" node.
  902. // Check this first as Agents are also listed under the group tree.
  903. if ($this->isAgent($id)) {
  904. return false;
  905. }
  906. if ($id->isEqual($this->_usersId))
  907. return true;
  908. // If the Id does not correspond to an agent and it is a decendent of the
  909. // groups tree, then it must be a group.
  910. if (!isset($this->_groupTreeIds)) {
  911. $this->_groupTreeIds = array();
  912. $this->_groupTreeIds[$this->_everyoneId->getIdString()] =$this->_everyoneId;
  913. $this->_groupTreeIds[$this->_allGroupsId->getIdString()] =$this->_allGroupsId;
  914. $this->_groupTreeIds[$this->_allAgentsId->getIdString()] =$this->_allAgentsId;
  915. $this->_groupTreeIds[$this->_usersId->getIdString()] =$this->_usersId;
  916.  
  917.  
  918. $hierarchyManager = Services::getService("Hierarchy");
  919. $hierarchy =$hierarchyManager->getHierarchy($this->_hierarchyId);
  920. $traversalIterator =$hierarchy->traverse($this->_allGroupsId,
  921. Hierarchy::TRAVERSE_MODE_DEPTH_FIRST(), Hierarchy::TRAVERSE_DIRECTION_DOWN(),
  922. Hierarchy::TRAVERSE_LEVELS_ALL());
  923. while ($traversalIterator->hasNext()) {
  924. $traversalInfo =$traversalIterator->next();
  925. $nodeId =$traversalInfo->getNodeId();
  926. $this->_groupTreeIds[$nodeId->getIdString()] =$nodeId;
  927. }
  928. }
  929. if (array_key_exists($id->getIdString(), $this->_groupTreeIds))
  930. return true;
  931. // Check external directories
  932. $authNMethodManager = Services::getService("AuthNMethodManager");
  933. $types =$authNMethodManager->getAuthNTypes();
  934. while ($types->hasNext()) {
  935. $type =$types->next();
  936. $authNMethod =$authNMethodManager->getAuthNMethodForType($type);
  937. if ($authNMethod->supportsDirectory() && $authNMethod->isGroup($id))
  938. return true;
  939. }
  940. return false;
  941. }
  942. }
  943.  
  944. ?>

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