taxonomy_csv.export.result.inc 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. /**
  3. * @file
  4. * Show export result messages.
  5. */
  6. /**
  7. * Invoke associated include file.
  8. */
  9. $module_dir = drupal_get_path('module', 'taxonomy_csv');
  10. require_once($module_dir . '/taxonomy_csv.result.inc');
  11. /**
  12. * Display result messages of export process.
  13. *
  14. * @param $options
  15. * Array. Same as taxonomy_csv_export.
  16. * @param $worst_level
  17. * Integer. Worst watchdog level of the process.
  18. * @param $summary
  19. * Translated string. Short summary of informations on process.
  20. * @param $results
  21. * Array. Batch process results.
  22. *
  23. * @return
  24. * Nothing.
  25. */
  26. function _taxonomy_csv_export_result($options, $worst_level, $summary, $results) {
  27. // Prepare info and warning messages.
  28. $messages = array();
  29. // Summary message.
  30. $messages[] = array($worst_level => $summary);
  31. // Prepare batch result message.
  32. if ($options['total_terms'] == 0) {
  33. $message = t('Notice: Chosen vocabulary has no term to export.');
  34. $messages[] = array(WATCHDOG_NOTICE => $message);
  35. }
  36. // Only summary is displayed in case of error.
  37. elseif ($worst_level >= WATCHDOG_WARNING) {
  38. $list_format = _taxonomy_csv_values('export_format');
  39. // General infos.
  40. $message = t('!term_count / !total_terms terms of chosen vocabularies have been exported to file !file (!filesize KB) with the format "!format". Click on link to view it or right click to download it.', array(
  41. '!term_count' => $options['current_term'],
  42. '!total_terms' => $options['total_terms'],
  43. '!file' => l($options['file']->filename, file_create_url('public://' . $options['file']->filename)),
  44. '!filesize' => number_format(filesize($options['file']->filepath) / 1000, 1),
  45. '!format' => $list_format[$options['export_format']],
  46. ));
  47. // Main check of end process.
  48. $watchdog_level = (($options['current_term'] == $options['total_terms']) && ($options['current_term'] > 0)) ?
  49. WATCHDOG_INFO :
  50. WATCHDOG_ERROR;
  51. $messages[] = array($watchdog_level => $message);
  52. // Infos on duplicate term names.
  53. $options['duplicate_terms'] = array();
  54. foreach ($options['vocabulary_id'] as $item) {
  55. $options['duplicate_terms'] += taxonomy_csv_term_find_duplicate($item);
  56. }
  57. $duplicate_count = count($options['duplicate_terms']);
  58. // If there are duplicate term names, display them if user chooses it.
  59. if ($duplicate_count) {
  60. $message = t('!count duplicate term names have been found in all vocabularies. Error can occur when you will import this list, except if you choose "fields and links" export format or import option "ignore existing items".', array('!count' => $duplicate_count));
  61. if ($options['result_duplicates']) {
  62. $message .= '<br />' . t('List of duplicated term names:')
  63. . ' "' . implode('", "', array_keys(array_flip($options['duplicate_terms']))) . '".';
  64. }
  65. $watchdog_level = WATCHDOG_NOTICE;
  66. }
  67. else {
  68. // No duplicate term names.
  69. $message = t('No duplicate term name has been found.');
  70. $watchdog_level = WATCHDOG_INFO;
  71. }
  72. $messages[] = array($watchdog_level => $message);
  73. // Info on specific format.
  74. foreach ($options['vocabulary'] as $vocabulary) {
  75. switch ($options['export_format']) {
  76. case TAXONOMY_CSV_FORMAT_TREE:
  77. if ($vocabulary->hierarchy == 2) {
  78. $message = t('Vocabulary "@vocabulary" is polyhierarchical. With the selected format (tree), only the first parent of each term was exported.', array(
  79. '@vocabulary' => $vocabulary->name,
  80. ));
  81. $messages[] = array(WATCHDOG_NOTICE => $message);
  82. }
  83. break;
  84. case TAXONOMY_CSV_FORMAT_FIELDS:
  85. $format = array();
  86. foreach ($vocabulary->fields as $field_name => &$field) {
  87. if (isset($vocabulary->fields_unlimited[$field_name])) {
  88. $format = array_merge($format, array_fill(0, $vocabulary->fields_unlimited[$field_name], $field_name));
  89. }
  90. else {
  91. $format = array_merge($format, array_fill(0, $field['cardinality'], $field_name));
  92. }
  93. }
  94. $message = t('CSV format of vocabulary "@vocabulary" is:', array(
  95. '@vocabulary' => $vocabulary->name,
  96. ));
  97. $message .= '<br /><pre>' . implode(', ', $format) . '</pre>';
  98. $messages[] = array(WATCHDOG_INFO => $message);
  99. break;
  100. case TAXONOMY_CSV_FORMAT_TRANSLATE:
  101. $format = array();
  102. switch ($vocabulary->i18n_mode) {
  103. case I18N_MODE_NONE:
  104. $format[] = 'und';
  105. break;
  106. case I18N_MODE_LANGUAGE:
  107. $format[] = $vocabulary->language;
  108. break;
  109. case I18N_MODE_LOCALIZE:
  110. $format = locale_language_list('name');
  111. unset($format[language_default('language')]);
  112. $format = array_flip($format);
  113. array_unshift($format, language_default('language'));
  114. break;
  115. case I18N_MODE_TRANSLATE:
  116. case I18N_MODE_MULTIPLE:
  117. $format = locale_language_list('name');
  118. $format = array_flip($format);
  119. array_unshift($format, 'und');
  120. break;
  121. }
  122. $message = t('CSV format of vocabulary "@vocabulary" is:', array(
  123. '@vocabulary' => $vocabulary->name,
  124. ));
  125. $message .= '<br /><pre>' . implode(', ', $format) . '</pre>';
  126. $messages[] = array(WATCHDOG_INFO => $message);
  127. break;
  128. }
  129. }
  130. }
  131. _taxonomy_csv_message_result($messages);
  132. }