Source for file HarmoniQualifier.class.php

Documentation is available at HarmoniQualifier.class.php

  1. <?php
  2.  
  3. require_once(OKI2."/osid/authorization/Qualifier.php");
  4. require_once(HARMONI.'oki2/hierarchy/HarmoniNode.class.php');
  5. require_once(HARMONI.'oki2/authorization/AuthorizationCache.class.php');
  6. require_once(HARMONI.'oki2/authorization/DefaultQualifierType.class.php');
  7. require_once(HARMONI.'oki2/authorization/HarmoniQualifierIterator.class.php');
  8.  
  9. /**
  10. * Qualifier is the context in which an Authorization is valid and consists of
  11. * an Id, a description and a QualifierType. Ids in Authorization are
  12. * externally defined and their uniqueness is enforced by the implementation.
  13. *
  14. * <p>
  15. * OSID Version: 2.0
  16. * </p>
  17. *
  18. * @package harmoni.osid_v2.authorization
  19. *
  20. * @copyright Copyright &copy; 2005, Middlebury College
  21. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  22. *
  23. * @version $Id: HarmoniQualifier.class.php,v 1.12 2007/09/04 20:25:38 adamfranco Exp $
  24. */
  25. class HarmoniQualifier
  26. extends Qualifier
  27. {
  28. /**
  29. * The associated hierarchy node object.
  30. * @var object _node
  31. * @access private
  32. */
  33. var $_node;
  34.  
  35. /**
  36. * The AuthorizationCache object.
  37. * @var object _cache
  38. * @access private
  39. */
  40. var $_cache;
  41. /**
  42. * The constructor.
  43. * @param ref object node The associated hierarchy node object.
  44. * @param ref object cache The AuthorizationCache object.
  45. * @access public
  46. */
  47. function HarmoniQualifier($node, $cache) {
  48. // ** parameter validation
  49. ArgumentValidator::validate($node, ExtendsValidatorRule::getRule("Node"), true);
  50. ArgumentValidator::validate($cache, ExtendsValidatorRule::getRule("AuthorizationCache"), true);
  51. // ** end of parameter validation
  52. $this->_node =$node;
  53. $this->_cache =$cache;
  54. }
  55. /**
  56. * Get the unique Id for this Qualifier.
  57. *
  58. * @return object Id
  59. *
  60. * @throws object AuthorizationException An exception with
  61. * one of the following messages defined in
  62. * org.osid.authorization.AuthorizationException may be thrown:
  63. * {@link }
  64. * org.osid.authorization.AuthorizationException#OPERATION_FAILED
  65. * OPERATION_FAILED}, {@link }
  66. * org.osid.authorization.AuthorizationException#PERMISSION_DENIED
  67. * PERMISSION_DENIED}, {@link }
  68. * org.osid.authorization.AuthorizationException#CONFIGURATION_ERROR
  69. * CONFIGURATION_ERROR}, {@link }
  70. * org.osid.authorization.AuthorizationException#UNIMPLEMENTED
  71. * UNIMPLEMENTED}
  72. *
  73. * @access public
  74. */
  75. function getId () {
  76. $id =$this->_node->getId();
  77. return $id;
  78. }
  79.  
  80. /**
  81. * Get the permanent reference name for this Qualifier.
  82. *
  83. * @return string
  84. *
  85. * @throws object AuthorizationException An exception with
  86. * one of the following messages defined in
  87. * org.osid.authorization.AuthorizationException may be thrown:
  88. * {@link }
  89. * org.osid.authorization.AuthorizationException#OPERATION_FAILED
  90. * OPERATION_FAILED}, {@link }
  91. * org.osid.authorization.AuthorizationException#PERMISSION_DENIED
  92. * PERMISSION_DENIED}, {@link }
  93. * org.osid.authorization.AuthorizationException#CONFIGURATION_ERROR
  94. * CONFIGURATION_ERROR}, {@link }
  95. * org.osid.authorization.AuthorizationException#UNIMPLEMENTED
  96. * UNIMPLEMENTED}
  97. *
  98. * @access public
  99. */
  100. function getReferenceName () {
  101. return $this->_node->getDisplayName();
  102. }
  103.  
  104. /**
  105. * Get the description for this Qualifier.
  106. *
  107. * @return string
  108. *
  109. * @throws object AuthorizationException An exception with
  110. * one of the following messages defined in
  111. * org.osid.authorization.AuthorizationException may be thrown:
  112. * {@link }
  113. * org.osid.authorization.AuthorizationException#OPERATION_FAILED
  114. * OPERATION_FAILED}, {@link }
  115. * org.osid.authorization.AuthorizationException#PERMISSION_DENIED
  116. * PERMISSION_DENIED}, {@link }
  117. * org.osid.authorization.AuthorizationException#CONFIGURATION_ERROR
  118. * CONFIGURATION_ERROR}, {@link }
  119. * org.osid.authorization.AuthorizationException#UNIMPLEMENTED
  120. * UNIMPLEMENTED}
  121. *
  122. * @access public
  123. */
  124. function getDescription () {
  125. return $this->_node->getDescription();
  126. }
  127.  
  128. /**
  129. * Return true if this Qualifier has any children; false otherwise
  130. *
  131. * @return boolean
  132. *
  133. * @throws object AuthorizationException An exception with
  134. * one of the following messages defined in
  135. * org.osid.authorization.AuthorizationException may be thrown:
  136. * {@link }
  137. * org.osid.authorization.AuthorizationException#OPERATION_FAILED
  138. * OPERATION_FAILED}, {@link }
  139. * org.osid.authorization.AuthorizationException#PERMISSION_DENIED
  140. * PERMISSION_DENIED}, {@link }
  141. * org.osid.authorization.AuthorizationException#CONFIGURATION_ERROR
  142. * CONFIGURATION_ERROR}, {@link }
  143. * org.osid.authorization.AuthorizationException#UNIMPLEMENTED
  144. * UNIMPLEMENTED}
  145. *
  146. * @access public
  147. */
  148. function isParent () {
  149. return !$this->_node->isLeaf();
  150. }
  151.  
  152. /**
  153. * Get the QualifierType for this Qualifier.
  154. *
  155. * @return object Type
  156. *
  157. * @throws object AuthorizationException An exception with
  158. * one of the following messages defined in
  159. * org.osid.authorization.AuthorizationException may be thrown:
  160. * {@link }
  161. * org.osid.authorization.AuthorizationException#OPERATION_FAILED
  162. * OPERATION_FAILED}, {@link }
  163. * org.osid.authorization.AuthorizationException#PERMISSION_DENIED
  164. * PERMISSION_DENIED}, {@link }
  165. * org.osid.authorization.AuthorizationException#CONFIGURATION_ERROR
  166. * CONFIGURATION_ERROR}, {@link }
  167. * org.osid.authorization.AuthorizationException#UNIMPLEMENTED
  168. * UNIMPLEMENTED}
  169. *
  170. * @access public
  171. */
  172. function getQualifierType () {
  173. return $this->_node->getType();
  174. }
  175.  
  176. /**
  177. * Update the reference name for this Qualifier.
  178. *
  179. * WARNING: NOT IN OSID
  180. *
  181. * @param string $referenceName
  182. *
  183. * @throws object AuthorizationException An exception with
  184. * one of the following messages defined in
  185. * org.osid.authorization.AuthorizationException may be thrown:
  186. * {@link }
  187. * org.osid.authorization.AuthorizationException#OPERATION_FAILED
  188. * OPERATION_FAILED}, {@link }
  189. * org.osid.authorization.AuthorizationException#PERMISSION_DENIED
  190. * PERMISSION_DENIED}, {@link }
  191. * org.osid.authorization.AuthorizationException#CONFIGURATION_ERROR
  192. * CONFIGURATION_ERROR}, {@link }
  193. * org.osid.authorization.AuthorizationException#UNIMPLEMENTED
  194. * UNIMPLEMENTED}, {@link }
  195. * org.osid.authorization.AuthorizationException#NULL_ARGUMENT
  196. * NULL_ARGUMENT}
  197. *
  198. * @access public
  199. */
  200. function updateReferenceName ( $referenceName ) {
  201. $this->_node->updateDisplayName($displayName);
  202. }
  203.  
  204. /**
  205. * Update the description for this Qualifier.
  206. *
  207. * @param string $description
  208. *
  209. * @throws object AuthorizationException An exception with
  210. * one of the following messages defined in
  211. * org.osid.authorization.AuthorizationException may be thrown:
  212. * {@link }
  213. * org.osid.authorization.AuthorizationException#OPERATION_FAILED
  214. * OPERATION_FAILED}, {@link }
  215. * org.osid.authorization.AuthorizationException#PERMISSION_DENIED
  216. * PERMISSION_DENIED}, {@link }
  217. * org.osid.authorization.AuthorizationException#CONFIGURATION_ERROR
  218. * CONFIGURATION_ERROR}, {@link }
  219. * org.osid.authorization.AuthorizationException#UNIMPLEMENTED
  220. * UNIMPLEMENTED}, {@link }
  221. * org.osid.authorization.AuthorizationException#NULL_ARGUMENT
  222. * NULL_ARGUMENT}
  223. *
  224. * @access public
  225. */
  226. function updateDescription ( $description ) {
  227. $this->_node->updateDescription($description);
  228. }
  229.  
  230. /**
  231. * Adds a parent to this Qualifier supported by the Authorization
  232. * implementation.
  233. *
  234. * @param object Id $parentQualifierId
  235. *
  236. * @throws object AuthorizationException An exception with
  237. * one of the following messages defined in
  238. * org.osid.authorization.AuthorizationException may be thrown:
  239. * {@link }
  240. * org.osid.authorization.AuthorizationException#OPERATION_FAILED
  241. * OPERATION_FAILED}, {@link }
  242. * org.osid.authorization.AuthorizationException#PERMISSION_DENIED
  243. * PERMISSION_DENIED}, {@link }
  244. * org.osid.authorization.AuthorizationException#CONFIGURATION_ERROR
  245. * CONFIGURATION_ERROR}, {@link }
  246. * org.osid.authorization.AuthorizationException#UNIMPLEMENTED
  247. * UNIMPLEMENTED}, {@link }
  248. * org.osid.authorization.AuthorizationException#NULL_ARGUMENT
  249. * NULL_ARGUMENT}, {@link }
  250. * org.osid.authorization.AuthorizationException#UNKNOWN_ID
  251. * UNKNOWN_ID}
  252. *
  253. * @access public
  254. */
  255. function addParent ( $parentQualifierId ) {
  256. $this->_node->addParent($parentQualifierId);
  257. }
  258.  
  259. /**
  260. * Removes a parent from this Qualifier. If this is the last parent the
  261. * delete will fail and an AuthorizationException will be thrown. For a
  262. * non-Root Qualifier there must always be a parent.
  263. *
  264. * @param object Id $parentQualifierId
  265. *
  266. * @throws object AuthorizationException An exception with
  267. * one of the following messages defined in
  268. * org.osid.authorization.AuthorizationException may be thrown:
  269. * {@link }
  270. * org.osid.authorization.AuthorizationException#OPERATION_FAILED
  271. * OPERATION_FAILED}, {@link }
  272. * org.osid.authorization.AuthorizationException#PERMISSION_DENIED
  273. * PERMISSION_DENIED}, {@link }
  274. * org.osid.authorization.AuthorizationException#CONFIGURATION_ERROR
  275. * CONFIGURATION_ERROR}, {@link }
  276. * org.osid.authorization.AuthorizationException#UNIMPLEMENTED
  277. * UNIMPLEMENTED}, {@link }
  278. * org.osid.authorization.AuthorizationException#NULL_ARGUMENT
  279. * NULL_ARGUMENT}, {@link }
  280. * org.osid.authorization.AuthorizationException#UNKNOWN_ID
  281. * UNKNOWN_ID}
  282. *
  283. * @access public
  284. */
  285. function removeParent ( $parentQualifierId ) {
  286. $this->_node->removeParent($parentQualifierId);
  287. }
  288.  
  289. /**
  290. * Changes the parent of this Qualifier by adding a new parent and removing
  291. * the old parent.
  292. *
  293. * @param object Id $oldParentId
  294. * @param object Id $newParentId
  295. *
  296. * @throws object AuthorizationException An exception with
  297. * one of the following messages defined in
  298. * org.osid.authorization.AuthorizationException may be thrown:
  299. * {@link }
  300. * org.osid.authorization.AuthorizationException#OPERATION_FAILED
  301. * OPERATION_FAILED}, {@link }
  302. * org.osid.authorization.AuthorizationException#PERMISSION_DENIED
  303. * PERMISSION_DENIED}, {@link }
  304. * org.osid.authorization.AuthorizationException#CONFIGURATION_ERROR
  305. * CONFIGURATION_ERROR}, {@link }
  306. * org.osid.authorization.AuthorizationException#UNIMPLEMENTED
  307. * UNIMPLEMENTED}, {@link }
  308. * org.osid.authorization.AuthorizationException#NULL_ARGUMENT
  309. * NULL_ARGUMENT}, {@link }
  310. * org.osid.authorization.AuthorizationException#UNKNOWN_ID
  311. * UNKNOWN_ID}
  312. *
  313. * @access public
  314. */
  315. function changeParent ( $oldParentId, $newParentId ) {
  316. $this->_node->changeParent($oldParentId, $newParentId);
  317. }
  318.  
  319. /**
  320. * Determines if this Qualifier is the child a given parent
  321. *
  322. * @param object Id $parentId
  323. *
  324. * @return boolean
  325. *
  326. * @throws object AuthorizationException An exception with
  327. * one of the following messages defined in
  328. * org.osid.authorization.AuthorizationException may be thrown:
  329. * {@link }
  330. * org.osid.authorization.AuthorizationException#OPERATION_FAILED
  331. * OPERATION_FAILED}, {@link }
  332. * org.osid.authorization.AuthorizationException#PERMISSION_DENIED
  333. * PERMISSION_DENIED}, {@link }
  334. * org.osid.authorization.AuthorizationException#CONFIGURATION_ERROR
  335. * CONFIGURATION_ERROR}, {@link }
  336. * org.osid.authorization.AuthorizationException#UNIMPLEMENTED
  337. * UNIMPLEMENTED}, {@link }
  338. * org.osid.authorization.AuthorizationException#NULL_ARGUMENT
  339. * NULL_ARGUMENT}, {@link }
  340. * org.osid.authorization.AuthorizationException#UNKNOWN_ID
  341. * UNKNOWN_ID}
  342. *
  343. * @access public
  344. */
  345. function isChildOf ( $parentId ) {
  346. // ** parameter validation
  347. $extendsRule = ExtendsValidatorRule::getRule("Id");
  348. ArgumentValidator::validate($parentId, $extendsRule, true);
  349. // ** end of parameter validation
  350.  
  351. // get the parents of this node
  352. $parents =$this->getParents();
  353. // search for the given parent
  354. while ($parents->hasNext()) {
  355. $parent =$parents->next();
  356. $parentId1 =$parent->getId();
  357. if ($parentId->isEqual($parentId1))
  358. return true;
  359. }
  360. return false;
  361. }
  362.  
  363. /**
  364. * Determines if this Qualifier is a descendant of the given qualifierId.
  365. *
  366. * @param object Id $ancestorId
  367. *
  368. * @return boolean
  369. *
  370. * @throws object AuthorizationException An exception with
  371. * one of the following messages defined in
  372. * org.osid.authorization.AuthorizationException may be thrown:
  373. * {@link }
  374. * org.osid.authorization.AuthorizationException#OPERATION_FAILED
  375. * OPERATION_FAILED}, {@link }
  376. * org.osid.authorization.AuthorizationException#PERMISSION_DENIED
  377. * PERMISSION_DENIED}, {@link }
  378. * org.osid.authorization.AuthorizationException#CONFIGURATION_ERROR
  379. * CONFIGURATION_ERROR}, {@link }
  380. * org.osid.authorization.AuthorizationException#UNIMPLEMENTED
  381. * UNIMPLEMENTED}, {@link }
  382. * org.osid.authorization.AuthorizationException#NULL_ARGUMENT
  383. * NULL_ARGUMENT}, {@link }
  384. * org.osid.authorization.AuthorizationException#UNKNOWN_ID
  385. * UNKNOWN_ID}
  386. *
  387. * @access public
  388. */
  389. function isDescendantOf ( $ancestorId ) {
  390. // Alright, I realize this could be written much more efficiently (for
  391. // example by using Hierarchy->traverse()) but it is too much pain to do so.
  392. // The code below uses the methods in this class and is clearer, albeit slower.
  393. // Are we going to use this method a lot anyway?
  394. // base case
  395. if ($ancestorId->isEqual($this->getId()))
  396. return true;
  397. // recurse up
  398. $parents =$this->getParents();
  399. while ($parents->hasNext()) {
  400. $parent =$parents->next();
  401. if ($parent->isDescendantOf($ancestorId))
  402. return true;
  403. }
  404. return false;
  405. }
  406.  
  407. /**
  408. * Gets the children of this Qualifier.
  409. *
  410. * @return object QualifierIterator
  411. *
  412. * @throws object AuthorizationException An exception with
  413. * one of the following messages defined in
  414. * org.osid.authorization.AuthorizationException may be thrown:
  415. * {@link }
  416. * org.osid.authorization.AuthorizationException#OPERATION_FAILED
  417. * OPERATION_FAILED}, {@link }
  418. * org.osid.authorization.AuthorizationException#PERMISSION_DENIED
  419. * PERMISSION_DENIED}, {@link }
  420. * org.osid.authorization.AuthorizationException#CONFIGURATION_ERROR
  421. * CONFIGURATION_ERROR}, {@link }
  422. * org.osid.authorization.AuthorizationException#UNIMPLEMENTED
  423. * UNIMPLEMENTED}
  424. *
  425. * @access public
  426. */
  427. function getChildren () {
  428. // obtain the parent nodes
  429. $children =$this->_node->getChildren();
  430. $result = array();
  431. // for each node, cache if not cached, create a new Qualifier,
  432. // and add to result array
  433. while ($children->hasNext()) {
  434. $child =$children->next();
  435. $childId =$child->getId();
  436. $idValue = $childId->getIdString();
  437. if (!isset($this->_cache->_qualifiers[$idValue])) {
  438. $qualifier = new HarmoniQualifier($child, $this->_cache);
  439. $this->_cache->_qualifiers[$idValue] =$qualifier;
  440. }
  441. $result[] =$this->_cache->_qualifiers[$idValue];
  442. }
  443. $obj = new HarmoniQualifierIterator($result);
  444. return $obj;
  445. }
  446.  
  447. /**
  448. * Gets the parents of this Qualifier.
  449. *
  450. * @return object QualifierIterator
  451. *
  452. * @throws object AuthorizationException An exception with
  453. * one of the following messages defined in
  454. * org.osid.authorization.AuthorizationException may be thrown:
  455. * {@link }
  456. * org.osid.authorization.AuthorizationException#OPERATION_FAILED
  457. * OPERATION_FAILED}, {@link }
  458. * org.osid.authorization.AuthorizationException#PERMISSION_DENIED
  459. * PERMISSION_DENIED}, {@link }
  460. * org.osid.authorization.AuthorizationException#CONFIGURATION_ERROR
  461. * CONFIGURATION_ERROR}, {@link }
  462. * org.osid.authorization.AuthorizationException#UNIMPLEMENTED
  463. * UNIMPLEMENTED}
  464. *
  465. * @access public
  466. */
  467. function getParents () {
  468. // obtain the parent nodes
  469. $parents =$this->_node->getParents();
  470. $result = array();
  471. // for each node, cache if not cached, create a new Qualifier,
  472. // and add to result array
  473. while ($parents->hasNext()) {
  474. $parent =$parents->next();
  475. $parentId =$parent->getId();
  476. $idValue = $parentId->getIdString();
  477. if (!isset($this->_cache->_qualifiers[$idValue])) {
  478. $qualifier = new HarmoniQualifier($parent, $this->_cache);
  479. $this->_cache->_qualifiers[$idValue] =$qualifier;
  480. }
  481. $result[] =$this->_cache->_qualifiers[$idValue];
  482. }
  483. $obj = new HarmoniQualifierIterator($result);
  484. return $obj;
  485. }
  486. }
  487.  
  488. ?>

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