PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/classes/export.php

https://github.com/tbuljevic/bccie
PHP | 208 lines | 144 code | 36 blank | 28 comment | 25 complexity | b61e5af208b1594b1b64a476406c5b85 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /**
  3. * File containing the Export functions file.
  4. *
  5. * @copyright Copyright (C) 1999 - 2012 Brookins Consulting. All rights reserved.
  6. * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2 (or any later version)
  7. * @version //autogentag//
  8. * @package bccie
  9. */
  10. include_once( 'kernel/classes/ezcontentclass.php' );
  11. include_once( 'kernel/classes/ezinformationcollection.php' );
  12. include_once( 'lib/ezutils/classes/ezhttptool.php' );
  13. include_once( 'lib/ezutils/classes/ezexecution.php' );
  14. include_once( 'extension/bccie/modules/bccie/parser.php' );
  15. /*
  16. Export Collections
  17. */
  18. function exportCollections( $collections, $dir='var/export', $format='csv', $separator=',', $days=false, $remove=false, $debug=false )
  19. {
  20. foreach ( $collections as $collection_id )
  21. {
  22. if ( $debug )
  23. {
  24. print_r("Object Collection ID For Export: $item" ."\n");
  25. }
  26. if ( is_numeric( $collection_id ) )
  27. {
  28. exportCollection( $collection_id, $dir, $format, $separator, $days, $debug );
  29. }
  30. if ( $debug )
  31. {
  32. print_r("Object Collections Export Finished!\n");
  33. }
  34. }
  35. }
  36. /*
  37. Exports Object Collection to File
  38. */
  39. function exportCollection( $objectID=false, $dir='var/export', $format='csv', $separator=',', $days=false, $debug=false )
  40. {
  41. $ret = false;
  42. $object = false;
  43. // Settings
  44. $ini = eZINI::instance( "cie.ini" );
  45. $excludeAttributeID = $ini->variable( "CieSettings", "ExcludeAttributeID" );
  46. if( is_numeric( $objectID ) )
  47. {
  48. $object =& eZContentObject::fetch( $objectID );
  49. $classID = $object->attribute('contentclass_id');
  50. }
  51. // eZDebug::writeDebug( $object );
  52. if( is_numeric( $classID ) )
  53. {
  54. $class =& eZContentClass::fetch( $classID );
  55. }
  56. if ( $debug == true )
  57. echo "Object ClassID: $classID\n";
  58. if( is_object( $class ) )
  59. {
  60. $className = $class->attribute('identifier');
  61. $classDataMap = $class->attribute('data_map');
  62. }
  63. // Settings
  64. $ini = eZINI::instance( "cie.ini" );
  65. $excludeAttributeID = $ini->variable( "CieSettings", "ExcludeAttributeID" );
  66. if ( $debug == true )
  67. {
  68. echo "Exporting Collection: $objectID\n";
  69. echo "Output Directory: $dir\n";
  70. echo "Output Format: $format\n";
  71. echo "Output Separator: $separator\n";
  72. echo "Object Collection ID: $objectID\n";
  73. echo "Object Class Name: $className\n";
  74. }
  75. // if ( $debug == true )
  76. // print_r( $classDataMap );
  77. // print_r( $class );
  78. // die( );
  79. if( !$object )
  80. {
  81. die('Encountered Non-Object, Unknown Error');
  82. }
  83. $collections = eZInformationCollection::fetchCollectionsList(
  84. $objectID,
  85. false,
  86. false,
  87. array() );
  88. $collection_count = eZInformationCollection::fetchCollectionCountForObject( $objectID );
  89. if ( $debug == true )
  90. {
  91. echo "Object Collection Count: $collection_count\n\n";
  92. echo "Object Collection Contents: \n";
  93. print_r( $collections );
  94. }
  95. $attributes_to_export = array();
  96. // fetch collection class attributes for export
  97. foreach ( $classDataMap as $attribute )
  98. {
  99. // print_r( $attribute );
  100. if( is_object( $attribute ) )
  101. {
  102. $is_ic = $attribute->attribute('is_information_collector');
  103. if( is_numeric( $is_ic ) )
  104. {
  105. if ( $is_ic )
  106. {
  107. $id = $attribute->attribute('id');
  108. $name = $attribute->attribute('identifier');
  109. $attributes_to_export[]=$id;
  110. if( $debug )
  111. {
  112. print_r("Object Class Attribute Name: $name \n");
  113. // echo "Object Class Attribute is Information Collector: $is_ic\n";
  114. print_r("Object Class Attribute ID: $id \n\n");
  115. }
  116. }
  117. }
  118. }
  119. }
  120. // Set output file name pattern
  121. if( $days != false )
  122. {
  123. $start = mktime(0, 0, 0, date("m") , date("d")-$days, date("Y"));
  124. $namePattern = "_" . date("Y-m-d", $start) . "_to_" . date("Y-m-d");
  125. }
  126. else
  127. {
  128. $namePattern = "_export_" . date("Y-m-d_H-i");
  129. }
  130. // Set output file name
  131. switch( $format )
  132. {
  133. case 'csv':
  134. $filename = $object->attribute( 'name' ) . $namePattern . ".csv";
  135. break;
  136. case 'sylk':
  137. $filename = $object->attribute( 'name' ) . $namePattern . ".slk";
  138. break;
  139. default :
  140. $filename = $object->attribute( 'name' ) . $namePattern . ".csv";
  141. break;
  142. }
  143. $sdir = $dir.'/';
  144. $path = $sdir.$filename;
  145. if ( $debug == true )
  146. {
  147. echo "Collection Output Filename: $filename\n";
  148. echo "Collection Output Path: $path\n";
  149. }
  150. if ( $debug == true )
  151. { echo "Class Attributes ot Export (Array): \n";
  152. print_r( $attributes_to_export ); echo "\n";
  153. }
  154. print_r("Object information collection record entries fetch in progress...\n");
  155. $parser = new Parser();
  156. $data = $parser->exportInformationCollection( $collections,
  157. $attributes_to_export, $separator,
  158. $format, $days );
  159. if ( $debug == true )
  160. {
  161. echo "Collection Output Content:\n";
  162. echo( "$data\n" );
  163. }
  164. include_once( 'lib/ezfile/classes/ezfile.php' );
  165. $file = new eZFile();
  166. $file->create( $filename, $dir, $data );
  167. print_r("Object Collection Data Export File Path: $path\n");
  168. print_r("Object Collection Export Completed!\n\n");
  169. // flush();
  170. // eZExecution::cleanExit();
  171. }
  172. ?>