Source for file HarmoniAgent.class.php

Documentation is available at HarmoniAgent.class.php

  1. <?php
  2. /**
  3. * @package harmoni.osid_v2.agent
  4. *
  5. * @copyright Copyright &copy; 2005, Middlebury College
  6. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  7. *
  8. * @version $Id: HarmoniAgent.class.php,v 1.20 2007/08/22 14:45:44 adamfranco Exp $
  9. */
  10.  
  11. require_once(OKI2."/osid/agent/Agent.php");
  12. require_once(HARMONI."/oki2/shared/HarmoniPropertiesIterator.class.php");
  13.  
  14. /**
  15. * Agent is an abstraction that includes Id, display name, type, and
  16. * Properties. Agents are created using implementations of
  17. * org.osid.agent.AgentManager.
  18. *
  19. * <p>
  20. * OSID Version: 2.0
  21. * </p>
  22. *
  23. * @package harmoni.osid_v2.agent
  24. *
  25. * @copyright Copyright &copy; 2005, Middlebury College
  26. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  27. *
  28. * @version $Id: HarmoniAgent.class.php,v 1.20 2007/08/22 14:45:44 adamfranco Exp $
  29. */
  30. class HarmoniAgent
  31. implements Agent
  32. {
  33.  
  34. /**
  35. * The node that this group corresponds to.
  36. * @var object _node
  37. * @access protected
  38. */
  39. var $_node;
  40. /**
  41. * @var object $_hierarchy;
  42. * @access private
  43. * @since 8/30/05
  44. */
  45. var $_hierarchy;
  46. /**
  47. * @var string $_idString
  48. * @access protected
  49. * @since 9/10/05
  50. */
  51. var $_idString;
  52. /**
  53. * The constructor.
  54. * @param object Hierarchy $hierarchy
  55. * @param object Node $node
  56. * @access public
  57. */
  58. function HarmoniAgent($hierarchy, $node) {
  59. // ** parameter validation
  60. ArgumentValidator::validate($node, ExtendsValidatorRule::getRule("Node"), true);
  61. ArgumentValidator::validate($hierarchy, ExtendsValidatorRule::getRule("Hierarchy"), true);
  62. $this->_hierarchy = $hierarchy;
  63. $this->_node = $node;
  64. // set the local _idString
  65. $id = $this->getId();
  66. $this->_idString = $id->getIdString();
  67. }
  68.  
  69. /**
  70. * Get the name of this Agent.
  71. *
  72. * @return string
  73. *
  74. * @throws object AgentException An exception with one of the
  75. * following messages defined in org.osid.agent.AgentException may
  76. * be thrown: {@link }
  77. * org.osid.agent.AgentException#OPERATION_FAILED
  78. * OPERATION_FAILED}, {@link }
  79. * org.osid.agent.AgentException#PERMISSION_DENIED
  80. * PERMISSION_DENIED}, {@link }
  81. * org.osid.agent.AgentException#CONFIGURATION_ERROR
  82. * CONFIGURATION_ERROR}, {@link }
  83. * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED}
  84. *
  85. * @access public
  86. */
  87. function getDisplayName () {
  88. return $this->_node->getDisplayName();
  89. }
  90.  
  91. /**
  92. * Get the id of this Agent.
  93. *
  94. * @return object Id
  95. *
  96. * @throws object AgentException An exception with one of the
  97. * following messages defined in org.osid.agent.AgentException may
  98. * be thrown: {@link }
  99. * org.osid.agent.AgentException#OPERATION_FAILED
  100. * OPERATION_FAILED}, {@link }
  101. * org.osid.agent.AgentException#PERMISSION_DENIED
  102. * PERMISSION_DENIED}, {@link }
  103. * org.osid.agent.AgentException#CONFIGURATION_ERROR
  104. * CONFIGURATION_ERROR}, {@link }
  105. * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED}
  106. *
  107. * @access public
  108. */
  109. function getId () {
  110. return $this->_node->getId();
  111. }
  112.  
  113. /**
  114. * Get the type of this Agent.
  115. *
  116. * @return object Type
  117. *
  118. * @throws object AgentException An exception with one of the
  119. * following messages defined in org.osid.agent.AgentException may
  120. * be thrown: {@link }
  121. * org.osid.agent.AgentException#OPERATION_FAILED
  122. * OPERATION_FAILED}, {@link }
  123. * org.osid.agent.AgentException#PERMISSION_DENIED
  124. * PERMISSION_DENIED}, {@link }
  125. * org.osid.agent.AgentException#CONFIGURATION_ERROR
  126. * CONFIGURATION_ERROR}, {@link }
  127. * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED}
  128. *
  129. * @access public
  130. */
  131. function getType () {
  132. return $this->_node->getType();
  133. }
  134.  
  135. /**
  136. * Get the Properties associated with this Agent.
  137. *
  138. * @return object PropertiesIterator
  139. *
  140. * @throws object AgentException An exception with one of the
  141. * following messages defined in org.osid.agent.AgentException may
  142. * be thrown: {@link }
  143. * org.osid.agent.AgentException#OPERATION_FAILED
  144. * OPERATION_FAILED}, {@link }
  145. * org.osid.agent.AgentException#PERMISSION_DENIED
  146. * PERMISSION_DENIED}, {@link }
  147. * org.osid.agent.AgentException#CONFIGURATION_ERROR
  148. * CONFIGURATION_ERROR}, {@link }
  149. * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED}
  150. *
  151. * @access public
  152. */
  153. function getProperties () {
  154. $propertyManager = Services::getService("Property");
  155. $iterator = new HarmoniPropertiesIterator(
  156. $propertyManager->retrieveProperties($this->_idString));
  157. return $iterator;
  158. }
  159.  
  160. /**
  161. * Get the Properties of this Type associated with this Agent.
  162. *
  163. * @param object Type $propertiesType
  164. *
  165. * @return object Properties
  166. *
  167. * @throws object AgentException An exception with one of the
  168. * following messages defined in org.osid.agent.AgentException may
  169. * be thrown: {@link }
  170. * org.osid.agent.AgentException#OPERATION_FAILED
  171. * OPERATION_FAILED}, {@link }
  172. * org.osid.agent.AgentException#PERMISSION_DENIED
  173. * PERMISSION_DENIED}, {@link }
  174. * org.osid.agent.AgentException#CONFIGURATION_ERROR
  175. * CONFIGURATION_ERROR}, {@link }
  176. * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED},
  177. * {@link org.osid.agent.AgentException#NULL_ARGUMENT}
  178. * NULL_ARGUMENT}, {@link }
  179. * org.osid.agent.AgentException#UNKNOWN_TYPE UNKNOWN_TYPE}
  180. *
  181. * @access public
  182. */
  183. function getPropertiesByType ( $propertiesType ) {
  184. $propertyManager = Services::getService("Property");
  185. $propertiesArray = $propertyManager->retrieveProperties($this->_idString);
  186. //if we don't have an object of the type, we'll want to return Null so we know that
  187. $propertiesOfType=null;
  188. foreach (array_keys($propertiesArray) as $key) {
  189. if ($propertiesType->isEqual(
  190. $propertiesArray[$key]->getType()))
  191. {
  192. $propertiesOfType = $propertiesArray[$key];
  193. }
  194. }
  195. return $propertiesOfType;
  196. }
  197.  
  198. /**
  199. * Get the Properties Types supported by this Agent.
  200. *
  201. * @return object TypeIterator
  202. *
  203. * @throws object AgentException An exception with one of the
  204. * following messages defined in org.osid.agent.AgentException may
  205. * be thrown: {@link }
  206. * org.osid.agent.AgentException#OPERATION_FAILED
  207. * OPERATION_FAILED}, {@link }
  208. * org.osid.agent.AgentException#PERMISSION_DENIED
  209. * PERMISSION_DENIED}, {@link }
  210. * org.osid.agent.AgentException#CONFIGURATION_ERROR
  211. * CONFIGURATION_ERROR}, {@link }
  212. * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED}
  213. *
  214. * @access public
  215. */
  216. function getPropertyTypes () {
  217. $array = array();
  218. $propertyManager = Services::getService("Property");
  219. $propertiesArray = $propertyManager->retrieveProperties($this->_idString);
  220. foreach (array_keys($propertiesArray) as $key) {
  221. $type = $propertiesArray[$key]->getType();
  222. $typeString = $type->getDomain()
  223. ."::".$type->getAuthority()
  224. ."::".$type->getKeyword();
  225. $array[$typeString] = $type;
  226. }
  227. $iterator = new HarmoniIterator($array);
  228. return $iterator;
  229. }
  230. /**
  231. * Answer true if this Agent is an Agent, not a group
  232. *
  233. * WARNING: NOT IN OSID
  234. *
  235. * @return boolean
  236. * @access public
  237. * @since 12/7/06
  238. */
  239. function isAgent () {
  240. return !$this->isGroup();
  241. }
  242. /**
  243. * Answer true if this Agent is an Group
  244. *
  245. * WARNING: NOT IN OSID
  246. *
  247. * @return boolean
  248. * @access public
  249. * @since 12/7/06
  250. */
  251. function isGroup () {
  252. return false;
  253. }
  254. }
  255.  
  256. ?>

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