Source for file SimpleRecordPrinter.class.php

Documentation is available at SimpleRecordPrinter.class.php

  1. <?php
  2. /**
  3. * @package polyphony.datamanager_gui
  4. *
  5. * @copyright Copyright &copy; 2005, Middlebury College
  6. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  7. *
  8. * @version $Id: SimpleRecordPrinter.class.php,v 1.11 2007/09/19 14:04:43 adamfranco Exp $
  9. */
  10.  
  11. /**
  12. *
  13. *
  14. * @package polyphony.datamanager_gui
  15. *
  16. * @copyright Copyright &copy; 2005, Middlebury College
  17. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  18. *
  19. * @version $Id: SimpleRecordPrinter.class.php,v 1.11 2007/09/19 14:04:43 adamfranco Exp $
  20. */
  21. class SimpleRecordPrinter {
  22. /**
  23. * Prints out the specified record in a plain-text format.
  24. * @access public
  25. * @return string|void
  26. * @static
  27. */
  28. function printRecord($record, $html=true, $return=false)
  29. {
  30. if ($record->getFetchMode() == -1) {
  31. print "<b>Record not populated...</b><br />";
  32. return;
  33. }
  34. $fetchModeStrings = array(
  35. RECORD_NODATA=>"no_data",
  36. RECORD_CURRENT=>"current_data",
  37. RECORD_FULL=>"full_data"
  38. );
  39. $recordManager = Services::getService("RecordManager");
  40. $v = $record->isVersionControlled();
  41. $text = "";
  42. if ($html) $text .= "<pre>\n";
  43. if ($record->getID()) {
  44. $text .= "ID: ".$record->getID();
  45. $ids = $recordManager->getRecordSetIDsContaining($record);
  46. $text .= "; groups: ";
  47. if (count($ids)) $text .= implode(", ",$ids);
  48. else $text .= "none";
  49. $text .= "; ";
  50. }
  51. $text .= "type: ".$record->getSchemaID();
  52. $created =$record->getCreationDate();
  53. $text .= "; created: " . $created->asString();
  54. $text .= "; ".$fetchModeStrings[$record->getFetchMode()];
  55. // $text .= print_r($record->getFetchMode(), true);
  56. if ($v) $text .= "; vControl";
  57. $text .= "\n";
  58. $schema =$record->getSchema();
  59. $labels = $schema->getAllLabels();
  60. $noValue = array();
  61. foreach ($labels as $label) {
  62. if ($record->numValues($label, true)) {
  63. foreach ($record->getIndices($label, true) as $i) {
  64. $fieldID = $schema->getID() . "." . $label;
  65. $value =$record->getRecordFieldValue($fieldID,$i);
  66. if ($v) {
  67. foreach ($value->getVersionIDs() as $verID) {
  68. $version =$value->getVersion($verID);
  69. if (!$version->isActive()) continue;
  70. $text .= "\t";
  71. $text .= SimpleRecordPrinter::_doRecordFieldData($value, $version, $label, $i, true, $verID);
  72. $text .= "\n";
  73. }
  74. foreach ($value->getVersionIDs() as $verID) {
  75. $version =$value->getVersion($verID);
  76. if ($version->isActive()) continue;
  77. $text .= "\t -";
  78. $text .= SimpleRecordPrinter::_doRecordFieldData($value, $version, $label, $i, true, $verID);
  79. $text .= "\n";
  80. }
  81. } else {
  82. $text .= "\t";
  83. $version =$value->getActiveVersion();
  84. if (!$version) $version =$value->getNewestVersion();
  85. if (!$version) continue;
  86. $text .= SimpleRecordPrinter::_doRecordFieldData($value, $version, $label, $i);
  87. $text .= "\n";
  88. }
  89. }
  90. } else $noValue[] = $label;
  91. }
  92. if (count($noValue)) $text .= "no values for: ".implode(", ",$noValue) . "\n";
  93. if ($html) $text .= "</pre>\n";
  94. if ($return) return $text;
  95. else print $text;
  96. }
  97. /**
  98. * Prints out a single {@link RecordFieldData} line.
  99. * @access public
  100. * @return string
  101. */
  102. function _doRecordFieldData($value, $version, $label, $i, $v = false, $vID = null)
  103. {
  104. $text = '';
  105. $primitive =$version->getPrimitive();
  106. $flags = array();
  107. if (!$version->isActive()) $flags[] = "d";
  108. if ($version->willPrune()) $flags[] = "p";
  109. if ($version->_update) $flags[] = "u";
  110. if ($v && $version->isActive()) $flags[] = "A";
  111. if (!count($flags)) $flags[] = "-";
  112. $text .= "(".implode("",$flags).") ";
  113. $text .= "\t";
  114. $text .= $label."[$i] = ";
  115. $text .= $primitive->asString();
  116. if ($v) {
  117. $date =$version->getDate();
  118. $text .= "\t\t(".$vID." - ".$date->asString().")";
  119. }
  120. return $text;
  121. }
  122. }

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