Projet

Général

Profil

Paste
Télécharger (20,1 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / views / modules / system.views.inc @ 4003efde

1
<?php
2

    
3
/**
4
 * @file
5
 * Provide views data and handlers for system.module.
6
 *
7
 * @ingroup views_module_handlers
8
 */
9

    
10
/**
11
 * Implements hook_views_data().
12
 */
13
function system_views_data() {
14
  $data = array();
15

    
16
  // ----------------------------------------------------------------------
17
  // 'file_managed' table.
18
  $data['files']['moved to'] = 'file_managed';
19
  $data['file_managed']['table']['group']  = t('File');
20

    
21
  // Advertise this table as a possible base table.
22
  $data['file_managed']['table']['base'] = array(
23
    'field' => 'fid',
24
    'title' => t('File'),
25
    'help' => t("Files maintained by Drupal and various modules."),
26
    'defaults' => array(
27
      'field' => 'filename',
28
    ),
29
  );
30
  $data['file_managed']['table']['entity type'] = 'file';
31

    
32
  // File ID / 'fid'.
33
  $data['file_managed']['fid'] = array(
34
    'title' => t('File ID'),
35
    'help' => t('The ID of the file.'),
36
    'field' => array(
37
      'handler' => 'views_handler_field_file',
38
      'click sortable' => TRUE,
39
    ),
40
    'argument' => array(
41
      'handler' => 'views_handler_argument_file_fid',
42
      'name field' => 'filename',
43
  // the field to display in the summary.
44
      'numeric' => TRUE,
45
    ),
46
    'filter' => array(
47
      'handler' => 'views_handler_filter_numeric',
48
    ),
49
    'sort' => array(
50
      'handler' => 'views_handler_sort',
51
    ),
52
  );
53

    
54
  // Filename.
55
  $data['file_managed']['filename'] = array(
56
    'title' => t('Name'),
57
    'help' => t('The name of the file.'),
58
    'field' => array(
59
      'handler' => 'views_handler_field_file',
60
      'click sortable' => TRUE,
61
    ),
62
    'sort' => array(
63
      'handler' => 'views_handler_sort',
64
    ),
65
    'filter' => array(
66
      'handler' => 'views_handler_filter_string',
67
    ),
68
    'argument' => array(
69
      'handler' => 'views_handler_argument_string',
70
    ),
71
  );
72

    
73
  // URI.
74
  $data['file_managed']['uri'] = array(
75
    'title' => t('Path'),
76
    'help' => t('The path of the file.'),
77
    'field' => array(
78
      'handler' => 'views_handler_field_file_uri',
79
      'click sortable' => TRUE,
80
    ),
81
    'sort' => array(
82
      'handler' => 'views_handler_sort',
83
    ),
84
    'filter' => array(
85
      'handler' => 'views_handler_filter_string',
86
    ),
87
    'argument' => array(
88
      'handler' => 'views_handler_argument_string',
89
    ),
90
  );
91

    
92
  // The file's MIME Type.
93
  $data['file_managed']['filemime'] = array(
94
    'title' => t('Mime type'),
95
    'help' => t('The mime type of the file.'),
96
    'field' => array(
97
      'handler' => 'views_handler_field_file_filemime',
98
      'click sortable' => TRUE,
99
    ),
100
    'sort' => array(
101
      'handler' => 'views_handler_sort',
102
    ),
103
    'filter' => array(
104
      'handler' => 'views_handler_filter_string',
105
    ),
106
    'argument' => array(
107
      'handler' => 'views_handler_argument_string',
108
    ),
109
  );
110

    
111
  // Extension.
112
  $data['file_managed']['extension'] = array(
113
    'title' => t('Extension'),
114
    'help' => t('The extension of the file.'),
115
    'real field' => 'uri',
116
    'field' => array(
117
      'handler' => 'views_handler_field_file_extension',
118
      'click sortable' => FALSE,
119
    ),
120
  );
121

    
122
  // Filesize.
123
  $data['file_managed']['filesize'] = array(
124
    'title' => t('Size'),
125
    'help' => t('The size of the file.'),
126
    'field' => array(
127
      'handler' => 'views_handler_field_file_size',
128
      'click sortable' => TRUE,
129
    ),
130
    'sort' => array(
131
      'handler' => 'views_handler_sort',
132
    ),
133
    'filter' => array(
134
      'handler' => 'views_handler_filter_numeric',
135
    ),
136
  );
137

    
138
  // Status.
139
  $data['file_managed']['status'] = array(
140
    'title' => t('Status'),
141
    'help' => t('The status of the file.'),
142
    'field' => array(
143
      'handler' => 'views_handler_field_file_status',
144
      'click sortable' => TRUE,
145
    ),
146
    'sort' => array(
147
      'handler' => 'views_handler_sort',
148
    ),
149
    'filter' => array(
150
      'handler' => 'views_handler_filter_file_status',
151
    ),
152
  );
153

    
154
  // Timestamp field.
155
  $data['file_managed']['timestamp'] = array(
156
    'title' => t('Upload date'),
157
    'help' => t('The date the file was uploaded.'),
158
    'field' => array(
159
      'handler' => 'views_handler_field_date',
160
      'click sortable' => TRUE,
161
    ),
162
    'sort' => array(
163
      'handler' => 'views_handler_sort_date',
164
    ),
165
    'filter' => array(
166
      'handler' => 'views_handler_filter_date',
167
    ),
168
  );
169

    
170
  // User ID / 'uid'.
171
  $data['file_managed']['uid'] = array(
172
    'title' => t('User who uploaded'),
173
    'help' => t('The user that uploaded the file.'),
174
    'relationship' => array(
175
      'title' => t('User who uploaded'),
176
      'label' => t('User who uploaded'),
177
      'base' => 'users',
178
      'base field' => 'uid',
179
    ),
180
  );
181

    
182
  // ----------------------------------------------------------------------
183
  // file_usage table.
184
  $data['file_usage']['table']['group']  = t('File Usage');
185

    
186
  // Provide field-type-things to several base tables; on the core files table
187
  // ("file_managed") so that we can create relationships from files to
188
  // entities, and then on each core entity type base table so that we can
189
  // provide general relationships between entities and files.
190
  $data['file_usage']['table']['join'] = array(
191
    // Link ourself to the {file_managed} table so we can provide file->entity
192
    // relationships.
193
    'file_managed' => array(
194
      'field' => 'fid',
195
      'left_field' => 'fid',
196
    ),
197
    // Link ourself to the {node} table so we can provide node->file
198
    // relationships.
199
    'node' => array(
200
      'field' => 'id',
201
      'left_field' => 'nid',
202
      'extra' => array(array('field' => 'type', 'value' => 'node')),
203
    ),
204
    // Link ourself to the {users} table so we can provide user->file
205
    // relationships.
206
    'users' => array(
207
      'field' => 'id',
208
      'left_field' => 'uid',
209
      'extra' => array(array('field' => 'type', 'value' => 'user')),
210
    ),
211
    // Link ourself to the {comment} table so we can provide comment->file
212
    // relationships.
213
    'comment' => array(
214
      'field' => 'id',
215
      'left_field' => 'cid',
216
      'extra' => array(array('field' => 'type', 'value' => 'comment')),
217
    ),
218
    // Link ourself to the {taxonomy_term_data} table so we can provide
219
    // taxonomy_term->file relationships.
220
    'taxonomy_term_data' => array(
221
      'field' => 'id',
222
      'left_field' => 'tid',
223
      'extra' => array(array('field' => 'type', 'value' => 'taxonomy_term')),
224
    ),
225
    // Link ourself to the {taxonomy_vocabulary} table so we can provide
226
    // taxonomy_vocabulary->file relationships.
227
    'taxonomy_vocabulary' => array(
228
      'field' => 'id',
229
      'left_field' => 'vid',
230
      'extra' => array(array('field' => 'type', 'value' => 'taxonomy_vocabulary')),
231
    ),
232
  );
233

    
234
  // Provide a relationship between the files table and each entity type, and
235
  // between each entity type and the files table. Entity->file relationships
236
  // are type-restricted in the joins declared above, and file->entity
237
  // relationships are type-restricted in the relationship declarations below.
238
  // Relationships between files and nodes.
239
  $data['file_usage']['file_to_node'] = array(
240
    'title' => t('Content'),
241
    'help' => t('Content that is associated with this file, usually because this file is in a field on the content.'),
242
    // Only provide this field/relationship/etc. when the 'file_managed' base
243
    // table is present.
244
    'skip base' => array('node', 'node_revision', 'users', 'comment', 'taxonomy_term_data', 'taxonomy_vocabulary'),
245
    'real field' => 'id',
246
    'relationship' => array(
247
      'title' => t('Content'),
248
      'label' => t('Content'),
249
      'base' => 'node',
250
      'base field' => 'nid',
251
      'relationship field' => 'id',
252
      'extra' => array(array('table' => 'file_usage', 'field' => 'type', 'operator' => '=', 'value' => 'node')),
253
    ),
254
  );
255
  $data['file_usage']['node_to_file'] = array(
256
    'title' => t('File'),
257
    'help' => t('A file that is associated with this node, usually because it is in a field on the node.'),
258
    // Only provide this field/relationship/etc. when the 'node' base table is
259
    // present.
260
    'skip base' => array('file_managed', 'users', 'comment', 'taxonomy_term_data', 'taxonomy_vocabulary'),
261
    'real field' => 'fid',
262
    'relationship' => array(
263
      'title' => t('File'),
264
      'label' => t('File'),
265
      'base' => 'file_managed',
266
      'base field' => 'fid',
267
      'relationship field' => 'fid',
268
    ),
269
  );
270

    
271
  // Relationships between files and users.
272
  $data['file_usage']['file_to_user'] = array(
273
    'title' => t('User'),
274
    'help' => t('A user that is associated with this file, usually because this file is in a field on the user.'),
275
    // Only provide this field/relationship/etc. when the 'file_managed' base
276
    // table is present.
277
    'skip base' => array('node', 'node_revision', 'users', 'comment', 'taxonomy_term_data', 'taxonomy_vocabulary'),
278
    'real field' => 'id',
279
    'relationship' => array(
280
      'title' => t('User'),
281
      'label' => t('User'),
282
      'base' => 'users',
283
      'base field' => 'uid',
284
      'relationship field' => 'id',
285
      'extra' => array(array('table' => 'file_usage', 'field' => 'type', 'operator' => '=', 'value' => 'user')),
286
    ),
287
  );
288
  $data['file_usage']['user_to_file'] = array(
289
    'title' => t('File'),
290
    'help' => t('A file that is associated with this user, usually because it is in a field on the user.'),
291
    // Only provide this field/relationship/etc. when the 'users' base table is
292
    // present.
293
    'skip base' => array('file_managed', 'node', 'node_revision', 'comment', 'taxonomy_term_data', 'taxonomy_vocabulary'),
294
    'real field' => 'fid',
295
    'relationship' => array(
296
      'title' => t('File'),
297
      'label' => t('File'),
298
      'base' => 'file_managed',
299
      'base field' => 'fid',
300
      'relationship field' => 'fid',
301
    ),
302
  );
303

    
304
  // Relationships between files and comments.
305
  $data['file_usage']['file_to_comment'] = array(
306
    'title' => t('Comment'),
307
    'help' => t('A comment that is associated with this file, usually because this file is in a field on the comment.'),
308
    // Only provide this field/relationship/etc. when the 'file_managed' base
309
    // table is present.
310
    'skip base' => array('node', 'node_revision', 'users', 'comment', 'taxonomy_term_data', 'taxonomy_vocabulary'),
311
    'real field' => 'id',
312
    'relationship' => array(
313
      'title' => t('Comment'),
314
      'label' => t('Comment'),
315
      'base' => 'comment',
316
      'base field' => 'cid',
317
      'relationship field' => 'id',
318
      'extra' => array(array('table' => 'file_usage', 'field' => 'type', 'operator' => '=', 'value' => 'comment')),
319
    ),
320
  );
321
  $data['file_usage']['comment_to_file'] = array(
322
    'title' => t('File'),
323
    'help' => t('A file that is associated with this comment, usually because it is in a field on the comment.'),
324
    // Only provide this field/relationship/etc. when the 'comment' base table
325
    // is present.
326
    'skip base' => array('file_managed', 'node', 'node_revision', 'users', 'taxonomy_term_data', 'taxonomy_vocabulary'),
327
    'real field' => 'fid',
328
    'relationship' => array(
329
      'title' => t('File'),
330
      'label' => t('File'),
331
      'base' => 'file_managed',
332
      'base field' => 'fid',
333
      'relationship field' => 'fid',
334
    ),
335
  );
336

    
337
  // Relationships between files and taxonomy_terms.
338
  $data['file_usage']['file_to_taxonomy_term'] = array(
339
    'title' => t('Taxonomy Term'),
340
    'help' => t('A taxonomy term that is associated with this file, usually because this file is in a field on the taxonomy term.'),
341
    // Only provide this field/relationship/etc. when the 'file_managed' base
342
    // table is present.
343
    'skip base' => array('node', 'node_revision', 'users', 'comment', 'taxonomy_term_data', 'taxonomy_vocabulary'),
344
    'real field' => 'id',
345
    'relationship' => array(
346
      'title' => t('Taxonomy Term'),
347
      'label' => t('Taxonomy Term'),
348
      'base' => 'taxonomy_term_data',
349
      'base field' => 'tid',
350
      'relationship field' => 'id',
351
      'extra' => array(array('table' => 'file_usage', 'field' => 'type', 'operator' => '=', 'value' => 'taxonomy_term')),
352
    ),
353
  );
354
  $data['file_usage']['taxonomy_term_to_file'] = array(
355
    'title' => t('File'),
356
    'help' => t('A file that is associated with this taxonomy term, usually because it is in a field on the taxonomy term.'),
357
    // Only provide this field/relationship/etc. when the 'taxonomy_term_data'
358
    // base table is present.
359
    'skip base' => array('file_managed', 'node', 'node_revision', 'users', 'comment', 'taxonomy_vocabulary'),
360
    'real field' => 'fid',
361
    'relationship' => array(
362
      'title' => t('File'),
363
      'label' => t('File'),
364
      'base' => 'file_managed',
365
      'base field' => 'fid',
366
      'relationship field' => 'fid',
367
    ),
368
  );
369

    
370
  // Relationships between files and taxonomy_vocabulary items.
371
  $data['file_usage']['file_to_taxonomy_vocabulary'] = array(
372
    'title' => t('Taxonomy Vocabulary'),
373
    'help' => t('A taxonomy vocabulary that is associated with this file, usually because this file is in a field on the taxonomy vocabulary.'),
374
    // Only provide this field/relationship/etc. when the 'file_managed' base
375
    // table is present.
376
    'skip base' => array('node', 'node_revision', 'users', 'comment', 'taxonomy_term_data', 'taxonomy_vocabulary'),
377
    'real field' => 'id',
378
    'relationship' => array(
379
      'title' => t('Taxonomy Vocabulary'),
380
      'label' => t('Taxonomy Vocabulary'),
381
      'base' => 'taxonomy_vocabulary',
382
      'base field' => 'vid',
383
      'relationship field' => 'id',
384
      'extra' => array(array('table' => 'file_usage', 'field' => 'type', 'operator' => '=', 'value' => 'taxonomy_vocabulary')),
385
    ),
386
  );
387
  $data['file_usage']['taxonomy_vocabulary_to_file'] = array(
388
    'title' => t('File'),
389
    'help' => t('A file that is associated with this taxonomy vocabulary, usually because it is in a field on the taxonomy vocabulary.'),
390
    // Only provide this field/relationship/etc. when the 'taxonomy_vocabulary'
391
    // base table is present.
392
    'skip base' => array('file_managed', 'node', 'node_revision', 'users', 'comment', 'taxonomy_term_data'),
393
    'real field' => 'fid',
394
    'relationship' => array(
395
      'title' => t('File'),
396
      'label' => t('File'),
397
      'base' => 'file_managed',
398
      'base field' => 'fid',
399
      'relationship field' => 'fid',
400
    ),
401
  );
402

    
403
  // Provide basic fields from the {file_usage} table to all of the base tables
404
  // we've declared joins to (because there is no 'skip base' property on these
405
  // fields).
406
  $data['file_usage']['module'] = array(
407
    'title' => t('Module'),
408
    'help' => t('The module managing this file relationship.'),
409
    'field' => array(
410
      'handler' => 'views_handler_field',
411
      'click sortable' => TRUE,
412
    ),
413
    'filter' => array(
414
      'handler' => 'views_handler_filter_string',
415
    ),
416
    'argument' => array(
417
      'handler' => 'views_handler_argument_string',
418
    ),
419
    'sort' => array(
420
      'handler' => 'views_handler_sort',
421
    ),
422
  );
423
  $data['file_usage']['type'] = array(
424
    'title' => t('Entity type'),
425
    'help' => t('The type of entity that is related to the file.'),
426
    'field' => array(
427
      'handler' => 'views_handler_field',
428
      'click sortable' => TRUE,
429
    ),
430
    'filter' => array(
431
      'handler' => 'views_handler_filter_string',
432
    ),
433
    'argument' => array(
434
      'handler' => 'views_handler_argument_string',
435
    ),
436
    'sort' => array(
437
      'handler' => 'views_handler_sort',
438
    ),
439
  );
440
  $data['file_usage']['id'] = array(
441
    'title' => t('Entity ID'),
442
    'help' => t('The ID of the entity that is related to the file.'),
443
    'field' => array(
444
      'handler' => 'views_handler_field_numeric',
445
      'click sortable' => TRUE,
446
    ),
447
    'argument' => array(
448
      'handler' => 'views_handler_argument_numeric',
449
    ),
450
    'filter' => array(
451
      'handler' => 'views_handler_filter_numeric',
452
    ),
453
    'sort' => array(
454
      'handler' => 'views_handler_sort',
455
    ),
456
  );
457
  $data['file_usage']['count'] = array(
458
    'title' => t('Use count'),
459
    'help' => t('The number of times the file is used by this entity.'),
460
    'field' => array(
461
      'handler' => 'views_handler_field_numeric',
462
      'click sortable' => TRUE,
463
    ),
464
    'filter' => array(
465
      'handler' => 'views_handler_filter_numeric',
466
    ),
467
    'sort' => array(
468
      'handler' => 'views_handler_sort',
469
    ),
470
  );
471

    
472
  // ----------------------------------------------------------------------
473
  // System table.
474
  $data['system']['table']['group']  = t('System');
475

    
476
  // Advertise this table as a possible base table.
477
  $data['system']['table']['base'] = array(
478
    'field' => 'filename',
479
    'title' => t('Module/Theme/Theme engine'),
480
    'help' => t('Modules/Themes/Theme engines in your codebase.'),
481
  );
482

    
483
  // Fields.
484
  // - filename.
485
  $data['system']['filename'] = array(
486
    'title' => t('Module/Theme/Theme engine filename'),
487
    'help' => t('The path of the primary file for this item, relative to the Drupal root; e.g. modules/node/node.module.'),
488
    'field' => array(
489
      'handler' => 'views_handler_field',
490
      'click sortable' => TRUE,
491
    ),
492
    'argument' => array(
493
      // The field to display in the summary.
494
      'handler' => 'views_handler_argument_string',
495
      'name field' => 'filename',
496
    ),
497
    'filter' => array(
498
      'handler' => 'views_handler_filter_string',
499
    ),
500
    'sort' => array(
501
      'handler' => 'views_handler_sort',
502
    ),
503
  );
504
  // - name.
505
  $data['system']['name'] = array(
506
    'title' => t('Module/Theme/Theme engine name'),
507
    'help' => t('The name of the item; e.g. node.'),
508
    'field' => array(
509
      'handler' => 'views_handler_field',
510
      'click sortable' => TRUE,
511
    ),
512
    'argument' => array(
513
      // The field to display in the summary.
514
      'handler' => 'views_handler_argument_string',
515
      'name field' => 'name',
516
    ),
517
    'filter' => array(
518
      'handler' => 'views_handler_filter_string',
519
    ),
520
    'sort' => array(
521
      'handler' => 'views_handler_sort',
522
    ),
523
  );
524
  // - type.
525
  $data['system']['type'] = array(
526
    'title' => t('Type'),
527
    'help' => t('The type of the item, either module, theme, or theme_engine.'),
528
    'field' => array(
529
      'handler' => 'views_handler_field',
530
      'click sortable' => TRUE,
531
    ),
532
    'argument' => array(
533
      // The field to display in the summary.
534
      'handler' => 'views_handler_argument_string',
535
      'name field' => 'type',
536
    ),
537
    'filter' => array(
538
      'handler' => 'views_handler_filter_system_type',
539
    ),
540
    'sort' => array(
541
      'handler' => 'views_handler_sort',
542
    ),
543
  );
544
  // - status.
545
  $data['system']['status'] = array(
546
    'title' => t('Status'),
547
    'help' => t('Boolean indicating whether or not this item is enabled.'),
548
    'field' => array(
549
      'handler' => 'views_handler_field_boolean',
550
      'click sortable' => TRUE,
551
    ),
552
    'argument' => array(
553
      // The field to display in the summary.
554
      'handler' => 'views_handler_argument_numeric',
555
      'name field' => 'status',
556
    ),
557
    'filter' => array(
558
      'handler' => 'views_handler_filter_boolean_operator',
559
    ),
560
    'sort' => array(
561
      'handler' => 'views_handler_sort',
562
    ),
563
  );
564
  // - schema version.
565
  $data['system']['schema_version'] = array(
566
    'title' => t('Schema version'),
567
    'help' => t("The module's database schema version number. -1 if the module is not installed (its tables do not exist); 0 or the largest N of the module's hook_update_N() function that has either been run or existed when the module was first installed."),
568
    'field' => array(
569
      'handler' => 'views_handler_field_numeric',
570
      'click sortable' => TRUE,
571
    ),
572
    'argument' => array(
573
      // The field to display in the summary.
574
      'handler' => 'views_handler_argument_numeric',
575
      'name field' => 'schema_version',
576
    ),
577
    'filter' => array(
578
      'handler' => 'views_handler_filter_numeric',
579
    ),
580
    'sort' => array(
581
      'handler' => 'views_handler_sort',
582
    ),
583
  );
584

    
585
  return $data;
586
}
587

    
588
/**
589
 * Obtain a human readable label for a file's status.
590
 *
591
 * @param int $choice
592
 *   Indicate the file's status, expected to be either '0' for a temporary file
593
 *   or the value of FILE_STATUS_PERMANENT for a permanent file; any other value
594
 *   will be indicated as being 'Unknown'.
595
 *
596
 * @return string
597
 *   A string representing the file's status.
598
 */
599
function _views_file_status($choice = NULL) {
600
  $status = array(
601
    0 => t('Temporary'),
602
    FILE_STATUS_PERMANENT => t('Permanent'),
603
  );
604

    
605
  if (isset($choice)) {
606
    return isset($status[$choice]) ? $status[$choice] : t('Unknown');
607
  }
608

    
609
  return $status;
610
}