Source for file Record.class.php

Documentation is available at Record.class.php

  1. <?php
  2.  
  3. require_once HARMONI."dataManager/record/RecordField.class.php";
  4.  
  5. /**
  6. * @package harmoni.datamanager
  7. * @constant int NEW_VALUE Used when setting the value of a new index within a field.
  8. */
  9. define("NEW_VALUE",-1);
  10. /**
  11. * @package harmoni.datamanager
  12. * @constant int RECORD_NODATA Specifies that only the record descriptor has been fetched - no data.
  13. */
  14. define("RECORD_NODATA",0);
  15. /**
  16. * @package harmoni.datamanager
  17. * @constant int RECORD_CURRENT Specifies that all active values for fields have been fetched.
  18. */
  19. define("RECORD_CURRENT",2);
  20. /**
  21. * @package harmoni.datamanager
  22. * @constant int RECORD_FULL Specifies that all values active and inactive (all versions) have been fetched.
  23. */
  24. define("RECORD_FULL",4);
  25.  
  26.  
  27. /**
  28. * A Record is a set of data matching a certain {@link Schema}. The Record can be fetched from the database in a number of
  29. * ways, which can be changed at runtime. See the RECORD_* constants.
  30. *
  31. * @package harmoni.datamanager
  32. *
  33. * @copyright Copyright &copy; 2005, Middlebury College
  34. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  35. *
  36. * @version $Id: Record.class.php,v 1.39 2007/09/04 20:25:31 adamfranco Exp $
  37. */
  38. class Record {
  39. var $_myID;
  40. var $_delete;
  41. var $_schema;
  42. var $_versionControlled;
  43. var $_fields;
  44. var $_creationDate;
  45. var $_dateFromDB = false;
  46. var $_fetchMode;
  47. var $_fetchedValueIDs;
  48.  
  49. var $_prune;
  50. var $_pruneConstraint;
  51. /**
  52. * Constructor
  53. * @param mixed $schema Either a {@link Schema} object or a string ID of the schema to use.
  54. * @param optional boolean $verControl If set to TRUE this Record will use version-control.
  55. * @param optional int $fetchMode USED INTERNALLY
  56. */
  57. function Record($schema, $verControl=false, $fetchMode = RECORD_FULL) {
  58. ArgumentValidator::validate($verControl, BooleanValidatorRule::getRule());
  59. // ArgumentValidator::validate($schema, ExtendsValidatorRule::getRule("Schema"));
  60. if (is_object($schema)) {
  61. $schemaID = $schema->getID();
  62. } else $schemaID = $schema; // it's a string (we hope)
  63. $schemaManager = Services::getService("SchemaManager");
  64. $schema =$schemaManager->getSchemaByID($schemaID);
  65. $schema->load();
  66. $this->_schema =$schema;
  67. $this->_fields = array();
  68. $this->_versionControlled = $verControl;
  69. $this->_fetchMode = $fetchMode;
  70. $this->_fetchedValueIDs = array();
  71. $this->_creationDate = DateAndTime::now();
  72. $this->_myID = null;
  73. $this->_delete = false;
  74. // set up the individual fields
  75. foreach ($schema->getAllIDs(true) as $label) {
  76. $def =$schema->getField($label);
  77. $this->_fields[$label] = new RecordField($def, $this);
  78. unset($def);
  79. }
  80. $this->_idManager = Services::getService("Id");
  81. }
  82. /**
  83. * Returns this Record's {@link Schema}
  84. * @return ref object
  85. */
  86. function getSchema() {
  87. return $this->_schema;
  88. }
  89. /**
  90. * Returns the indices (indexes) of each value for the given field. Can then be retrieved with any getValue-type function.
  91. * @access public
  92. * @param string $label
  93. * @param optional boolean $includeInactive Includes the inactive values for 'label'. Default: false
  94. * @return array An array of integers
  95. */
  96. function getIndices($label, $includeInactive = false)
  97. {
  98. $this->_checkLabel($label);
  99. $id = $this->_getFieldID($label);
  100. return $this->_fields[$id]->getIndices($includeInactive);
  101. }
  102. /**
  103. * Returns the indices (indexes) of each value for the given field. Can then be retrieved with any getValue-type function.
  104. * @access public
  105. * @param string $label
  106. * @return array An array of integers
  107. * @deprecated use getIndices().
  108. */
  109. function getActiveIndices($label)
  110. {
  111. return $this->getIndices($label);
  112. }
  113. /**
  114. * INTERNAL USE ONLY: Sets the fetch mode.
  115. * @access public
  116. * @return void
  117. */
  118. function setFetchMode($mode)
  119. {
  120. $this->_fetchMode = $mode;
  121. }
  122. /**
  123. * Returns the Schema ID associated with this Record.
  124. * @return string
  125. */
  126. function getSchemaID() {
  127. return $this->_schema->getID();
  128. }
  129. /**
  130. * Returns this Record's ID.
  131. * @return int
  132. */
  133. function getID() {
  134. return $this->_myID;
  135. }
  136. function _checkLabel($label) {
  137. if (!$this->_schema->fieldExistsByLabel($label)) {
  138. throwError(new FieldNotFoundError($label,$this->_schema->getID()));
  139. return false;
  140. }
  141. // If the schema has changed since we were created, ensure that we
  142. // have a valid field object
  143. $id = $this->_getFieldID($label);
  144. if (!isset($this->_fields[$id])) {
  145. $def =$this->_schema->getField($this->_schema->getFieldIDFromLabel($label));
  146. $this->_fields[$id] = new RecordField($def, $this);
  147. }
  148. return true;
  149. }
  150. /**
  151. * Re-indexes all the values in a multi-valued field so that they increment by 1 started at 0.
  152. * @access public
  153. * @param string $label The field's label.
  154. * @return void
  155. */
  156. function reIndex($label)
  157. {
  158. $this->_checkLabel($label);
  159. $this->_fields[$this->_getFieldID($label)]->reIndex();
  160. }
  161. /**
  162. * Returns the full ID of a field, given a label.
  163. * @return string
  164. * @access private
  165. * @param string $label
  166. */
  167. function _getFieldID($label) {
  168. return $this->_schema->getFieldIDFromLabel($label);
  169. }
  170. /**
  171. * Returns a field's label given its ID.
  172. * @return string
  173. * @access private
  174. * @param string $id
  175. */
  176. function _getFieldLabel($id) {
  177. return $this->_schema->getFieldLabelFromID($id);
  178. }
  179. /**
  180. * Returns the active {@link SObject} value object for $index under $label.
  181. * @return ref object
  182. * @param string $label
  183. * @param optional int $index default=0.
  184. */
  185. function getValue($label, $index=0) {
  186. $this->_checkLabel($label);
  187. $id = $this->_getFieldID($label);
  188. $versions =$this->_fields[$id]->getRecordFieldValue($index);
  189. if ($versions->hasActiveValue())
  190. $ver =$versions->getActiveVersion();
  191. else
  192. $ver =$versions->getNewestVersion();
  193. return $ver->getPrimitive();
  194. }
  195. /**
  196. * Returns the active value for a label/index by calling $function on the {@link SObject} that is returned.
  197. * @param string $function The function to call.
  198. * @param string $label The label.
  199. * @param optional int $index defaults to 0
  200. * @access public
  201. * @return ref mixed
  202. */
  203. function getValueByFunction($function, $label, $index=0)
  204. {
  205. $prim =$this->getCurrentValue($label, $index);
  206. return $prim->$function();
  207. }
  208. /**
  209. * Returns a string value for $index under $label. What is returned depends on the DataType.
  210. * @param string $label
  211. * @param optional int $index default=0.
  212. */
  213. function getStringValue($label, $index=0) {
  214. $actVer =$this->getCurrentValue($label, $index);
  215. if (!$actVer) return null;
  216. return $actVer->asString();
  217. }
  218. /**
  219. * Returns an array of all the string values for the passed label.
  220. * @param string $label
  221. * @access public
  222. * @return array
  223. */
  224. function getStringValues($label) {
  225. $ar = array();
  226. foreach($this->getIndices($label) as $index) {
  227. if (!$this->deleted($label, $index)) $ar[] = $this->getStringValue($label, $index);
  228. }
  229. return $ar;
  230. }
  231. /**
  232. * Returns an array of {@link RecordFieldData} objects corresponding to the different
  233. * versions available for a given $label/$index - useful for version-controlled Records.
  234. * @access public
  235. * @param string $label
  236. * @param optional integer $index
  237. * @return ref array An array keyed by version ID.
  238. */
  239. function getVersions($label, $index=0) {
  240. $this->_checkLabel($label);
  241. $id = $this->_getFieldID($label);
  242. $ids = $this->_fields[$id]->getVersionIDs($index);
  243. $array = array();
  244. foreach ($ids as $verID) {
  245. $array[$verID] =$this->_fields[$id]->getVersion($verID);
  246. }
  247. return $array;
  248. }
  249. /**
  250. * Returns all the {@link RecordFieldValue}s objects associated with a field by id.
  251. * @param string $id The field's unique ID
  252. * @return ref array
  253. * @access public
  254. */
  255. function getRecordFieldValues($id) {
  256. $this->_checkLabel($this->_getFieldLabel($id));
  257. $array = array();
  258. foreach ($this->getIndices($this->_getFieldLabel($id)) as $index) {
  259. $array[] =$this->_fields[$id]->getRecordFieldValue($index);
  260. }
  261. return $array;
  262. }
  263. /**
  264. * Returns the {@link RecordFieldValue} associated with a field by id.
  265. * @param string $id The field's unique ID
  266. * @param optional integer $index
  267. * @return ref object
  268. * @access public
  269. */
  270. function getRecordFieldValue($id, $index=0) {
  271. $this->_checkLabel($this->_getFieldLabel($id));
  272. return $this->_fields[$id]->getRecordFieldValue($index);
  273. }
  274. /**
  275. * INTERNAL USE ONLY: Creates a number of {@link RecordFieldValue} objects based on an array of database rows.
  276. * @return bool
  277. * @param ref array $arrayOfRows
  278. */
  279. function populate( $arrayOfRows ) {
  280. // ok, we're going to be passed an array of rows that corresonds to
  281. // our label[index] = valueVersion[n] setup.
  282. // that means we have to separate out the rows that have to do with each
  283. // label, and hand each package to a FieldValues object.
  284.  
  285. foreach (array_keys($arrayOfRows) as $key) {
  286. $this->takeRow($arrayOfRows[$key]);
  287. }
  288. }
  289. /**
  290. * INTERNAL USE ONLY: Takes one row from a database and populates our objects with it.
  291. * @param ref array $row
  292. * @return void
  293. */
  294. function takeRow( $row ) {
  295. // see if we can't get our ID from the row
  296. if (!$this->_myID && $row['record_id'])
  297. $this->_myID = $row['record_id'];
  298. else if ($row['record_id'] != $this->_myID) {
  299. throwError( new Error("Can not take database row because it does not seem to correspond with our
  300. Record ID.", "Record",true));
  301. }
  302. // let's check if we have our creation date set yet.
  303. if (!$this->_dateFromDB) {
  304. $dbHandler= Services::getService("DatabaseManager");
  305. $this->_creationDate =$dbHandler->fromDBDate($row["record_created"], DATAMANAGER_DBID);
  306. $this->_dateFromDB = true;
  307. }
  308. // if this is an empty Record, we're going to get a row with NULL values for all
  309. // columns not in the "dm_record_field" table. so, let's check for that and return if it's the case.
  310. if (!$row['record_field_id']) return;
  311. // now, we need to check if we've already accounted for this specific value from the database
  312. if (in_array($row['record_field_id'], $this->_fetchedValueIDs)) return;
  313. $fieldID = $row['schema_field_id'];
  314. $label = $this->_getFieldLabel($fieldID);
  315.  
  316. if (!isset($this->_fields[$fieldID])) {
  317. throwError( new Error("Could not populate Record with label '$label' because it doesn't
  318. seem to be defined in the Schema.","record",true));
  319. }
  320. $this->_fields[$fieldID]->takeRow($row);
  321. $this->_fetchedValueIDs[] = $row['record_field_id'];
  322. }
  323. /**
  324. * Returns the {@link DateAndTime} object specifying when this Record was created.
  325. * @access public
  326. * @return ref object
  327. */
  328. function getCreationDate()
  329. {
  330. return $this->_creationDate;
  331. }
  332. /**
  333. * Returns the number of values we have set for $label.
  334. * @return int
  335. * @param string $label
  336. * @param optional boolean $includeInactive If TRUE will include inactive values as well.
  337. */
  338. function numValues($label, $includeInactive = false) {
  339. $this->_checkLabel($label);
  340. if (!isset($this->_fields[$this->_getFieldID($label)]))
  341. return 0;
  342. return $this->_fields[$this->_getFieldID($label)]->numValues($includeInactive);
  343. }
  344. /**
  345. * Returns TRUE if this DataSet was created with Version Control.
  346. * @return bool
  347. */
  348. function isVersionControlled() {
  349. return $this->_versionControlled;
  350. }
  351. /**
  352. * Returns if this Record is about to be deleted or not.
  353. * @return bool
  354. * @access public
  355. */
  356. function isActive() {
  357. return !$this->_delete;
  358. }
  359.  
  360. /**
  361. * De-activates the value under $label[$index].
  362. * @param string $label The field label to delete.
  363. * @param optional int $index The index (for multi-value fields) to delete.
  364. * @access public
  365. * @return void
  366. */
  367. function deleteValue($label, $index=0)
  368. {
  369. $this->_checkLabel($label);
  370. $this->_fields[$this->_getFieldID($label)]->deleteValue($index);
  371. }
  372. /**
  373. * Re-activates the value under $label[$index].
  374. * @param string $label The field label to un-delete.
  375. * @param optional int $index The index (for multi-value fields) to un-delete.
  376. * @access public
  377. * @return void
  378. */
  379. function undeleteValue($label, $index=0)
  380. {
  381. $this->_checkLabel($label);
  382. $this->_fields[$this->_getFieldID($label)]->undeleteValue($index);
  383. }
  384. /**
  385. * Returns true if the given value has been deleted.
  386. * @param string $label the field label to check.
  387. * @param optional int $index The index (defaults to 0) to check.
  388. * @access public
  389. * @return bool
  390. */
  391. function isValueDeleted($label, $index = 0)
  392. {
  393. $this->_checkLabel($label);
  394. return $this->_fields[$this->_getFieldID($label)]->isIndexDeleted($index);
  395. }
  396. /**
  397. * Sets the value of $index under $label to $obj where $obj is an {@link SObject}.
  398. * @return bool
  399. * @param string $label
  400. * @param ref object $obj
  401. * @param optional int $index default=0
  402. */
  403. function setValue($label, $obj, $index=0) {
  404. $this->_checkLabel($label);
  405. $id = $this->_getFieldID($label);
  406. ArgumentValidator::validate($this->_fields[$id],
  407. ExtendsValidatorRule::getRule("RecordField"));
  408. if ($index == NEW_VALUE) {
  409. return $this->_fields[$id]->addValueFromPrimitive($obj);
  410. }
  411. return $this->_fields[$id]->setValueFromPrimitive($index, $obj);
  412. }
  413. /**
  414. * Commits (either inserts or updates) the data for this Record into the database.
  415. * @param boolean optional $ignoreMandatory If true, doesn't fail if mandatory
  416. * fields don't have values.
  417. * @return bool
  418. */
  419. function commit($ignoreMandatory=false) {
  420. // Ensure that we have fields for all labels, incase
  421. // the schema has changed since we were loaded.
  422. foreach ($this->_schema->getAllLabels() as $label)
  423. $this->_checkLabel($label);
  424. // Get the DBHandler
  425. $dbHandler = Services::getService("DatabaseManager");
  426. // the first thing we're gonna do is check to make sure that all our required fields
  427. // have at least one value.
  428. if (!$this->_delete) {
  429. foreach ($this->_schema->getAllIDs() as $id) {
  430. $fieldDef =$this->_schema->getField($id);
  431. if ($fieldDef->isRequired() && ($this->_fields[$id]->numValues(true) == 0 ||
  432. $this->_fields[$id]->numValues() == 0) && !$ignoreMandatory) {
  433. throwError(new Error("Could not commit Record to database because the required field '$id' does
  434. not have any values!","Record",true));
  435. return false;
  436. }
  437. }
  438. if ($this->_myID) {
  439. // we're already in the database
  440. $query = new UpdateQuery();
  441. $query->setTable("dm_record");
  442. $query->setColumns(array("ver_control"));
  443. $query->setValues(array(
  444. ($this->_versionControlled)?1:0
  445. ));
  446. $query->setWhere("id='".addslashes($this->_myID)."'");
  447. } else {
  448. // we'll have to make a new entry
  449. $schemaManager = Services::getService("SchemaManager");
  450. $newID =$this->_idManager->createId();
  451. $this->_myID = $newID->getIdString();
  452. $query = new InsertQuery();
  453. $query->setTable("dm_record");
  454. $query->setColumns(array("id","fk_schema","created","ver_control"));
  455. $query->addRowOfValues(array(
  456. "'".addslashes($this->_myID)."'",
  457. "'".addslashes($this->_schema->getID())."'",
  458. $dbHandler->toDBDate($this->_creationDate,DATAMANAGER_DBID),
  459. ($this->_versionControlled)?1:0
  460. ));
  461. }
  462. // execute the query;
  463. $result =$dbHandler->query($query,DATAMANAGER_DBID);
  464. if (!$result) {
  465. throwError( new UnknownDBError("Record") );
  466. return false;
  467. }
  468. }
  469. // now let's cycle through our FieldValues and commit them
  470. foreach ($this->_schema->getAllIDs() as $id) {
  471. $this->_fields[$id]->commit();
  472. }
  473. if ($this->_prune) {
  474. $constraint =$this->_pruneConstraint;
  475. // check if we have to delete any dataset tags based on our constraints
  476. $constraint->checkTags($this);
  477. $tagMgr = Services::getService("RecordTagManager");
  478. // if we are no good any more, delete ourselves completely
  479. if ($this->_delete) {
  480. // now, remove any tags from the DB that have to do with us, since they will no longer
  481. // be valid.
  482. $tagMgr->pruneTags($this);
  483. $query = new DeleteQuery();
  484. $query->setTable("dm_record");
  485. $query->setWhere("id='".addslashes($this->getID())."'");
  486. $dbHandler->query($query, DATAMANAGER_DBID);
  487.  
  488. $query = new DeleteQuery();
  489. $query->setTable("dm_record_set");
  490. $query->setWhere("fk_record='".addslashes($this->getID())."'");
  491.  
  492. $dbHandler->query($query, DATAMANAGER_DBID);
  493. } else {
  494. // if we're pruning but not deleting the whole shebang, let's
  495. // make sure that there are no tags in the database with no
  496. // mappings whatsoever.
  497. $tagMgr->checkForEmptyTags($this);
  498. }
  499. }
  500. return true;
  501. }
  502. /**
  503. * INTERNAL USE ONLY: Returns an array of field IDs that have already been fetched & populated.
  504. * @access public
  505. * @return array
  506. */
  507. function getFetchedFieldIDs()
  508. {
  509. return $this->_fetchedValueIDs;
  510. }
  511. /**
  512. * Uses the {@link RecordTagManager} service to add a tag of the current state (in the DB) of this Record.
  513. * @return void
  514. * @param optional object $date An optional {@link DateAndTime} to specify the date that should be attached to the tag instead of the current date/time.
  515. */
  516. function tag($date=null) {
  517. $this->makeCurrent();
  518. $tagMgr = Services::getService("RecordTagManager");
  519. $tagMgr->tagRecord($this, $date);
  520. }
  521. /**
  522. * Calls both commit() and tag().
  523. * @return void
  524. * @param optional object $date An optional {@link DateAndTime} object for tagging. If specified, it will use $date instead of the current date and time.
  525. */
  526. function commitAndTag($date=null) {
  527. $this->commit();
  528. $this->tag($date);
  529. }
  530. /**
  531. * INTERNAL USE ONLY: Returns our current fetch mode.
  532. * @access public
  533. * @return int
  534. */
  535. function getFetchMode()
  536. {
  537. return $this->_fetchMode;
  538. }
  539. /**
  540. * Creates an exact (specific to the data) copy of the Record, that can then be inserted into
  541. * the DB as a new set with the same data.
  542. * @return ref object A new {@link Record} object.
  543. */
  544. function replicate() {
  545. $this->makeFull();
  546. $newSet = new Record($this->_schema, $this->_versionControlled);
  547. // @todo
  548. foreach ($this->_schema->getAllIDs() as $id) {
  549. $label = $this->_getFieldLabel($id);
  550. foreach($this->getIndices($label, true) as $i) {
  551. $newSet->_fields[$id]->_values[$i] =$this->_fields[$id]->_values[$i]->replicate($newSet->_fields[$id]);
  552. $newSet->_fields[$id]->_numValues++;
  553. }
  554. }
  555. return $newSet;
  556. }
  557. /**
  558. * Goes through all the old versions of values and actually DELETES them from the database.
  559. * @param ref object $versionConstraint A {@link VersionConstraint) on which to base our pruning.}
  560. * @return void
  561. */
  562. function prune($versionConstraint) {
  563. $this->makeFull();
  564. $this->_pruneConstraint =$versionConstraint;
  565. $this->_prune=true;
  566. // just step through each FieldValues object and call prune()
  567. foreach ($this->_schema->getAllIDs(true) as $id) {
  568. $this->_fields[$id]->prune($versionConstraint);
  569. }
  570. }
  571. /**
  572. * Changes this Records active flag.
  573. * @param boolean $bool The new value.
  574. * @return void
  575. * @deprecated does nothing
  576. */
  577. function setActiveFlag($bool) {
  578. // does nothing
  579. }
  580. /**
  581. * Takes a tag object and activates the appropriate versions of values based on the tag mappings.
  582. * @return bool
  583. * @param ref object $tag A {@link RecordTag} object.
  584. */
  585. function activateTag($tag) {
  586. // check to make sure the tag is affiliated with us
  587. if ($this->getID() != $tag->getRecordID()) {
  588. throwError (new Error("Can not activate tag because it is not affiliated with this Record.","Record",true));
  589. return false;
  590. }
  591. // load the mapping data for the tag
  592. $tag->load();
  593. $this->makeFull();
  594. foreach ($this->_schema->getAllIDs(true) as $id) {
  595. // if the tag doesn't have any mappings for $label, skip it
  596. // if (!$tag->haveMappings($label)) continue;
  597. $label = $this->_getFieldLabel($id);
  598. foreach ($this->getIndices($label, true) as $i) {
  599. $newVerID = $tag->getMapping($id, $i);
  600. // go through each version and deactivate all versions unless they are active and $verID
  601. $vers =$this->getVersions($label, $i);
  602. foreach (array_keys($vers) as $verID) {
  603. $verObj =$vers[$verID];
  604. // if it's our active vers in the RecordTag, activate it
  605. if ($verID == $newVerID) {
  606. if (!$verObj->isActive()) {
  607. $verObj->setActiveFlag(true);
  608. $verObj->update();
  609. }
  610. }
  611. // if it's not, deactivate it
  612. else {
  613. if ($verObj->isActive()) {
  614. $verObj->setActiveFlag(false);
  615. $verObj->update();
  616. }
  617. }
  618. }
  619. }
  620. }
  621. return true;
  622. }
  623. /**
  624. * Returns an array of hashed values for all of our fields. If a field allows multiple values, we return an array of those values instead of just the string value.
  625. * @access public
  626. * @return array format: array = ("single"=>value, "multiple"=>array(value1,value2,...));
  627. */
  628. function getValuesArray()
  629. {
  630. $this->makeCurrent();
  631. $array = array();
  632. $array["__id"] = $this->getID();
  633. $ids = $this->_schema->getAllIDs();
  634. foreach ($ids as $id) {
  635. $field = $this->_fields[$id]->getSchemaField();
  636. $label = $this->_getFieldLabel($id);
  637. if ($field->getMultFlag()) {
  638. $array[$label] = array();
  639. foreach ($this->getIndices($label) as $i) {
  640. $value =$this->getValue($label,$i);
  641. $array[$label][] = $value->asString();
  642. }
  643. } else {
  644. if ($this->numValues($label)) {
  645. $value =$this->getValue($label);
  646. $array[$label] = $value->asString();
  647. }
  648. }
  649. }
  650. return $array;
  651. }
  652. /**
  653. * INTERNAL USE ONLY: makes sure that our representation of the data includes ALL values, active and inactive.
  654. * @access public
  655. * @return void
  656. */
  657. function makeFull()
  658. {
  659. // we will get the RecordManager and ask it to re-fetch our values. We'll also have it exclude those values
  660. // that we already have fetched.
  661. if ($this->getFetchMode() >= RECORD_FULL) return;
  662. // print "<b>makeFull()</b><br />";
  663. // printDebugBacktrace(debug_backtrace());
  664. if (!$this->getID()) return;
  665. $recordManager = Services::getService("RecordManager");
  666. $recordManager->fetchRecord($this->getID(), RECORD_FULL);
  667. }
  668. /**
  669. * INTERNAL USE ONLY: Makes sure that our representation of the data includes all current values.
  670. * @access public
  671. * @return void
  672. */
  673. function makeCurrent()
  674. {
  675. // we will get the RecordManager to fetch our fields from the database
  676. if ($this->getFetchMode() >= RECORD_CURRENT) return;
  677.  
  678. // print "<b>makeCurrent()</b><br />";
  679. // printDebugBacktrace(debug_backtrace());
  680. if (!$this->getID()) return;
  681. $recordManager = Services::getService("RecordManager");
  682. $recordManager->fetchRecord($this->getID(), RECORD_CURRENT);
  683. }
  684. /**
  685. * Deletes the record entirely from the database upon calling commit().
  686. * @access public
  687. * @return void
  688. */
  689. function delete()
  690. {
  691. $this->_delete = true;
  692. $this->makeFull();
  693. // also remove all of our data
  694. $this->prune(new PruneAllVersionConstraint());
  695. }
  696.  
  697. }
  698.  
  699. /**
  700. *@package harmoni.datamanager
  701. */
  702. class FieldNotFoundError extends Error {
  703. function FieldNotFoundError($label,$type) {
  704. parent::Error("The field labeled '$label' was not found in schema '$type'.","Record",true);
  705. }
  706. }
  707.  
  708. /**
  709. * @package harmoni.datamanager
  710. */
  711. class ValueIndexNotFoundError extends Error {
  712. function ValueIndexNotFoundError($label,$id,$index) {
  713. parent::Error("The value index $index was not found for field '$label' in Record ID $id.","Record",true);
  714. }
  715. }
  716.  
  717. ?>

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