Source for file HarmoniHierarchy.class.php

Documentation is available at HarmoniHierarchy.class.php

  1. <?php
  2.  
  3. require_once(OKI2."/osid/hierarchy/Hierarchy.php");
  4. require_once(HARMONI.'/oki2/hierarchy/HarmoniNode.class.php');
  5. require_once(HARMONI.'/oki2/hierarchy/HierarchyCache.class.php');
  6. require_once(HARMONI.'/oki2/hierarchy/HarmoniNodeIterator.class.php');
  7. require_once(HARMONI.'/oki2/hierarchy/HarmoniTraversalInfo.class.php');
  8. require_once(HARMONI.'/oki2/hierarchy/HarmoniTraversalInfoIterator.class.php');
  9. require_once(HARMONI.'/oki2/hierarchy/DefaultNodeType.class.php');
  10.  
  11. /**
  12. * Hierarchy is a structure composed of nodes arranged in root, parent, and
  13. * child form. The Hierarchy can be traversed in several ways to determine
  14. * the arrangement of nodes. A Hierarchy can allow multiple parents. A
  15. * Hierarchy can allow recursion. The implementation is responsible for
  16. * ensuring that the integrity of the Hierarchy is always maintained.
  17. *
  18. * <p>
  19. * OSID Version: 2.0
  20. * </p>
  21. *
  22. * @package harmoni.osid_v2.hierarchy
  23. *
  24. * @copyright Copyright &copy; 2005, Middlebury College
  25. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  26. *
  27. * @version $Id: HarmoniHierarchy.class.php,v 1.22 2007/09/17 16:44:35 adamfranco Exp $
  28. */
  29.  
  30. class HarmoniHierarchy
  31. extends Hierarchy {
  32.  
  33. /**
  34. * The Id of this hierarchy.
  35. * @var object _id
  36. * @access private
  37. */
  38. var $_id;
  39. /**
  40. * The display name of this hierarchy.
  41. * @var string _displayName
  42. * @access private
  43. */
  44. var $_displayName;
  45. /**
  46. * The description of this hierarchy.
  47. * @var string _description
  48. * @access private
  49. */
  50. var $_description;
  51. /**
  52. * Constructor.
  53. *
  54. * @param object ID $id The Id of this Hierarchy.
  55. * @param string $displayName The displayName of the Hierarchy.
  56. * @param string $description The description of the Hierarchy.
  57. * @param boolean allowsMultipleParents This is true if the hierarchy will allow
  58. * multiple parents.
  59. * @param ref object cache This is the HierarchyCache object. Must be the same
  60. * one that all other nodes in the Hierarchy are using.
  61. * @access public
  62. */
  63. function HarmoniHierarchy($id, $displayName, $description, $cache) {
  64. // ** parameter validation
  65. ArgumentValidator::validate($id, ExtendsValidatorRule::getRule("Id"), true);
  66. ArgumentValidator::validate($displayName, StringValidatorRule::getRule(), true);
  67. ArgumentValidator::validate($description, StringValidatorRule::getRule(), true);
  68. ArgumentValidator::validate($cache, ExtendsValidatorRule::getRule("HierarchyCache"), true);
  69. // ** end of parameter validation
  70. $this->_id =$id;
  71. $this->_displayName = $displayName;
  72. $this->_description = $description;
  73. $this->_cache =$cache;
  74. }
  75.  
  76. /**
  77. * Get the unique Id for this Hierarchy.
  78. *
  79. * @return object Id
  80. *
  81. * @throws object HierarchyException An exception with one of
  82. * the following messages defined in
  83. * org.osid.hierarchy.HierarchyException may be thrown: {@link }
  84. * org.osid.hierarchy.HierarchyException#OPERATION_FAILED
  85. * OPERATION_FAILED}, {@link }
  86. * org.osid.hierarchy.HierarchyException#PERMISSION_DENIED
  87. * PERMISSION_DENIED}, {@link }
  88. * org.osid.hierarchy.HierarchyException#CONFIGURATION_ERROR
  89. * CONFIGURATION_ERROR}, {@link }
  90. * org.osid.hierarchy.HierarchyException#UNIMPLEMENTED
  91. * UNIMPLEMENTED}
  92. *
  93. * @access public
  94. */
  95. function getId () {
  96. return $this->_id;
  97. }
  98.  
  99. /**
  100. * Get the display name for this Hierarchy.
  101. *
  102. * @return string
  103. *
  104. * @throws object HierarchyException An exception with one of
  105. * the following messages defined in
  106. * org.osid.hierarchy.HierarchyException may be thrown: {@link }
  107. * org.osid.hierarchy.HierarchyException#OPERATION_FAILED
  108. * OPERATION_FAILED}, {@link }
  109. * org.osid.hierarchy.HierarchyException#PERMISSION_DENIED
  110. * PERMISSION_DENIED}, {@link }
  111. * org.osid.hierarchy.HierarchyException#CONFIGURATION_ERROR
  112. * CONFIGURATION_ERROR}, {@link }
  113. * org.osid.hierarchy.HierarchyException#UNIMPLEMENTED
  114. * UNIMPLEMENTED}
  115. *
  116. * @access public
  117. */
  118. function getDisplayName () {
  119. return $this->_displayName;
  120. }
  121. /**
  122. * Update the display name for this Hierarchy.
  123. *
  124. * @param string $displayName
  125. *
  126. * @throws object HierarchyException An exception with one of
  127. * the following messages defined in
  128. * org.osid.hierarchy.HierarchyException may be thrown: {@link }
  129. * org.osid.hierarchy.HierarchyException#OPERATION_FAILED
  130. * OPERATION_FAILED}, {@link }
  131. * org.osid.hierarchy.HierarchyException#PERMISSION_DENIED
  132. * PERMISSION_DENIED}, {@link }
  133. * org.osid.hierarchy.HierarchyException#CONFIGURATION_ERROR
  134. * CONFIGURATION_ERROR}, {@link }
  135. * org.osid.hierarchy.HierarchyException#UNIMPLEMENTED
  136. * UNIMPLEMENTED}
  137. *
  138. * @access public
  139. */
  140. function updateDisplayName ( $displayName ) {
  141. // ** parameter validation
  142. $stringRule = StringValidatorRule::getRule();
  143. ArgumentValidator::validate($displayName, $stringRule, true);
  144. // ** end of parameter validation
  145. if ($this->_displayName == $displayName)
  146. return; // nothing to update
  147. // update the object
  148. $this->_displayName = $displayName;
  149.  
  150. // update the database
  151. $dbHandler = Services::getService("DatabaseManager");
  152. $db = $this->_cache->_hyDB.".";
  153. $query = new UpdateQuery();
  154. $query->setTable($db."hierarchy");
  155. $id =$this->getId();
  156. $idValue = $id->getIdString();
  157. $where = "{$db}hierarchy.hierarchy_id = '{$idValue}'";
  158. $query->setWhere($where);
  159. $query->setColumns(array("{$db}hierarchy.hierarchy_display_name"));
  160. $query->setValues(array("'".addslashes($displayName)."'"));
  161. $queryResult =$dbHandler->query($query, $this->_cache->_dbIndex);
  162. if ($queryResult->getNumberOfRows() == 0)
  163. throwError(new Error(HierarchyException::OPERATION_FAILED(),"Hierarchy",true));
  164. if ($queryResult->getNumberOfRows() > 1)
  165. throwError(new Error(HierarchyException::OPERATION_FAILED() ,"Hierarchy",true));
  166. }
  167.  
  168. /**
  169. * Get the description for this Hierarchy.
  170. *
  171. * @return string
  172. *
  173. * @throws object HierarchyException An exception with one of
  174. * the following messages defined in
  175. * org.osid.hierarchy.HierarchyException may be thrown: {@link }
  176. * org.osid.hierarchy.HierarchyException#OPERATION_FAILED
  177. * OPERATION_FAILED}, {@link }
  178. * org.osid.hierarchy.HierarchyException#PERMISSION_DENIED
  179. * PERMISSION_DENIED}, {@link }
  180. * org.osid.hierarchy.HierarchyException#CONFIGURATION_ERROR
  181. * CONFIGURATION_ERROR}, {@link }
  182. * org.osid.hierarchy.HierarchyException#UNIMPLEMENTED
  183. * UNIMPLEMENTED}
  184. *
  185. * @access public
  186. */
  187. function getDescription () {
  188. return $this->_description;
  189. }
  190.  
  191. /**
  192. * Update the description for this Hierarchy.
  193. *
  194. * @param string $description
  195. *
  196. * @throws object HierarchyException An exception with one of
  197. * the following messages defined in
  198. * org.osid.hierarchy.HierarchyException may be thrown: {@link }
  199. * org.osid.hierarchy.HierarchyException#OPERATION_FAILED
  200. * OPERATION_FAILED}, {@link }
  201. * org.osid.hierarchy.HierarchyException#PERMISSION_DENIED
  202. * PERMISSION_DENIED}, {@link }
  203. * org.osid.hierarchy.HierarchyException#CONFIGURATION_ERROR
  204. * CONFIGURATION_ERROR}, {@link }
  205. * org.osid.hierarchy.HierarchyException#UNIMPLEMENTED
  206. * UNIMPLEMENTED}, {@link }
  207. * org.osid.hierarchy.HierarchyException#NULL_ARGUMENT
  208. * NULL_ARGUMENT}
  209. *
  210. * @access public
  211. */
  212. function updateDescription ( $description ) {
  213. // ** parameter validation
  214. ArgumentValidator::validate($description, StringValidatorRule::getRule(), true);
  215. // ** end of parameter validation
  216. if ($this->_description == $description)
  217. return; // nothing to update
  218.  
  219. // update the object
  220. $this->_description = $description;
  221.  
  222. // update the database
  223. $dbHandler = Services::getService("DatabaseManager");
  224. $db = $this->_cache->_hyDB.".";
  225. $query = new UpdateQuery();
  226. $query->setTable($db."hierarchy");
  227. $id =$this->getId();
  228. $idValue = $id->getIdString();
  229. $where = "{$db}hierarchy.hierarchy_id = '{$idValue}'";
  230. $query->setWhere($where);
  231. $query->setColumns(array("{$db}hierarchy.hierarchy_description"));
  232. $query->setValues(array("'".addslashes($description)."'"));
  233. $queryResult =$dbHandler->query($query, $this->_cache->_dbIndex);
  234. if ($queryResult->getNumberOfRows() == 0)
  235. throwError(new Error(HierarchyException::OPERATION_FAILED(),"Hierarchy",true));
  236. if ($queryResult->getNumberOfRows() > 1)
  237. throwError(new Error(HierarchyException::OPERATION_FAILED(),"Hierarchy",true));
  238. }
  239. /**
  240. * Create a root Node. The Node is created with the specified unique Id,
  241. * and, unlike Nodes created with createNode, initially has no parents or
  242. * children.
  243. *
  244. * @param object Id $nodeId
  245. * @param object Type $nodeType
  246. * @param string $displayName
  247. * @param string $description
  248. *
  249. * @return object Node
  250. *
  251. * @throws object HierarchyException An exception with one of
  252. * the following messages defined in
  253. * org.osid.hierarchy.HierarchyException may be thrown: {@link }
  254. * org.osid.hierarchy.HierarchyException#OPERATION_FAILED
  255. * OPERATION_FAILED}, {@link }
  256. * org.osid.hierarchy.HierarchyException#PERMISSION_DENIED
  257. * PERMISSION_DENIED}, {@link }
  258. * org.osid.hierarchy.HierarchyException#CONFIGURATION_ERROR
  259. * CONFIGURATION_ERROR}, {@link }
  260. * org.osid.hierarchy.HierarchyException#UNIMPLEMENTED
  261. * UNIMPLEMENTED}{@link }
  262. * org.osid.hierarchy.HierarchyException#NULL_ARGUMENT
  263. * NULL_ARGUMENT}, {@link }
  264. * org.osid.hierarchy.HierarchyException#SINGLE_PARENT_HIERARCHY
  265. * SINGLE_PARENT_HIERARCHY}
  266. *
  267. * @access public
  268. */
  269. function createRootNode ( $nodeId, $nodeType, $displayName, $description ) {
  270. // ** parameter validation
  271. ArgumentValidator::validate($nodeId, ExtendsValidatorRule::getRule("Id"), true);
  272. ArgumentValidator::validate($nodeType, ExtendsValidatorRule::getRule("Type"), true);
  273. ArgumentValidator::validate($displayName, StringValidatorRule::getRule(), true);
  274. ArgumentValidator::validate($description, StringValidatorRule::getRule(), true);
  275. // ** end of parameter validation
  276.  
  277. return $this->_cache->createRootNode($nodeId, $nodeType, $displayName, $description);
  278. }
  279.  
  280. /**
  281. * Create a Node. The Node is created with the specified unique Id and
  282. * initially has only the specified parent.
  283. *
  284. * @param object Id $nodeId
  285. * @param object Id $parentId
  286. * @param object Type $type
  287. * @param string $displayName
  288. * @param string $description
  289. *
  290. * @return object Node
  291. *
  292. * @throws object HierarchyException An exception with one of
  293. * the following messages defined in
  294. * org.osid.hierarchy.HierarchyException may be thrown: {@link }
  295. * org.osid.hierarchy.HierarchyException#OPERATION_FAILED
  296. * OPERATION_FAILED}, {@link }
  297. * org.osid.hierarchy.HierarchyException#PERMISSION_DENIED
  298. * PERMISSION_DENIED}, {@link }
  299. * org.osid.hierarchy.HierarchyException#CONFIGURATION_ERROR
  300. * CONFIGURATION_ERROR}, {@link }
  301. * org.osid.hierarchy.HierarchyException#UNIMPLEMENTED
  302. * UNIMPLEMENTED}, {@link }
  303. * org.osid.hierarchy.HierarchyException#NULL_ARGUMENT
  304. * NULL_ARGUMENT}, {@link }
  305. * org.osid.hierarchy.HierarchyException#UNKNOWN_PARENT_NODE
  306. * UNKNOWN_PARENT_NODE}, {@link }
  307. * org.osid.hierarchy.HierarchyException#ATTEMPTED_RECURSION
  308. * ATTEMPTED_RECURSION}
  309. *
  310. * @access public
  311. */
  312. function createNode ( $nodeId, $parentId, $type, $displayName, $description ) {
  313. // ** parameter validation
  314. ArgumentValidator::validate($nodeId, ExtendsValidatorRule::getRule("Id"), true);
  315. ArgumentValidator::validate($parentId, ExtendsValidatorRule::getRule("Id"), true);
  316. ArgumentValidator::validate($type, ExtendsValidatorRule::getRule("Type"), true);
  317. ArgumentValidator::validate($displayName, StringValidatorRule::getRule(), true);
  318. ArgumentValidator::validate($description, StringValidatorRule::getRule(), true);
  319. // ** end of parameter validation
  320.  
  321. return $this->_cache->createNode($nodeId, $parentId, $type, $displayName, $description);
  322. }
  323.  
  324. /**
  325. * Delete a Node by Id. Only leaf Nodes can be deleted.
  326. *
  327. * @param object Id $nodeId
  328. *
  329. * @throws object HierarchyException An exception with one of
  330. * the following messages defined in
  331. * org.osid.hierarchy.HierarchyException may be thrown: {@link }
  332. * org.osid.hierarchy.HierarchyException#OPERATION_FAILED
  333. * OPERATION_FAILED}, {@link }
  334. * org.osid.hierarchy.HierarchyException#PERMISSION_DENIED
  335. * PERMISSION_DENIED}, {@link }
  336. * org.osid.hierarchy.HierarchyException#CONFIGURATION_ERROR
  337. * CONFIGURATION_ERROR}, {@link }
  338. * org.osid.hierarchy.HierarchyException#UNIMPLEMENTED
  339. * UNIMPLEMENTED}, {@link }
  340. * org.osid.hierarchy.HierarchyException#NULL_ARGUMENT
  341. * NULL_ARGUMENT}, {@link }
  342. * org.osid.hierarchy.HierarchyException#NODE_TYPE_NOT_FOUND
  343. * NODE_TYPE_NOT_FOUND}, {@link }
  344. * org.osid.hierarchy.HierarchyException#INCONSISTENT_STATE
  345. * INCONSISTENT_STATE}
  346. *
  347. * @access public
  348. */
  349. function deleteNode ( $nodeId ) {
  350. // ** parameter validation
  351. ArgumentValidator::validate($nodeId, ExtendsValidatorRule::getRule("Id"), true);
  352. // ** end of parameter validation
  353. $this->_cache->deleteNode($nodeId->getIdString());
  354. }
  355.  
  356. /**
  357. * Add a NodeType to this Hierarchy.
  358. *
  359. * @param object Type $type
  360. *
  361. * @throws object HierarchyException An exception with one of
  362. * the following messages defined in
  363. * org.osid.hierarchy.HierarchyException may be thrown: {@link }
  364. * org.osid.hierarchy.HierarchyException#OPERATION_FAILED
  365. * OPERATION_FAILED}, {@link }
  366. * org.osid.hierarchy.HierarchyException#PERMISSION_DENIED
  367. * PERMISSION_DENIED}, {@link }
  368. * org.osid.hierarchy.HierarchyException#CONFIGURATION_ERROR
  369. * CONFIGURATION_ERROR}, {@link }
  370. * org.osid.hierarchy.HierarchyException#UNIMPLEMENTED
  371. * UNIMPLEMENTED}, {@link }
  372. * org.osid.hierarchy.HierarchyException#NULL_ARGUMENT
  373. * NULL_ARGUMENT}, {@link }
  374. * org.osid.hierarchy.HierarchyException#ALREADY_ADDED
  375. * ALREADY_ADDED}
  376. *
  377. * @access public
  378. */
  379. function addNodeType ( $type ) {
  380. throwError(new Error(HierarchyException::UNIMPLEMENTED(), "Hierarchy", true));
  381. }
  382.  
  383. /**
  384. * Remove a NodeType from this Hierarchy. Note that no Nodes can have this
  385. * NodeType.
  386. *
  387. * @param object Type $type
  388. *
  389. * @throws object HierarchyException An exception with one of
  390. * the following messages defined in
  391. * org.osid.hierarchy.HierarchyException may be thrown: {@link }
  392. * org.osid.hierarchy.HierarchyException#OPERATION_FAILED
  393. * OPERATION_FAILED}, {@link }
  394. * org.osid.hierarchy.HierarchyException#PERMISSION_DENIED
  395. * PERMISSION_DENIED}, {@link }
  396. * org.osid.hierarchy.HierarchyException#CONFIGURATION_ERROR
  397. * CONFIGURATION_ERROR}, {@link }
  398. * org.osid.hierarchy.HierarchyException#UNIMPLEMENTED
  399. * UNIMPLEMENTED}, {@link }
  400. * org.osid.hierarchy.HierarchyException#NULL_ARGUMENT
  401. * NULL_ARGUMENT}, {@link }
  402. * org.osid.hierarchy.HierarchyException#NODE_TYPE_IN_USE
  403. * NODE_TYPE_IN_USE}, {@link }
  404. * org.osid.hierarchy.HierarchyException#NODE_TYPE_NOT_FOUND
  405. * NODE_TYPE_NOT_FOUND}
  406. *
  407. * @access public
  408. */
  409. function removeNodeType ( $type ) {
  410. throwError(new Error(HierarchyException::UNIMPLEMENTED(), "Hierarchy", true));
  411. }
  412.  
  413. /**
  414. * Get all the Nodes in this Hierarchy.
  415. *
  416. * @return object NodeIterator
  417. *
  418. * @throws object HierarchyException An exception with one of
  419. * the following messages defined in
  420. * org.osid.hierarchy.HierarchyException may be thrown: {@link }
  421. * org.osid.hierarchy.HierarchyException#OPERATION_FAILED
  422. * OPERATION_FAILED}, {@link }
  423. * org.osid.hierarchy.HierarchyException#PERMISSION_DENIED
  424. * PERMISSION_DENIED}, {@link }
  425. * org.osid.hierarchy.HierarchyException#CONFIGURATION_ERROR
  426. * CONFIGURATION_ERROR}, {@link }
  427. * org.osid.hierarchy.HierarchyException#UNIMPLEMENTED
  428. * UNIMPLEMENTED}
  429. *
  430. * @access public
  431. */
  432. function getAllNodes () {
  433. // if all the nodes haven't been cached then do it
  434. $nodes =$this->_cache->getAllNodes();
  435.  
  436. // create the iterator and return them
  437. $obj = new HarmoniNodeIterator($nodes);
  438. return $obj;
  439. }
  440.  
  441. /**
  442. * Get the root Nodes in this Hierarchy.
  443. *
  444. * @return object NodeIterator
  445. *
  446. * @throws object HierarchyException An exception with one of
  447. * the following messages defined in
  448. * org.osid.hierarchy.HierarchyException may be thrown: {@link }
  449. * org.osid.hierarchy.HierarchyException#OPERATION_FAILED
  450. * OPERATION_FAILED}, {@link }
  451. * org.osid.hierarchy.HierarchyException#PERMISSION_DENIED
  452. * PERMISSION_DENIED}, {@link }
  453. * org.osid.hierarchy.HierarchyException#CONFIGURATION_ERROR
  454. * CONFIGURATION_ERROR}, {@link }
  455. * org.osid.hierarchy.HierarchyException#UNIMPLEMENTED
  456. * UNIMPLEMENTED}
  457. *
  458. * @access public
  459. */
  460. function getRootNodes () {
  461. // if all the nodes haven't been cached then do it
  462. $nodes =$this->_cache->getRootNodes();
  463.  
  464. // create the iterator and return them
  465. $obj = new HarmoniNodeIterator($nodes);
  466. return $obj;
  467. }
  468.  
  469. /**
  470. * Get a Node by unique Id.
  471. *
  472. * @param object Id $nodeId
  473. *
  474. * @return object Node
  475. *
  476. * @throws object HierarchyException An exception with one of
  477. * the following messages defined in
  478. * org.osid.hierarchy.HierarchyException may be thrown: {@link }
  479. * org.osid.hierarchy.HierarchyException#OPERATION_FAILED
  480. * OPERATION_FAILED}, {@link }
  481. * org.osid.hierarchy.HierarchyException#PERMISSION_DENIED
  482. * PERMISSION_DENIED}, {@link }
  483. * org.osid.hierarchy.HierarchyException#CONFIGURATION_ERROR
  484. * CONFIGURATION_ERROR}, {@link }
  485. * org.osid.hierarchy.HierarchyException#UNIMPLEMENTED
  486. * UNIMPLEMENTED}, {@link }
  487. * org.osid.hierarchy.HierarchyException#NULL_ARGUMENT
  488. * NULL_ARGUMENT}, {@link }
  489. * org.osid.hierarchy.HierarchyException#NODE_TYPE_NOT_FOUND
  490. * NODE_TYPE_NOT_FOUND}
  491. *
  492. * @access public
  493. */
  494. function getNode ( $nodeId ) {
  495. // ** parameter validation
  496. ArgumentValidator::validate($nodeId, ExtendsValidatorRule::getRule("Id"), true);
  497. // ** end of parameter validation
  498. $idValue = $nodeId->getIdString();
  499. $node = $this->_cache->getNode($idValue);
  500. return $node;
  501. }
  502. /**
  503. * Answer TRUE if the a node exists with the given Id
  504. *
  505. * WARNING: NOT in OSID
  506. *
  507. * @param object Id $nodeId
  508. *
  509. * @return boolean
  510. *
  511. * @access public
  512. */
  513. function nodeExists ( $nodeId ) {
  514. // ** parameter validation
  515. ArgumentValidator::validate($nodeId, ExtendsValidatorRule::getRule("Id"), true);
  516. // ** end of parameter validation
  517. $idValue = $nodeId->getIdString();
  518. return $this->_cache->nodeExists($idValue);
  519. }
  520.  
  521. /**
  522. * Get all NodeTypes used in this Hierarchy.
  523. *
  524. * @return object TypeIterator
  525. *
  526. * @throws object HierarchyException An exception with one of
  527. * the following messages defined in
  528. * org.osid.hierarchy.HierarchyException may be thrown: {@link }
  529. * org.osid.hierarchy.HierarchyException#OPERATION_FAILED
  530. * OPERATION_FAILED}, {@link }
  531. * org.osid.hierarchy.HierarchyException#PERMISSION_DENIED
  532. * PERMISSION_DENIED}, {@link }
  533. * org.osid.hierarchy.HierarchyException#CONFIGURATION_ERROR
  534. * CONFIGURATION_ERROR}, {@link }
  535. * org.osid.hierarchy.HierarchyException#UNIMPLEMENTED
  536. * UNIMPLEMENTED}
  537. *
  538. * @access public
  539. */
  540. function getNodeTypes () {
  541. $dbHandler = Services::getService("DatabaseManager");
  542. $query = new SelectQuery();
  543. $db = $this->_cache->_hyDB.".";
  544. // set the tables
  545. $query->addTable($db."node");
  546. $joinc = $db."node.fk_type = ".$db."type.type_id";
  547. $query->addTable($db."type", INNER_JOIN, $joinc);
  548. $hierarchyIdValue = $this->_id->getIdString();
  549. $query->addWhere($db."node.fk_hierarchy = '{$hierarchyIdValue}'");
  550.  
  551. // set the columns to select
  552. $query->setDistinct(true);
  553. $query->addColumn("type_id", "id", $db."type");
  554. $query->addColumn("type_domain", "domain", $db."type");
  555. $query->addColumn("type_authority", "authority", $db."type");
  556. $query->addColumn("type_keyword", "keyword", $db."type");
  557. $query->addColumn("type_description", "description", $db."type");
  558. $queryResult =$dbHandler->query($query, $this->_cache->_dbIndex);
  559.  
  560. $types = array();
  561. while ($queryResult->hasMoreRows()) {
  562. // fetch current row
  563. $arr = $queryResult->getCurrentRow();
  564. // create type object
  565. $type = new HarmoniType($arr['domain'],$arr['authority'],$arr['keyword'],$arr['description']);
  566. // add it to array
  567. $types[] =$type;
  568.  
  569. $queryResult->advanceRow();
  570. }
  571. $queryResult->free();
  572. $result = new HarmoniTypeIterator($types);
  573. return $result;
  574. }
  575. /**
  576. * Get the Nodes of the specified Type in this Hierarchy.
  577. *
  578. * WARNING: NOT IN OSID - This method is not in the OSIDs as of version 2.0.
  579. *
  580. * @param object Type $nodeType
  581. * @return object NodeIterator Iterators return a set, one at a time. The
  582. * Iterator's hasNext method returns true if there are additional
  583. * objects available; false otherwise. The Iterator's next method
  584. * returns the next object. The order of the objects returned by
  585. * the Iterator is not guaranteed.
  586. *
  587. * @throws HierarchyException if there is a general failure.
  588. *
  589. * @todo Replace JavaDoc with PHPDoc
  590. */
  591. function getNodesByType( $nodeType ) {
  592. // if all the nodes haven't been cached then do it
  593. $where = "type_domain = '".addslashes($nodeType->getDomain())."'";
  594. $where .= " AND type_authority = '".addslashes($nodeType->getAuthority())."'";
  595. $where .= " AND type_keyword = '".addslashes($nodeType->getKeyword())."'";
  596. $nodes =$this->_cache->getNodesFromDB($where);
  597.  
  598. // create the iterator and return them
  599. $iterator = new HarmoniNodeIterator($nodes);
  600. return $iterator;
  601. }
  602.  
  603. /**
  604. * Returns true if multiple parents are allowed; false otherwise.
  605. *
  606. * @return boolean
  607. *
  608. * @throws object HierarchyException An exception with one of
  609. * the following messages defined in
  610. * org.osid.hierarchy.HierarchyException may be thrown: {@link }
  611. * org.osid.hierarchy.HierarchyException#OPERATION_FAILED
  612. * OPERATION_FAILED}, {@link }
  613. * org.osid.hierarchy.HierarchyException#PERMISSION_DENIED
  614. * PERMISSION_DENIED}, {@link }
  615. * org.osid.hierarchy.HierarchyException#CONFIGURATION_ERROR
  616. * CONFIGURATION_ERROR}, {@link }
  617. * org.osid.hierarchy.HierarchyException#UNIMPLEMENTED
  618. * UNIMPLEMENTED}
  619. *
  620. * @access public
  621. */
  622. function allowsMultipleParents () {
  623. return $this->_cache->_allowsMultipleParents;
  624. }
  625.  
  626. /**
  627. * Returns true if recursion allowed; false otherwise.
  628. *
  629. * @return boolean
  630. *
  631. * @throws object HierarchyException An exception with one of
  632. * the following messages defined in
  633. * org.osid.hierarchy.HierarchyException may be thrown: {@link }
  634. * org.osid.hierarchy.HierarchyException#OPERATION_FAILED
  635. * OPERATION_FAILED}, {@link }
  636. * org.osid.hierarchy.HierarchyException#PERMISSION_DENIED
  637. * PERMISSION_DENIED}, {@link }
  638. * org.osid.hierarchy.HierarchyException#CONFIGURATION_ERROR
  639. * CONFIGURATION_ERROR}, {@link }
  640. * org.osid.hierarchy.HierarchyException#UNIMPLEMENTED
  641. * UNIMPLEMENTED}
  642. *
  643. * @access public
  644. */
  645. function allowsRecursion () {
  646. return false;
  647. }
  648.  
  649. /**
  650. * Traverse a Hierarchy returning information about each Node encountered.
  651. *
  652. * @param object Id $startId
  653. * @param int $mode
  654. * @param int $direction
  655. * @param int $levels
  656. *
  657. * @return object TraversalInfoIterator
  658. *
  659. * @throws object HierarchyException An exception with one of
  660. * the following messages defined in
  661. * org.osid.hierarchy.HierarchyException may be thrown: {@link }
  662. * org.osid.hierarchy.HierarchyException#OPERATION_FAILED
  663. * OPERATION_FAILED}, {@link }
  664. * org.osid.hierarchy.HierarchyException#PERMISSION_DENIED
  665. * PERMISSION_DENIED}, {@link }
  666. * org.osid.hierarchy.HierarchyException#CONFIGURATION_ERROR
  667. * CONFIGURATION_ERROR}, {@link }
  668. * org.osid.hierarchy.HierarchyException#UNIMPLEMENTED
  669. * UNIMPLEMENTED}, {@link }
  670. * org.osid.hierarchy.HierarchyException#NODE_TYPE_NOT_FOUND
  671. * NODE_TYPE_NOT_FOUND}, {@link }
  672. * org.osid.hierarchy.HierarchyException#UNKNOWN_TRAVERSAL_MODE
  673. * UNKNOWN_TRAVERSAL_MODE}, {@link }
  674. * org.osid.hierarchy.HierarchyException#UNKNOWN_TRAVERSAL_DIRECTION
  675. * UNKNOWN_TRAVERSAL_DIRECTION}
  676. *
  677. * @access public
  678. */
  679. function traverse ( $startId, $mode, $direction, $levels ) {
  680. // Check the arguments
  681. ArgumentValidator::validate($startId, ExtendsValidatorRule::getRule("Id"));
  682. ArgumentValidator::validate($mode, IntegerValidatorRule::getRule());
  683. ArgumentValidator::validate($direction, IntegerValidatorRule::getRule());
  684. ArgumentValidator::validate($levels, IntegerValidatorRule::getRule());
  685.  
  686. if ($mode != Hierarchy::TRAVERSE_MODE_DEPTH_FIRST()) {
  687. // Only depth-first traversal is supported in the current implementation.
  688. throwError(new Error(HierarchyException::UNKNOWN_TRAVERSAL_DIRECTION(), "Hierarchy", true));
  689. }
  690.  
  691. $down = ($direction == Hierarchy::TRAVERSE_DIRECTION_DOWN());
  692. $result = $this->_cache->traverse($startId, $down, $levels);
  693.  
  694. return $result;
  695. }
  696. /**
  697. * Clears the cache.
  698. *
  699. * WARNING: NOT IN OSID
  700. *
  701. * @access public
  702. ***/
  703. function clearCache() {
  704. $this->_cache->clearCache();
  705. }
  706. }
  707.  
  708. ?>

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