forked from tripal/tripal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtripal_chado.views.inc
501 lines (456 loc) · 16.7 KB
/
tripal_chado.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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
<?php
/**
* @file
* Integrates many of the core database tables with drupal views
*/
/**
* Describe various Tripal Core systems to Views for the creation of
* administrative views.
*
* @ingroup tripal
*/
function tripal_chado_views_data() {
$data = array();
// Custom Tables Management
$data = tripal_chado_views_data_custom_tables($data);
// Materialized Views Management
$data = tripal_chado_views_data_mviews($data);
return $data;
}
// /**
// * Implements hook_views_data_alter().
// */
// function tripal_chado_views_data_alter(&$data) {
// // Adds integration for chado-based fields.
// tripal_chado_add_field_views_data($data);
// return $data;
// }
// /**
// * Adds integration for chado-based fields.
// *
// * We can't use hook_field_view_data since this only works when the
// * storage engine is of type 'field_sql_storage' and of course,
// * ours is not. Thus we create our own implementation of field_views_data()
// * for our storage engine.
// */
// function tripal_chado_add_field_views_data(&$data) {
// foreach (field_info_fields() as $field) {
// if ($field['storage']['type'] != 'field_chado_storage') {
// continue;
// }
// $field_name = $field['field_name'];
// $field_type = $field['type'];
// // Currently, we only handle integration of chado fields with TripalEntity.
// // @todo: extend this to work with other entities in the future.
// if (isset($field['bundles']['TripalEntity']) AND isset($field['settings']['chado_column'])) {
// // We currently don't support prop tables for views integration due
// // in part to the multiple values but also b/c we can't indicate which
// // type of property to show. Thus, instead of warning the user,
// // we just won't integrate it at this time.
// // @todo: Handle property fields.
// if (preg_match('/prop$/', $field['settings']['chado_table'])) {
// continue;
// }
// // Get some information about the chado table in order to make good
// // default choices for handlers.
// $table_desc = chado_get_schema($field['settings']['chado_table']);
// $field_defn = $table_desc['fields'][ $field['settings']['chado_column'] ];
// // We also need to know if this field is a foreign key.
// $fk_defn = FALSE;
// foreach ($table_desc['foreign keys'] as $details) {
// foreach ($details['columns'] as $left_field => $right_field) {
// if ($left_field == $field['settings']['chado_column']) {
// $fk_defn = array(
// 'left_table' => $field['settings']['chado_table'],
// 'left_field' => $left_field,
// 'right_table' => $details['table'],
// 'right_field' => $right_field,
// );
// }
// }
// }
// // Unfortunatly we can't use the field label since that is set at the
// // instance level and fields are integrated at the field level (independant of bundle).
// // Thus we will simply make the most readable and informative field name we can.
// $data['tripal_entity'][$field_name]['title'] = ucfirst(str_replace('_',' ',$field['settings']['chado_table']))
// . ': ' .ucfirst(str_replace('_',' ',$field['settings']['chado_column']));
// // The help should be 'Appears in: TripalEntity: gene, organism'
// // so that users know where they can use it. This requires a little extra work since all
// // we have access to at this point is bio_data_2, bio_data_4 but since that's not very
// // informative, extra work is worth it ;-).
// $entity_info = entity_get_info('TripalEntity');
// $bundle_labels = array();
// foreach ($field['bundles']['TripalEntity'] as $bundle_id) {
// $bundle_labels[] = $entity_info['bundles'][$bundle_id]['label'];
// }
// $data['tripal_entity'][$field_name]['help'] = 'Appears in: TripalEntity:' . implode(', ', $bundle_labels);
// // Define the field.
// $data['tripal_entity'][$field_name]['field']['chado_field'] = $field['settings']['chado_column'];
// $data['tripal_entity'][$field_name]['field']['chado_table'] = $field['settings']['chado_table'];
// $data['tripal_entity'][$field_name]['field']['field_name'] = $field['field_name'];
// $data['tripal_entity'][$field_name]['field']['entity_table'] = 'tripal_entity';
// $data['tripal_entity'][$field_name]['field']['entity_type'] = 'TripalEntity';
// $data['tripal_entity'][$field_name]['field']['bundles'] = $field['bundles']['TripalEntity'];
// $data['tripal_entity'][$field_name]['field']['handler'] = 'chado_views_handler_field';
// $data['tripal_entity'][$field_name]['field']['click sortable'] = FALSE;
// // Define the Filter.
// $data['tripal_entity'][$field_name]['filter']['chado_field'] = $field['settings']['chado_column'];
// $data['tripal_entity'][$field_name]['filter']['chado_table'] = $field['settings']['chado_table'];
// $data['tripal_entity'][$field_name]['filter']['field_name'] = $field['field_name'];
// $data['tripal_entity'][$field_name]['filter']['entity_table'] = 'tripal_entity';
// $data['tripal_entity'][$field_name]['filter']['entity_type'] = 'TripalEntity';
// $data['tripal_entity'][$field_name]['filter']['bundles'] = $field['bundles']['TripalEntity'];
// $data['tripal_entity'][$field_name]['filter']['handler'] = 'chado_views_handler_filter_string';
// // Define sorting.
// $data['tripal_entity'][$field_name]['sort']['chado_field'] = $field['settings']['chado_column'];
// $data['tripal_entity'][$field_name]['sort']['chado_table'] = $field['settings']['chado_table'];
// $data['tripal_entity'][$field_name]['sort']['field_name'] = $field['field_name'];
// $data['tripal_entity'][$field_name]['sort']['entity_table'] = 'tripal_entity';
// $data['tripal_entity'][$field_name]['sort']['entity_type'] = 'TripalEntity';
// $data['tripal_entity'][$field_name]['sort']['bundles'] = $field['bundles']['TripalEntity'];
// $data['tripal_entity'][$field_name]['sort']['handler'] = 'chado_views_handler_sort';
// // Specify special handlers.
// if ($fk_defn) {
// $data['tripal_entity'][$field_name]['filter']['handler'] = 'chado_views_handler_filter_fk';
// $data['tripal_entity'][$field_name]['filter']['foreign_key'] = $fk_defn;
// }
// if ($field_defn['type'] == 'boolean') {
// $data['tripal_entity'][$field_name]['filter']['handler'] = 'chado_views_handler_filter_boolean';
// $data['tripal_entity'][$field_name]['filter']['label'] = $field['settings']['chado_column'];
// $data['tripal_entity'][$field_name]['filter']['type'] = 'yes-no';
// }
// elseif ($field_defn['type'] == 'datetime') {
// $data['tripal_entity'][$field_name]['filter']['handler'] = 'chado_views_handler_filter_date';
// }
// // Allow the fields to alter the default selections from above.
// tripal_load_include_field_type($field_type);
// if (preg_match('/^chado/', $field_type) and class_exists($field_type)) {
// $field_obj = new $field_type($field);
// $field_obj->views_data_alter($data['tripal_entity'][$field_name], $field, $entity_info);
// }
// }
// }
// }
/**
* Provides the data array for the tripal custom tables management
*
* @param $data
* Previously generated tripal views data array
* return
* $data array with custom tables management described
*
* @ingroup tripal
*/
function tripal_chado_views_data_custom_tables($data) {
$data['tripal_custom_tables']['table']['group'] = t('Tripal Custom Tables');
$data['tripal_custom_tables']['table']['base'] = array(
'field' => 'table_id', // This is the identifier field for the view.
'title' => t('Tripal Custom Tables'),
'help' => t('Custom Tables in Chado created by this Tripal Installation.'),
'weight' => 10,
);
// Table ID
$data['tripal_custom_tables']['table_id'] = array(
'title' => t('Custom Table ID'),
'help' => t('Custom table primary key.'),
'field' => array(
'handler' => 'views_handler_field_numeric',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
// Table Name
$data['tripal_custom_tables']['table_name'] = array(
'title' => t('Table Name'),
'help' => t('The name of the table in the database.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE, // This is use by the table display plugin.
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
);
// Schema
$data['tripal_custom_tables']['schema'] = array(
'title' => t('Table Schema'),
'help' => t('The schema definition of the table.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE, // This is use by the table display plugin.
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
);
// Table ID
$data['tripal_custom_tables']['mview_id'] = array(
'title' => t('Materialized View ID'),
'help' => t('Foreign key to tripal_mviews table for the materialized view.'),
'field' => array(
'handler' => 'views_handler_field_numeric',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
return $data;
}
/**
* Provides the data array for the tripal custom tables management
*
* @param $data
* Previously generated tripal views data array
* return
* $data array with custom tables management described
*
* @ingroup tripal
*/
function tripal_chado_views_data_mviews($data) {
$data['tripal_mviews']['table']['group'] = t('Tripal Materialized Views');
$data['tripal_mviews']['table']['base'] = array(
'field' => 'mview_id', // This is the identifier field for the view.
'title' => t('Tripal Materialized Views'),
'help' => t('Materialized Views in Chado created by this Tripal Installation.'),
'weight' => 10,
);
// Implicit Join to Tripal Views
$data['tripal_mviews']['table']['join'] = array(
'tripal_views' => array(
'left_field' => 'mview_id',
'field' => 'mview_id',
),
);
// Mview ID
$data['tripal_mviews']['mview_id'] = array(
'title' => t('Materialized View ID'),
'help' => t('The primary key.'),
'field' => array(
'handler' => 'views_handler_field_numeric',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
// name
$data['tripal_mviews']['name'] = array(
'title' => t('Name'),
'help' => t('Human-readable name of the materialized view.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE, // This is use by the table display plugin.
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
);
// modulename
$data['tripal_mviews']['modulename'] = array(
'title' => t('Module Name'),
'help' => t('The module that created the materialized view.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE, // This is use by the table display plugin.
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
);
// mv_table
$data['tripal_mviews']['mv_table'] = array(
'title' => t('Table'),
'help' => t('The database table the materialized view is stored in.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE, // This is use by the table display plugin.
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
);
// mv_specs
$data['tripal_mviews']['mv_specs'] = array(
'title' => t('Specification'),
'help' => t('Materialized View Specification.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE, // This is use by the table display plugin.
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
);
// mv_schema
$data['tripal_mviews']['mv_schema'] = array(
'title' => t('Schema'),
'help' => t('Schema definition for the materialized view table.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE, // This is use by the table display plugin.
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
);
// indexed
$data['tripal_mviews']['indexed'] = array(
'title' => t('Indices'),
'help' => t('Any indices for this materialized view.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE, // This is use by the table display plugin.
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
);
// query
$data['tripal_mviews']['query'] = array(
'title' => t('Query'),
'help' => t('The query used to populate the materialized view.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE, // This is use by the table display plugin.
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
);
// special_index
$data['tripal_mviews']['special_index'] = array(
'title' => t('Special Index'),
'help' => t('Any special indices for the materialized view.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE, // This is use by the table display plugin.
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
);
// last_update
$data['tripal_mviews']['last_update'] = array(
'title' => t('Updated'),
'help' => t('Date Last Updated.'),
'field' => array(
'handler' => 'views_handler_field_date',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort_date',
),
'filter' => array(
'handler' => 'views_handler_filter_date',
),
);
// status
$data['tripal_mviews']['status'] = array(
'title' => t('Status'),
'help' => t('The status of the materialized view.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE, // This is use by the table display plugin.
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
);
// comment
$data['tripal_mviews']['comment'] = array(
'title' => t('Description'),
'help' => t('Human-Readable Admin Description.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE, // This is use by the table display plugin.
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
);
return $data;
}