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