Projet

Général

Profil

Paste
Télécharger (2,26 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / date / date.diff.inc @ 599a39cd

1
<?php
2

    
3
/**
4
 * @file
5
 * Provide diff field functions for the Date module.
6
 */
7

    
8
/**
9
 * Diff field callback for parsing date fields comparative values.
10
 */
11
function date_field_diff_view($items, $context) {
12
  $diff_items = array();
13
  $display = $context['display'];
14
  $display['settings']['format_type'] = $context['settings']['format_type'];
15
  $display['settings']['fromto'] = $context['settings']['fromto'];
16
  foreach ($items as $delta => $item) {
17
    $date = date_formatter_process('date_default', $context['entity_type'], $context['entity'], $context['field'], $context['instance'], $context['language'], $item, $display);
18
    switch ($display['settings']['fromto']) {
19
      case 'both':
20
        if ($date['value']['formatted'] != $date['value2']['formatted']) {
21
          $diff_items[$delta] = t('@from to @to', array(
22
            '@from' => $date['value']['formatted'],
23
            '@to' => $date['value2']['formatted'],
24
          ));
25
        }
26
        else {
27
          $diff_items[$delta] = $date['value']['formatted'];
28
        }
29
        break;
30

    
31
      case 'value':
32
      case 'value2':
33
        $diff_items[$delta] = $date[$display['settings']['fromto']]['formatted'];
34
        break;
35
    }
36
  }
37
  return $diff_items;
38
}
39

    
40
/**
41
 * Provide default field comparison options.
42
 */
43
function date_field_diff_default_options($field_type) {
44
  return array(
45
    'format_type' => 'long',
46
    'fromto' => 'both',
47
  );
48
}
49

    
50
/**
51
 * Provide a form for setting the field comparison options.
52
 */
53
function date_field_diff_options_form($field_type, $settings) {
54
  $options_form = array();
55

    
56
  $form['format_type'] = array(
57
    '#title' => t('Choose how render dates and times'),
58
    '#type' => 'select',
59
    '#options' => date_format_type_options(),
60
    '#default_value' => $settings['format_type'],
61
    '#description' => t('To add or edit options, visit <a href="@date-time-page">Date and time settings</a>.', array('@date-time-page' => url('admin/config/regional/date-time'))),
62
    '#weight' => 0,
63
  );
64

    
65
  $form['fromto'] = array(
66
    '#title' => t('Display'),
67
    '#type' => 'select',
68
    '#options' => array(
69
      'both' => t('Both Start and End dates'),
70
      'value' => t('Start date only'),
71
      'value2' => t('End date only'),
72
    ),
73
    '#default_value' => $settings['fromto'],
74
    '#weight' => 1,
75
  );
76

    
77
  return $options_form;
78
}