Revision 1c0bd967
Added by Lorna Morris about 12 years ago
7.x/modules/dwca_export/dwca_export.module | ||
---|---|---|
336 | 336 |
|
337 | 337 |
if ($dwca_filename == 'description') { |
338 | 338 |
|
339 |
//lorna TODO: loop create a new $view_temp_file for each desciption type |
|
340 |
|
|
341 |
////////drupal_realpath($tmp_archive_file_name) |
|
342 |
$desc_file_name = drupal_tempnam("temporary://", "description"); |
|
343 |
$desc_file = fopen(drupal_realpath($desc_file_name), "w"); |
|
344 |
|
|
345 |
|
|
346 |
|
|
347 |
foreach($view_data as $type=>$view_data_inner){ |
|
348 |
//$view_temp_file = $view_data['general']['out_file_url']; |
|
349 |
$view_temp_file = $view_data_inner['out_file_url']; |
|
350 |
|
|
351 |
drupal_set_message(t('The TYPE is: ') . $type); |
|
352 |
drupal_set_message(t('The outfile URL: ') . $view_data_inner['out_file_url']); |
|
353 |
//lets start by creating a different filename for each type of desc data??? |
|
354 |
////// |
|
355 |
/////// |
|
356 |
/// |
|
357 |
$theFile = fopen($view_temp_file, "r"); |
|
358 |
//$theText = fgets($theFile); |
|
359 |
|
|
360 |
while(!feof($theFile)){ |
|
361 |
$lineOfText = fgets($theFile); |
|
362 |
print "$lineOfText<br />"; |
|
363 |
fputs($desc_file, $lineOfText); |
|
364 |
drupal_set_message($lineOfText); |
|
365 |
} |
|
366 |
|
|
367 |
//// |
|
368 |
|
|
369 |
|
|
370 |
|
|
371 |
_dwca_export_add_files_to_zip($view_temp_file, $type, $zip); |
|
372 |
} |
|
373 |
_dwca_export_add_files_to_zip($desc_file_name, $type, $zip); |
|
339 |
_dwca_export_concatenate_description_files($view_data, $zip); |
|
374 | 340 |
|
375 | 341 |
} else { |
376 | 342 |
|
377 | 343 |
$view_temp_file = $view_data['out_file_url']; |
378 |
drupal_set_message(t('The outfile URL!!: ') . $view_data['out_file_url']); |
|
379 | 344 |
_dwca_export_add_files_to_zip($view_temp_file, $dwca_filename, $zip); |
380 | 345 |
} |
381 |
|
|
382 |
//lorna temp file - concatenate desc data files |
|
383 |
//// |
|
384 |
////_dwca_export_add_files_to_zip($view_temp_file, $dwca_filename, $zip); |
|
385 | 346 |
|
386 | 347 |
} |
387 | 348 |
|
... | ... | |
390 | 351 |
return $tmp_archive_file_name; |
391 | 352 |
} |
392 | 353 |
|
354 |
/** |
|
355 |
* |
|
356 |
* Combines multiple Description Views for different description types into a single file |
|
357 |
* @param $view_data The inner array containing the view data for the different description types |
|
358 |
* @param $zip The zip file for the files making up the DwC-A. |
|
359 |
*/ |
|
360 |
function _dwca_export_concatenate_description_files($view_data, $zip){ |
|
361 |
|
|
362 |
$desc_file_name = drupal_tempnam("temporary://", "description.tmp"); |
|
363 |
$desc_file = fopen(drupal_realpath($desc_file_name), "w"); |
|
364 |
|
|
365 |
$first_desc_file = true; |
|
366 |
foreach($view_data as $type=>$view_data_inner){ |
|
367 |
|
|
368 |
$view_temp_file = $view_data_inner['out_file_url']; |
|
369 |
|
|
370 |
$theFile = fopen($view_temp_file, "r"); |
|
371 |
|
|
372 |
//print column names from first file |
|
373 |
if ($first_desc_file) { |
|
374 |
$lineOfText = fgets($theFile); |
|
375 |
fputs($desc_file, $lineOfText); |
|
376 |
$first_desc_file = false; |
|
377 |
} else { |
|
378 |
fgets($theFile); |
|
379 |
} |
|
380 |
|
|
381 |
while(!feof($theFile)){ |
|
382 |
$lineOfText = fgets($theFile); |
|
383 |
print "$lineOfText<br />"; |
|
384 |
|
|
385 |
$items = explode(',', $lineOfText); |
|
386 |
|
|
387 |
if (!empty($items[2])) { |
|
388 |
|
|
389 |
fputs($desc_file, $lineOfText); |
|
390 |
//add an end of line if there isn't one |
|
391 |
//if (!stripos(strrev($lineOfText), '"') === 0) { |
|
392 |
//fputs($desc_file, '"' . PHP_EOL); |
|
393 |
fputs($desc_file, PHP_EOL); |
|
394 |
//} |
|
395 |
} else { |
|
396 |
fgets($theFile); |
|
397 |
} |
|
398 |
|
|
399 |
drupal_set_message($lineOfText); |
|
400 |
} |
|
401 |
|
|
402 |
fclose($theFile); |
|
403 |
|
|
404 |
//currently also adding each individual desc type to archive |
|
405 |
_dwca_export_add_files_to_zip($view_temp_file, $type, $zip); |
|
406 |
} |
|
407 |
fclose($desc_file); |
|
408 |
|
|
409 |
_dwca_export_add_files_to_zip($desc_file_name, 'description', $zip); |
|
410 |
} |
|
411 |
|
|
393 | 412 |
function _dwca_export_add_files_to_zip($view_temp_file = NULL, $dwca_filename, $zip){ |
394 | 413 |
|
395 | 414 |
if($view_temp_file){ |
Also available in: Unified diff
Added method to combine multiple Description Views for different description types into a single text file