comment.views_convert.inc

Field conversion for fields handled by this module.

File

modules/comment.views_convert.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Field conversion for fields handled by this module.
  5. */
  6. /**
  7. * Implementation of hook_views_convert().
  8. *
  9. * Intervene to convert field values from the Views 1 format to the
  10. * Views 2 format. Intervene only if $view->add_item() won't produce
  11. * the right results, usually needed to set field options or values.
  12. */
  13. function comment_views_convert($display, $type, &$view, $field, $id = NULL) {
  14. switch ($type) {
  15. case 'field':
  16. switch ($field['tablename']) {
  17. case 'comments':
  18. switch ($field['field']) {
  19. case 'subject':
  20. if ($field['options'] = 'nolink') {
  21. $view->set_item_option($display, 'field', $id, 'link_to_comment', FALSE);
  22. }
  23. break;
  24. case 'cid':
  25. $view->set_item_option($display, 'field', $id, 'link_to_comment', FALSE);
  26. break;
  27. case 'timestamp':
  28. $handlers = array(
  29. 'views_handler_field_date_small' => 'small',
  30. 'views_handler_field_date' => 'medium',
  31. 'views_handler_field_date_large' => 'large',
  32. 'views_handler_field_date_custom' => 'custom',
  33. 'views_handler_field_since' => 'time ago',
  34. );
  35. $view->set_item_option($display, 'field', $id, 'date_format', $handlers[$field['handler']]);
  36. if (!empty($field['options'])) {
  37. $view->set_item_option($display, 'field', $id, 'custom_date_format', $field['options']);
  38. }
  39. break;
  40. case 'add':
  41. $view->set_item_option($display, 'field', $id, 'field', 'replyto_comment');
  42. break;
  43. }
  44. break;
  45. case 'node_comment_statistics':
  46. switch ($field['field']) {
  47. case 'last_comment_timestamp':
  48. $handlers = array(
  49. 'views_handler_field_date_small' => 'small',
  50. 'views_handler_field_date' => 'medium',
  51. 'views_handler_field_date_large' => 'large',
  52. 'views_handler_field_date_custom' => 'custom',
  53. 'views_handler_field_since' => 'time ago',
  54. );
  55. $view->set_item_option($display, 'field', $id, 'date_format', $handlers[$field['handler']]);
  56. if (!empty($field['options'])) {
  57. $view->set_item_option($display, 'field', $id, 'custom_date_format', $field['options']);
  58. }
  59. break;
  60. case 'last_changed':
  61. $handlers = array(
  62. 'views_handler_field_date_small' => 'small',
  63. 'views_handler_field_date' => 'medium',
  64. 'views_handler_field_date_large' => 'large',
  65. 'views_handler_field_date_custom' => 'custom',
  66. 'views_handler_field_since' => 'time ago',
  67. );
  68. $item = $view->get_item($display, 'field', $id);
  69. $item['date_format'] = $handlers[$field['handler']];
  70. if (!empty($field['options'])) {
  71. $item['custom_date_format'] = $field['options'];
  72. }
  73. $item['field'] = 'last_updated';
  74. $view->set_item($display, 'field', $id, $item);
  75. break;
  76. }
  77. break;
  78. }
  79. break;
  80. case 'filter':
  81. switch ($field['tablename']) {
  82. case 'node_comment_statistics':
  83. switch ($field['field']) {
  84. case 'comment_count':
  85. $view->set_item_option($display, 'filter', $id, 'operator', $field['operator']);
  86. break;
  87. case 'last_changed':
  88. $field['field'] = 'last_updated';
  89. case 'last_comment_timestamp':
  90. $item = $view->get_item($display, 'filter', $id);
  91. $item['operator'] = $field['operator'];
  92. $item['value'] = array(
  93. 'type' => $field['value'] == 'now' ? 'offset' : 'date',
  94. 'value' => $field['value'],
  95. );
  96. if (!empty($field['options'])) {
  97. $item['value']['value'] = intval($field['options']) .' seconds';
  98. }
  99. $item['field'] = $field['field'];
  100. $view->set_item($display, 'filter', $id, $item);
  101. break;
  102. }
  103. break;
  104. }
  105. break;
  106. case 'sort':
  107. switch ($field['tablename']) {
  108. case 'comments':
  109. switch ($field['field']) {
  110. case 'timestamp':
  111. $field['options'] = $field['options'] == 'normal' ? 'second' : $field['options'];
  112. $view->set_item_option($display, 'sort', $id, 'granularity', $field['options']);
  113. break;
  114. }
  115. break;
  116. case 'node_comment_statistics':
  117. switch ($field['field']) {
  118. case 'last_changed':
  119. $view->set_item_option($display, 'sort', $id, 'field', 'last_updated');
  120. case 'last_comment_timestamp':
  121. $field['options'] = $field['options'] == 'normal' ? 'second' : $field['options'];
  122. $view->set_item_option($display, 'sort', $id, 'granularity', $field['options']);
  123. break;
  124. }
  125. break;
  126. }
  127. break;
  128. }
  129. }