Source for file XMLAssetExporter.class.php

Documentation is available at XMLAssetExporter.class.php

  1. <?php
  2. /**
  3. * @since 10/17/05
  4. * @package polyphony.exporter
  5. *
  6. * @copyright Copyright &copy; 2005, Middlebury College
  7. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  8. *
  9. * @version $Id: XMLAssetExporter.class.php,v 1.11 2007/09/19 14:04:44 adamfranco Exp $
  10. */
  11.  
  12. require_once(POLYPHONY."/main/library/Exporter/XMLExporter.class.php");
  13. require_once(POLYPHONY."/main/library/Exporter/XMLRecordExporter.class.php");
  14. require_once(POLYPHONY."/main/library/Exporter/XMLFileRecordExporter.class.php");
  15. require_once(POLYPHONY."/main/library/Exporter/XMLRemoteFileRecordExporter.class.php");
  16.  
  17. /**
  18. * Exports into XML for use with the XML Importer
  19. *
  20. * @since 10/17/05
  21. * @package polyphony.exporter
  22. *
  23. * @copyright Copyright &copy; 2005, Middlebury College
  24. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  25. *
  26. * @version $Id: XMLAssetExporter.class.php,v 1.11 2007/09/19 14:04:44 adamfranco Exp $
  27. */
  28. class XMLAssetExporter extends XMLExporter {
  29. /**
  30. * Constructor
  31. *
  32. * @access public
  33. * @since 10/17/05
  34. */
  35. function XMLAssetExporter () {
  36. parent::XMLExporter();
  37. }
  38.  
  39. /**
  40. * Creates the child lists
  41. *
  42. * @access public
  43. * @since 10/31/05
  44. */
  45. function setupSelf() {
  46. $this->_childExporterList = array("XMLRecordExporter",
  47. "XMLAssetExporter");
  48. $this->_childElementList = array("records", "assets");
  49. }
  50.  
  51. /**
  52. * Constructor for starting an export
  53. *
  54. * @param string
  55. * @param string
  56. * @access public
  57. * @since 10/31/05
  58. */
  59. function withCompression($compression, $class = 'XMLAssetExporter') {
  60. return parent::withCompression($compression, $class);
  61. }
  62.  
  63.  
  64. /*
  65. * Constructor for adding repository to an export
  66. *
  67. * @param handle $xmlFile filehandle for the xml file
  68. * @param string $fileDir the directory for the files to be written
  69. * @access public
  70. * @since 10/31/05
  71. */
  72. function withDir($xmlFile, $fileDir) {
  73. $exporter = new XMLAssetExporter();
  74. $exporter->_xml =$xmlFile;
  75. $exporter->_fileDir = $fileDir;
  76. return $exporter;
  77. }
  78.  
  79. /**
  80. * Exporter of Asset things
  81. *
  82. * @param object HarmoniAsset
  83. * @access public
  84. * @since 10/17/05
  85. */
  86. function export ($asset) {
  87. $this->_object =$asset;
  88. $this->_myId =$this->_object->getId();
  89. $type =$this->_object->getAssetType();
  90.  
  91. fwrite($this->_xml,
  92. "\t<asset ".
  93. "id=\"".$this->_myId->getIdString()."\">\n".
  94. "\t\t<name>".$this->_object->getDisplayName()."</name>\n".
  95. "\t\t<description><![CDATA[".$this->_object->getDescription()."]]></description>\n".
  96. "\t\t<type>\n\t\t\t<domain>".$type->getDomain()."</domain>\n".
  97. "\t\t\t<authority>".$type->getAuthority()."</authority>\n".
  98. "\t\t\t<keyword>".$type->getKeyword()."</keyword>\n");
  99. if ($type->getDescription() != "")
  100. fwrite($this->_xml,
  101. "\t\t\t<description><![CDATA[".$type->getDescription()."]]></description>\n");
  102. fwrite($this->_xml,
  103. "\t\t</type>\n");
  104.  
  105. //================== DATES GO HERE ===================//
  106.  
  107. foreach ($this->_childElementList as $child) {
  108. $exportFn = "export".ucfirst($child);
  109. if (method_exists($this, $exportFn))
  110. $this->$exportFn();
  111. }
  112. fwrite($this->_xml, "\t</asset>\n");
  113. }
  114. /**
  115. * Exporter of a list of assets, for selective asset exporting
  116. *
  117. * @param array $idList a list of asset id's
  118. * @return string $file is the directory where all the data is written
  119. * @access public
  120. * @since 12/13/05
  121. */
  122. function exportList ($idList) {
  123. $harmoni = Harmoni::Instance();
  124. $repositoryManager = Services::getService("Repository");
  125. $listOfRS = array();
  126. $idListRS = array();
  127. $this->_fileDir = $this->_tmpDir;
  128. // prepare all the things we need to export
  129. foreach ($idList as $assetId) {
  130. $asset =$repositoryManager->getAsset($assetId);
  131.  
  132. // build the list of recordstructures
  133. $this->buildRSList($asset, $idListRS, $listOfRS);
  134. }
  135.  
  136. // get the xml file ready
  137. $this->setupXML($this->_fileDir);
  138. fwrite($this->_xml, "<repository>\n");
  139.  
  140. // export the necessary recordstructures
  141. foreach ($listOfRS as $rS) {
  142. $exporter = new XMLRecordStructureExporter($this->_xml);
  143. $exporter->export($rS);
  144. unset($exporter);
  145. }
  146. // clean up after the recordstructures
  147. unset($listOfRS, $idListRS);
  148. // export the assets
  149. $this->_status = new StatusStars(_("Exporting all Assets in the Collection"));
  150. $this->_status->initializeStatistics(count($idList), 100);
  151. foreach ($idList as $assetId) {
  152. $asset =$repositoryManager->getAsset($assetId);
  153. $this->export($asset);
  154. $this->_status->updateStatistics();
  155. }
  156. fwrite($this->_xml, "</repository>");
  157. fclose($this->_xml);
  158. return $this->_tmpDir;
  159. }
  160.  
  161. /**
  162. * Builds a list of the necessary record structures to ex/import the asset
  163. *
  164. * @param object HarmoniAsset $asset an asset that is being exporter
  165. * @param array $listOfRS an array of all the necessary RecordStructures1
  166. * @access public
  167. * @since 12/13/05
  168. */
  169. function buildRSList ($asset, $idListRS, $listOfRS) {
  170. $iterator =$asset->getRecordStructures();
  171. // go through RS's find those with different Id's
  172. while ($iterator->hasNext()) {
  173. $rS =$iterator->next();
  174. $id =$rS->getId();
  175. $idString = $id->getIdString();
  176. // new recordstructure add it to the list
  177. if (!in_array($idString, $idListRS)) {
  178. $idListRS[] = $idString;
  179. $listOfRS[] =$rS;
  180. }
  181. }
  182. // recurse through the children
  183. $children =$asset->getAssets();
  184. while($children->hasNext()) {
  185. $child =$children->next();
  186. $this->buildRSList($child, $idListRS, $listOfRS);
  187. }
  188. }
  189.  
  190. /**
  191. * Exporter of records
  192. *
  193. * Adds record elements to the xml, which contain the necessary
  194. * information to create the same records.
  195. *
  196. * @access public
  197. * @since 10/17/05
  198. */
  199. function exportRecords () {
  200. $idManager = Services::getService("Id");
  201. $children =$this->_object->getRecords();
  202. while ($children->hasNext()) {
  203. $child =$children->next();
  204. $rS =$child->getRecordStructure();
  205. if ($rS->getId() == $idManager->getId("FILE")) {
  206. $exporter = new XMLFileRecordExporter($this->_xml,
  207. $this->_fileDir);
  208. } else if ($rS->getId() == $idManager->getId("REMOTE_FILE")) {
  209. $exporter = new XMLRemoteFileRecordExporter($this->_xml,
  210. $this->_fileDir);
  211. } else
  212. $exporter = new XMLRecordExporter($this->_xml);
  213. $exporter->export($child); // ????
  214.  
  215. unset($exporter);
  216. }
  217. }
  218.  
  219. /**
  220. * Exporter of child Assets
  221. *
  222. * @access public
  223. * @since 10/17/05
  224. */
  225. function exportAssets () {
  226. $children =$this->_object->getAssets();
  227.  
  228. while ($children->hasNext()) {
  229. $child =$children->next();
  230.  
  231. $exporter = XMLAssetExporter::withDir($this->_xml,
  232. $this->_fileDir);
  233.  
  234. $exporter->export($child);
  235. unset($exporter);
  236. }
  237. }
  238. }
  239. ?>

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