summaryrefslogtreecommitdiffstats
path: root/modules/comment.views_convert.inc
blob: 4310f48e65f797e0e57f93e02607e53eedaad0af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
//$Id$

/**
 * @file
 * Field conversion for fields handled by this module.
 */

/**
 * Implementation of hook_views_convert().
 *
 * Intervene to convert field values from the Views 1 format to the
 * Views 2 format. Intervene only if $view->add_item() won't produce
 * the right results, usually needed to set field options or values.
 */
function comment_views_convert($display, $type, &$view, $field, $id = NULL) {
  switch ($type) {
    case 'field':
      switch ($field['tablename']) {
        case 'comments':
          switch ($field['field']) {
            case 'subject':
              if ($field['options'] = 'nolink') {
                $view->set_item_option($display, 'field', $id, 'link_to_comment', FALSE);
              }
              break;
            case 'cid':
              $view->set_item_option($display, 'field', $id, 'link_to_comment', FALSE);
              break;
            case 'timestamp':
              $handlers = array(
                'views_handler_field_date_small' => 'small',
                'views_handler_field_date' => 'medium',
                'views_handler_field_date_large' => 'large',
                'views_handler_field_date_custom' => 'custom',
                'views_handler_field_since' => 'time ago',
              );
              $view->set_item_option($display, 'field', $id, 'date_format', $handlers[$field['handler']]);
              if (!empty($field['options'])) {
                $view->set_item_option($display, 'field', $id, 'custom_date_format', $field['options']);
              }
              break;
            case 'add':
              $view->set_item_option($display, 'field', $id, 'field', 'replyto_comment');
              break;
          }
          break;
        case 'node_comment_statistics':
          switch ($field['field']) {
            case 'last_comment_timestamp':
              $handlers = array(
                'views_handler_field_date_small' => 'small',
                'views_handler_field_date' => 'medium',
                'views_handler_field_date_large' => 'large',
                'views_handler_field_date_custom' => 'custom',
                'views_handler_field_since' => 'time ago',
              );
              $view->set_item_option($display, 'field', $id, 'date_format', $handlers[$field['handler']]);
              if (!empty($field['options'])) {
                $view->set_item_option($display, 'field', $id, 'custom_date_format', $field['options']);
              }
              break;
            case 'last_changed':
              $handlers = array(
                'views_handler_field_date_small' => 'small',
                'views_handler_field_date' => 'medium',
                'views_handler_field_date_large' => 'large',
                'views_handler_field_date_custom' => 'custom',
                'views_handler_field_since' => 'time ago',
              );
              $item = $view->get_item($display, 'field', $id);
              $item['date_format'] = $handlers[$field['handler']];
              if (!empty($field['options'])) {
                $item['custom_date_format'] = $field['options'];
              }
              $item['field'] = 'last_updated';
              $view->set_item($display, 'field', $id, $item);
              break;
          }
          break;
      }
      break;
    case 'filter':
      switch ($field['tablename']) {
        case 'node_comment_statistics':
          switch ($field['field']) {
            case 'comment_count':
              $view->set_item_option($display, 'filter', $id, 'operator', $field['operator']);
              break;
            case 'last_changed':
              $field['field'] = 'last_updated';
            case 'last_comment_timestamp':
              $item = $view->get_item($display, 'filter', $id);
              $item['operator'] = $field['operator'];
              $item['value'] = array(
                'type' => $field['value'] == 'now' ? 'offset' : 'date',
                'value' => $field['value'],
              );
              if (!empty($field['options'])) {
                $item['value']['value'] = intval($field['options']) .' seconds';
              }
              $item['field'] = $field['field'];
              $view->set_item($display, 'filter', $id, $item);
              break;
          }
          break;
      }
      break;
    case 'sort':
      switch ($field['tablename']) {
        case 'comments':
          switch ($field['field']) {
            case 'timestamp':
              $field['options'] = $field['options'] == 'normal' ? 'second' : $field['options'];
              $view->set_item_option($display, 'sort', $id, 'granularity', $field['options']);
              break;
          }
          break;
        case 'node_comment_statistics':
          switch ($field['field']) {
            case 'last_changed':
              $view->set_item_option($display, 'sort', $id, 'field', 'last_updated');
            case 'last_comment_timestamp':
              $field['options'] = $field['options'] == 'normal' ? 'second' : $field['options'];
              $view->set_item_option($display, 'sort', $id, 'granularity', $field['options']);
              break;
          }
          break;
      }
      break;
  }
}