Source for file HarmoniPartStructure.class.php

Documentation is available at HarmoniPartStructure.class.php

  1. <?php
  2.  
  3. require(OKI2."osid/repository/PartStructure.php");
  4.  
  5. /**
  6. * Each Asset has one of the AssetType supported by the Repository. There are
  7. * also zero or more RecordStructures required by the Repository for each
  8. * AssetType. RecordStructures provide structural information. The values for
  9. * a given Asset's RecordStructure are stored in a Record. RecordStructures
  10. * can contain sub-elements which are referred to as PartStructures. The
  11. * structure defined in the RecordStructure and its PartStructures is used in
  12. * for any Records for the Asset. Records have Parts which parallel
  13. * PartStructures.
  14. *
  15. * <p>
  16. * OSID Version: 2.0
  17. * </p>
  18. *
  19. * @package harmoni.osid_v2.repository
  20. *
  21. * @copyright Copyright &copy;2005, Middlebury College
  22. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
  23. *
  24. * @version $Id: HarmoniPartStructure.class.php,v 1.20 2007/09/04 20:25:43 adamfranco Exp $
  25. */
  26. class HarmoniPartStructure extends PartStructure
  27. // extends java.io.Serializable
  28.  
  29. {
  30.  
  31. var $_schemaField;
  32. var $_recordStructure;
  33. function HarmoniPartStructure($recordStructure, $schemaField, $repositoryId) {
  34. ArgumentValidator::validate($repositoryId, ExtendsValidatorRule::getRule("Id"));
  35. $this->_schemaField =$schemaField;
  36. $this->_recordStructure =$recordStructure;
  37. $this->_repositoryId =$repositoryId;
  38. }
  39. /**
  40. * Get the display name for this PartStructure.
  41. *
  42. * @return string
  43. *
  44. * @throws object RepositoryException An exception with one of
  45. * the following messages defined in
  46. * org.osid.repository.RepositoryException may be thrown: {@link }
  47. * org.osid.repository.RepositoryException#OPERATION_FAILED
  48. * OPERATION_FAILED}, {@link }
  49. * org.osid.repository.RepositoryException#PERMISSION_DENIED
  50. * PERMISSION_DENIED}, {@link }
  51. * org.osid.repository.RepositoryException#CONFIGURATION_ERROR
  52. * CONFIGURATION_ERROR}, {@link }
  53. * org.osid.repository.RepositoryException#UNIMPLEMENTED
  54. * UNIMPLEMENTED}
  55. *
  56. * @access public
  57. */
  58. function getDisplayName () {
  59. return $this->_schemaField->getDisplayName();
  60. }
  61.  
  62.  
  63. /**
  64. * Update the display name for this PartStructure.
  65. *
  66. * @param string $displayName
  67. *
  68. * @throws object RepositoryException An exception with one of
  69. * the following messages defined in
  70. * org.osid.repository.RepositoryException may be thrown: {@link }
  71. * org.osid.repository.RepositoryException#OPERATION_FAILED
  72. * OPERATION_FAILED}, {@link }
  73. * org.osid.repository.RepositoryException#PERMISSION_DENIED
  74. * PERMISSION_DENIED}, {@link }
  75. * org.osid.repository.RepositoryException#CONFIGURATION_ERROR
  76. * CONFIGURATION_ERROR}, {@link }
  77. * org.osid.repository.RepositoryException#UNIMPLEMENTED
  78. * UNIMPLEMENTED}, {@link }
  79. * org.osid.repository.RepositoryException#NULL_ARGUMENT
  80. * NULL_ARGUMENT}
  81. *
  82. * @access public
  83. */
  84. function updateDisplayName ( $displayName ) {
  85. $this->_schemaField->updateDisplayName($displayName);
  86. $this->_schemaField->update();
  87. $id =$this->getId();
  88. $this->_schemaField->commit($id->getIdString());
  89. }
  90. /**
  91. * Get the description for this PartStructure.
  92. *
  93. * @return string
  94. *
  95. * @throws object RepositoryException An exception with one of
  96. * the following messages defined in
  97. * org.osid.repository.RepositoryException may be thrown: {@link }
  98. * org.osid.repository.RepositoryException#OPERATION_FAILED
  99. * OPERATION_FAILED}, {@link }
  100. * org.osid.repository.RepositoryException#PERMISSION_DENIED
  101. * PERMISSION_DENIED}, {@link }
  102. * org.osid.repository.RepositoryException#CONFIGURATION_ERROR
  103. * CONFIGURATION_ERROR}, {@link }
  104. * org.osid.repository.RepositoryException#UNIMPLEMENTED
  105. * UNIMPLEMENTED}
  106. *
  107. * @access public
  108. */
  109. function getDescription () {
  110. if ($desc = $this->_schemaField->getDescription()) return $desc;
  111. return "A HarmoniDataManager field of type '".$this->_schemaField->getType()."'.";
  112. }
  113. /**
  114. * Update the description for this PartStructure.
  115. *
  116. * WARNING: NOT IN OSID
  117. *
  118. * @param string $description
  119. *
  120. * @throws object RepositoryException An exception with one of
  121. * the following messages defined in
  122. * org.osid.repository.RepositoryException may be thrown: {@link }
  123. * org.osid.repository.RepositoryException#OPERATION_FAILED
  124. * OPERATION_FAILED}, {@link }
  125. * org.osid.repository.RepositoryException#PERMISSION_DENIED
  126. * PERMISSION_DENIED}, {@link }
  127. * org.osid.repository.RepositoryException#CONFIGURATION_ERROR
  128. * CONFIGURATION_ERROR}, {@link }
  129. * org.osid.repository.RepositoryException#UNIMPLEMENTED
  130. * UNIMPLEMENTED}, {@link }
  131. * org.osid.repository.RepositoryException#NULL_ARGUMENT
  132. * NULL_ARGUMENT}
  133. *
  134. * @access public
  135. */
  136. function updateDescription ( $description ) {
  137. $this->_schemaField->updateDescription($description);
  138. $this->_schemaField->update();
  139. $id =$this->getId();
  140. $this->_schemaField->commit($id->getIdString());
  141. }
  142. /**
  143. * Get the Type for this PartStructure.
  144. *
  145. * @return object Type
  146. *
  147. * @throws object RepositoryException An exception with one of
  148. * the following messages defined in
  149. * org.osid.repository.RepositoryException may be thrown: {@link }
  150. * org.osid.repository.RepositoryException#OPERATION_FAILED
  151. * OPERATION_FAILED}, {@link }
  152. * org.osid.repository.RepositoryException#PERMISSION_DENIED
  153. * PERMISSION_DENIED}, {@link }
  154. * org.osid.repository.RepositoryException#CONFIGURATION_ERROR
  155. * CONFIGURATION_ERROR}, {@link }
  156. * org.osid.repository.RepositoryException#UNIMPLEMENTED
  157. * UNIMPLEMENTED}
  158. *
  159. * @access public
  160. */
  161. function getType () {
  162. if (!isset($this->_type)) {
  163. $type = $this->_schemaField->getType();
  164. $this->_type = new HarmoniType("Repository", "edu.middlebury.harmoni", $type);
  165. }
  166. return $this->_type;
  167. }
  168.  
  169. /**
  170. * Get the unique Id for this PartStructure.
  171. *
  172. * @return object Id
  173. *
  174. * @throws object RepositoryException An exception with one of
  175. * the following messages defined in
  176. * org.osid.repository.RepositoryException may be thrown: {@link }
  177. * org.osid.repository.RepositoryException#OPERATION_FAILED
  178. * OPERATION_FAILED}, {@link }
  179. * org.osid.repository.RepositoryException#PERMISSION_DENIED
  180. * PERMISSION_DENIED}, {@link }
  181. * org.osid.repository.RepositoryException#CONFIGURATION_ERROR
  182. * CONFIGURATION_ERROR}, {@link }
  183. * org.osid.repository.RepositoryException#UNIMPLEMENTED
  184. * UNIMPLEMENTED}
  185. *
  186. * @access public
  187. */
  188. function getId () {
  189. $idManager = Services::getService("Id");
  190. return $idManager->getId(
  191. $this->_schemaField->getID()
  192. );
  193. }
  194.  
  195. /**
  196. * Get all the PartStructures in the PartStructure. Iterators return a
  197. * set, one at a time.
  198. *
  199. * @return object PartStructureIterator
  200. *
  201. * @throws object RepositoryException An exception with one of
  202. * the following messages defined in
  203. * org.osid.repository.RepositoryException may be thrown: {@link }
  204. * org.osid.repository.RepositoryException#OPERATION_FAILED
  205. * OPERATION_FAILED}, {@link }
  206. * org.osid.repository.RepositoryException#PERMISSION_DENIED
  207. * PERMISSION_DENIED}, {@link }
  208. * org.osid.repository.RepositoryException#CONFIGURATION_ERROR
  209. * CONFIGURATION_ERROR}, {@link }
  210. * org.osid.repository.RepositoryException#UNIMPLEMENTED
  211. * UNIMPLEMENTED}
  212. *
  213. * @access public
  214. */
  215. function getPartStructures () {
  216. $array = array();
  217. $obj = new HarmoniNodeIterator($array);
  218. return $obj; // @todo replace with HarmoniPartStructureIterator
  219. }
  220.  
  221. /**
  222. * Return true if this PartStructure is automatically populated by the
  223. * Repository; false otherwise. Examples of the kind of PartStructures
  224. * that might be populated are a time-stamp or the Agent setting the data.
  225. *
  226. * @return boolean
  227. *
  228. * @throws object RepositoryException An exception with one of
  229. * the following messages defined in
  230. * org.osid.repository.RepositoryException may be thrown: {@link }
  231. * org.osid.repository.RepositoryException#OPERATION_FAILED
  232. * OPERATION_FAILED}, {@link }
  233. * org.osid.repository.RepositoryException#PERMISSION_DENIED
  234. * PERMISSION_DENIED}, {@link }
  235. * org.osid.repository.RepositoryException#CONFIGURATION_ERROR
  236. * CONFIGURATION_ERROR}, {@link }
  237. * org.osid.repository.RepositoryException#UNIMPLEMENTED
  238. * UNIMPLEMENTED}
  239. *
  240. * @access public
  241. */
  242. function isPopulatedByRepository () {
  243. return false;
  244. }
  245.  
  246. /**
  247. * Return true if this PartStructure is mandatory; false otherwise.
  248. *
  249. * @return boolean
  250. *
  251. * @throws object RepositoryException An exception with one of
  252. * the following messages defined in
  253. * org.osid.repository.RepositoryException may be thrown: {@link }
  254. * org.osid.repository.RepositoryException#OPERATION_FAILED
  255. * OPERATION_FAILED}, {@link }
  256. * org.osid.repository.RepositoryException#PERMISSION_DENIED
  257. * PERMISSION_DENIED}, {@link }
  258. * org.osid.repository.RepositoryException#CONFIGURATION_ERROR
  259. * CONFIGURATION_ERROR}, {@link }
  260. * org.osid.repository.RepositoryException#UNIMPLEMENTED
  261. * UNIMPLEMENTED}
  262. *
  263. * @access public
  264. */
  265. function isMandatory () {
  266. return $this->_schemaField->isRequired();
  267. }
  268. /**
  269. * Update the mandatory flag for this PartStructure.
  270. *
  271. * WARNING: NOT IN OSID
  272. *
  273. * @param boolean $isMandatory
  274. *
  275. * @throws object RepositoryException An exception with one of
  276. * the following messages defined in
  277. * org.osid.repository.RepositoryException may be thrown: {@link }
  278. * org.osid.repository.RepositoryException#OPERATION_FAILED
  279. * OPERATION_FAILED}, {@link }
  280. * org.osid.repository.RepositoryException#PERMISSION_DENIED
  281. * PERMISSION_DENIED}, {@link }
  282. * org.osid.repository.RepositoryException#CONFIGURATION_ERROR
  283. * CONFIGURATION_ERROR}, {@link }
  284. * org.osid.repository.RepositoryException#UNIMPLEMENTED
  285. * UNIMPLEMENTED}, {@link }
  286. * org.osid.repository.RepositoryException#NULL_ARGUMENT
  287. * NULL_ARGUMENT}
  288. *
  289. * @access public
  290. */
  291. function updateIsMandatory ( $isMandatory ) {
  292. $this->_schemaField->setRequired($isMandatory);
  293. $this->_schemaField->update();
  294. $id =$this->getId();
  295. $this->_schemaField->commit($id->getIdString());
  296. }
  297.  
  298. /**
  299. * Return true if this PartStructure is repeatable; false otherwise. This
  300. * is determined by the implementation.
  301. *
  302. * @return boolean
  303. *
  304. * @throws object RepositoryException An exception with one of
  305. * the following messages defined in
  306. * org.osid.repository.RepositoryException may be thrown: {@link }
  307. * org.osid.repository.RepositoryException#OPERATION_FAILED
  308. * OPERATION_FAILED}, {@link }
  309. * org.osid.repository.RepositoryException#PERMISSION_DENIED
  310. * PERMISSION_DENIED}, {@link }
  311. * org.osid.repository.RepositoryException#CONFIGURATION_ERROR
  312. * CONFIGURATION_ERROR}, {@link }
  313. * org.osid.repository.RepositoryException#UNIMPLEMENTED
  314. * UNIMPLEMENTED}
  315. *
  316. * @access public
  317. */
  318. function isRepeatable () {
  319. return $this->_schemaField->getMultFlag();
  320. }
  321. /**
  322. * Update the repeatable flag for this PartStructure.
  323. *
  324. * WARNING: NOT IN OSID
  325. *
  326. * @param boolean $isRepeatable
  327. *
  328. * @throws object RepositoryException An exception with one of
  329. * the following messages defined in
  330. * org.osid.repository.RepositoryException may be thrown: {@link }
  331. * org.osid.repository.RepositoryException#OPERATION_FAILED
  332. * OPERATION_FAILED}, {@link }
  333. * org.osid.repository.RepositoryException#PERMISSION_DENIED
  334. * PERMISSION_DENIED}, {@link }
  335. * org.osid.repository.RepositoryException#CONFIGURATION_ERROR
  336. * CONFIGURATION_ERROR}, {@link }
  337. * org.osid.repository.RepositoryException#UNIMPLEMENTED
  338. * UNIMPLEMENTED}, {@link }
  339. * org.osid.repository.RepositoryException#NULL_ARGUMENT
  340. * NULL_ARGUMENT}
  341. *
  342. * @access public
  343. */
  344. function updateIsRepeatable ( $isRepeatable ) {
  345. $this->_schemaField->setMultFlag($isRepeatable);
  346. $this->_schemaField->update();
  347. $id =$this->getId();
  348. $this->_schemaField->commit($id->getIdString());
  349. }
  350.  
  351.  
  352. /**
  353. * Get the RecordStructure associated with this PartStructure.
  354. *
  355. * @return object RecordStructure
  356. *
  357. * @throws object RepositoryException An exception with one of
  358. * the following messages defined in
  359. * org.osid.repository.RepositoryException may be thrown: {@link }
  360. * org.osid.repository.RepositoryException#OPERATION_FAILED
  361. * OPERATION_FAILED}, {@link }
  362. * org.osid.repository.RepositoryException#PERMISSION_DENIED
  363. * PERMISSION_DENIED}, {@link }
  364. * org.osid.repository.RepositoryException#CONFIGURATION_ERROR
  365. * CONFIGURATION_ERROR}, {@link }
  366. * org.osid.repository.RepositoryException#UNIMPLEMENTED
  367. * UNIMPLEMENTED}
  368. *
  369. * @access public
  370. */
  371. function getRecordStructure () {
  372. return $this->_recordStructure;
  373. }
  374.  
  375. /**
  376. * Validate a Part against its PartStructure. Return true if valid; false
  377. * otherwise. The status of the Asset holding this Record is not changed
  378. * through this method. The implementation may throw an Exception for any
  379. * validation failures and use the Exception's message to identify
  380. * specific causes.
  381. *
  382. * @param object Part $part
  383. *
  384. * @return boolean
  385. *
  386. * @throws object RepositoryException An exception with one of
  387. * the following messages defined in
  388. * org.osid.repository.RepositoryException may be thrown: {@link }
  389. * org.osid.repository.RepositoryException#OPERATION_FAILED
  390. * OPERATION_FAILED}, {@link }
  391. * org.osid.repository.RepositoryException#PERMISSION_DENIED
  392. * PERMISSION_DENIED}, {@link }
  393. * org.osid.repository.RepositoryException#CONFIGURATION_ERROR
  394. * CONFIGURATION_ERROR}, {@link }
  395. * org.osid.repository.RepositoryException#UNIMPLEMENTED
  396. * UNIMPLEMENTED}, {@link }
  397. * org.osid.repository.RepositoryException#NULL_ARGUMENT
  398. * NULL_ARGUMENT}
  399. *
  400. * @access public
  401. */
  402. function validatePart ( $part ) {
  403. // we can check if the part (ie, RecordFieldValue) has values of the right type.
  404. // @todo
  405. return true;
  406. }
  407. /*******************************************************
  408. * Authority Lists:
  409. * The OSID does not have any support for authority lists.
  410. * These methods could have been placed in another system,
  411. * but have been placed here for ease of locating them.
  412. * Also involved with Authority Lists is a SearchType:
  413. * Repository::edu.middlebury.harmoni::AuthorityValue
  414. * which takes a PartStructure Id and a Value to search on.
  415. *********************************************************/
  416.  
  417. /**
  418. * Answer the authoritative values for this part.
  419. *
  420. * WARNING: NOT in OSID
  421. *
  422. * @return object ObjectIterator
  423. * @access public
  424. * @since 4/25/06
  425. */
  426. function getAuthoritativeValues () {
  427. if (!isset($this->_authoritativeValueObjects)) {
  428. $dtm = Services::getService("DataTypeManager");
  429. $type =$this->getType();
  430. $class = $dtm->primitiveClassForType($type->getKeyword());
  431. $this->_loadAuthoritativeValueStrings();
  432. $this->_authoritativeValueObjects = array();
  433. foreach ($this->_authoritativeValueStrings as $valueString) {
  434. eval('$valueObject = '.$class.'::fromString($valueString);');
  435. if ($valueObject)
  436. $this->_authoritativeValueObjects[$valueString] =$valueObject;
  437. }
  438. }
  439. $iterator = new HarmoniIterator($this->_authoritativeValueObjects);
  440. return $iterator;
  441. }
  442. /**
  443. * Answer true if the value pass is authoritative.
  444. *
  445. * WARNING: NOT in OSID
  446. *
  447. * @param object $value
  448. * @return boolean
  449. * @access public
  450. * @since 4/25/06
  451. */
  452. function isAuthoritativeValue ( $value ) {
  453. $this->_loadAuthoritativeValueStrings();
  454. return in_array($value->asString(), $this->_authoritativeValueStrings);
  455. }
  456. /**
  457. * Remove an authoritative value.
  458. *
  459. * WARNING: NOT in OSID
  460. *
  461. * @param object $value
  462. * @return void
  463. * @access public
  464. * @since 4/25/06
  465. */
  466. function removeAuthoritativeValue ( $value ) {
  467. if ($this->isAuthoritativeValue($value)) {
  468. // remove the object from our objects array
  469. if (isset($this->_authoritativeValueObjects[$value->asString()]))
  470. unset($this->_authoritativeValueObjects[$value->asString()]);
  471. // Remove the string from our strings array
  472. unset($this->_authoritativeValueStrings[array_search($value->asString(), $this->_authoritativeValueStrings)]);
  473. // Remove the value from our database
  474. $query = new DeleteQuery;
  475. $query->setTable('dr_authoritative_values');
  476. $id =$this->getId();
  477. $query->addWhere("fk_partstructure = '".addslashes($id->getIdString())."'");
  478. $query->addWhere("fk_repository = '".addslashes($this->_repositoryId->getIdString())."'");
  479. $query->addWhere("value = '".addslashes($value->asString())."'");
  480. $dbc = Services::getService("DBHandler");
  481. $repositoryManager = Services::getService("Repository");
  482. $configuration =$repositoryManager->_configuration;
  483. $dbc->query($query, $configuration->getProperty('database_index'));
  484. }
  485. }
  486. /**
  487. * Add an authoritative value
  488. *
  489. * WARNING: NOT in OSID
  490. *
  491. * @param object $value
  492. * @return void
  493. * @access public
  494. * @since 4/25/06
  495. */
  496. function addAuthoritativeValue ( $value ) {
  497. if (!$this->isAuthoritativeValue($value)) {
  498. // add the object to our objects array
  499. $this->_authoritativeValueObjects[$value->asString()] =$value;
  500. // add the string to our strings array
  501. $this->_authoritativeValueStrings[] = $value->asString();
  502. // add the value to our database
  503. $query = new InsertQuery;
  504. $query->setTable('dr_authoritative_values');
  505. $query->setColumns(array('fk_partstructure', 'fk_repository', 'value'));
  506. $id =$this->getId();
  507. $query->addRowOfValues(array(
  508. "'".addslashes($id->getIdString())."'",
  509. "'".addslashes($this->_repositoryId->getIdString())."'",
  510. "'".addslashes($value->asString())."'"));
  511. $dbc = Services::getService("DBHandler");
  512. $repositoryManager = Services::getService("Repository");
  513. $configuration =$repositoryManager->_configuration;
  514. $dbc->query($query, $configuration->getProperty('database_index'));
  515. }
  516. }
  517. /**
  518. * Add an authoritative value
  519. *
  520. * WARNING: NOT in OSID
  521. *
  522. * @param string $valueString
  523. * @return void
  524. * @access public
  525. * @since 4/25/06
  526. */
  527. function addAuthoritativeValueAsString ( $valueString ) {
  528. $this->addAuthoritativeValue(
  529. $this->createValueObjectFromString($valueString));
  530. }
  531. /**
  532. * Answer the Primative object appropriate for this part, whose value is
  533. * represented by the input string.
  534. *
  535. * @param string $valueString
  536. * @return object
  537. * @access public
  538. * @since 4/27/06
  539. */
  540. function createValueObjectFromString ( $valueString ) {
  541. $dtm = Services::getService("DataTypeManager");
  542. $type =$this->getType();
  543. $class = $dtm->primitiveClassForType($type->getKeyword());
  544. eval('$valueObject = '.$class.'::fromString($valueString);');
  545. return $valueObject;
  546. }
  547. /**
  548. * Answer the Id of the repository from whence this PartStructure came.
  549. *
  550. * WARNING: NOT in OSID
  551. *
  552. * @return object Id
  553. * @access public
  554. * @since 6/8/06
  555. */
  556. function getRepositoryId () {
  557. return $this->_repositoryId;
  558. }
  559. /**
  560. * Load the authoritative value list
  561. *
  562. * WARNING: NOT in OSID
  563. *
  564. * @return void
  565. * @access private
  566. * @since 4/25/06
  567. */
  568. function _loadAuthoritativeValueStrings () {
  569. if (!isset($this->_authoritativeValueStrings)) {
  570. $this->_authoritativeValueStrings = array();
  571. $query = new SelectQuery;
  572. $query->addTable('dr_authoritative_values');
  573. $query->addColumn('value');
  574. $id =$this->getId();
  575. $query->addWhere("fk_partstructure = '".addslashes($id->getIdString())."'");
  576. $query->addWhere("fk_repository = '".addslashes($this->_repositoryId->getIdString())."'");
  577. $query->addOrderBy("value", ASCENDING);
  578. $dbc = Services::getService("DBHandler");
  579. $repositoryManager = Services::getService("Repository");
  580. $configuration =$repositoryManager->_configuration;
  581. $result =$dbc->query($query, $configuration->getProperty('database_index'));
  582. while ($result->hasMoreRows()) {
  583. $this->_authoritativeValueStrings[] = $result->field('value');
  584. $result->advanceRow();
  585. }
  586. $result->free();
  587. }
  588. }
  589. }

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