-
Notifications
You must be signed in to change notification settings - Fork 4
/
ting_search_context.views.inc
242 lines (234 loc) · 7.12 KB
/
ting_search_context.views.inc
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
<?php
/**
* @file
* Contains this modules Views-hook implementations.
*/
/**
* Implements hook_views_data().
*
* Describes our custom tables to Views.
*
* @see ting_search_context_schema()
*/
function ting_search_context_views_data() {
$data = array();
// Describe the contexts table as a Views base table.
$data['ting_search_context_contexts']['table'] = array(
'group' => t('Ting search context'),
'base' => array(
'field' => 'context_id',
'title' => t('Ting search context contexts'),
'help' => t('Search contexts from the Ting search context module'),
'weight' => -10,
),
// Link the contexts table to the nodes_rated table and tell Views how to
// join our table with the node table (Implicit relationship).
'join' => array(
'node' => array(
'left_table' => 'ting_search_context_nodes_rated',
'left_field' => 'context_id',
// Field to join on this table.
'field' => 'context_id',
),
),
);
// The nodes rated table (not a Views base table).
$data['ting_search_context_nodes_rated']['table'] = array(
'group' => t('Ting search context'),
'join' => array(
'node' => array(
'left_field' => 'nid',
'field' => 'nid',
),
),
);
// Describe each of the individual fields in our tables.
$data['ting_search_context_contexts']['context_id'] = array(
'title' => t('Context ID'),
'help' => t('The ID of the context'),
// Information for displaying the field.
'field' => array(
'handler' => 'views_handler_field_numeric',
// Used by table display plugin.
'click sortable' => TRUE,
),
// Information for accepting a context ID as argument.
'argument' => array(
'handler' => 'views_handler_argument_numeric',
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
$data['ting_search_context_contexts']['type'] = array(
'title' => t('Type'),
'help' => t('The context type (system, search or subject)'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'ting_search_context_handler_filter_context_type',
),
'argument' => array(
// Maybe override to use name as summary.
'handler' => 'views_handler_argument_string',
),
);
$data['ting_search_context_contexts']['name'] = array(
'title' => t('Name'),
'help' => t('The human-readable name of the context'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
);
$data['ting_search_context_contexts']['context'] = array(
'title' => t('Context'),
'help' => t('The machine-name of the context'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
// ting_search_context_handler_filter_context_machine_name.
'handler' => 'views_handler_filter_string',
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
);
$data['ting_search_context_contexts']['subjects'] = array(
'title' => t('Subjects'),
'help' => t('The subjects of the context'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
);
$data['ting_search_context_contexts']['search'] = array(
'title' => t('Search'),
'help' => t('The search string of the context'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
);
// TODO: Relationship handlers for context_id and nid.
$data['ting_search_context_nodes_rated']['context_id'] = array(
'title' => t('Context ID'),
'help' => t('The ID of the rated context'),
// Information for displaying the field.
'field' => array(
'handler' => 'views_handler_field_numeric',
// Used by table display plugin.
'click sortable' => TRUE,
),
// Information for accepting a context ID as argument.
'argument' => array(
'handler' => 'views_handler_argument_numeric',
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
$data['ting_search_context_nodes_rated']['nid'] = array(
'title' => t('Node ID'),
'help' => t('The ID of the rated node'),
// Information for displaying the field.
'field' => array(
'handler' => 'views_handler_field_numeric',
// Used by table display plugin.
'click sortable' => TRUE,
),
// Information for accepting a context ID as argument.
'argument' => array(
'handler' => 'views_handler_argument_numeric',
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
$data['ting_search_context_nodes_rated']['rating'] = array(
'title' => t('Rating'),
'help' => t('The rating-number of the rating'),
// Information for displaying the field.
'field' => array(
'handler' => 'views_handler_field_numeric',
// Used by table display plugin.
'click sortable' => TRUE,
),
// Information for accepting a context ID as argument.
'argument' => array(
'handler' => 'views_handler_argument_numeric',
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
return $data;
}
/**
* Implements hook_views_data_alter().
*/
function ting_search_context_views_data_alter(&$data) {
// Provide some special handlers on the node table as an easy way to tackle
// the many-to-many complexity between nodes and contexts. For example, a
// node can be rated in many contexts and a contexts can have many nodes
// rated in it.
$data['node']['ting_search_context_node_ratings'] = array(
'title' => t('Node ratings'),
'help' => t('Associates ratings with nodes'),
'field' => array(
'title' => t('All ratings'),
'help' => t('Display all ratings associated with a node'),
'handler' => 'ting_search_context_handler_field_node_ratings',
'no group by' => TRUE,
),
'filter' => array(
'title' => t('Rating filter'),
'help' => t('Filter to only display content rated in selected contexts'),
'handler' => 'ting_search_context_handler_filter_node_ratings',
'real field' => 'nid',
),
);
}