Projet

Général

Profil

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

root / drupal7 / sites / all / modules / views / modules / profile / views_handler_field_profile_date.inc @ 5d12d676

1
<?php
2

    
3
/**
4
 * @file
5
 * Definition of views_handler_field_profile_date.
6
 */
7

    
8
/**
9
 * Field handler display a profile date.
10
 *
11
 * The dates are stored serialized, which makes them mostly useless from
12
 * SQL. About all we can do is unserialize and display them.
13
 *
14
 * @ingroup views_field_handlers
15
 */
16
class views_handler_field_profile_date extends views_handler_field_date {
17

    
18
  /**
19
   * {@inheritdoc}
20
   */
21
  public function options_form(&$form, &$form_state) {
22
    parent::options_form($form, $form_state);
23
    // we can't do "time ago" so remove it from the form.
24
    unset($form['date_format']['#options']['time ago']);
25
  }
26

    
27
  /**
28
   * Display a profile field of type 'date'.
29
   */
30
  public function render($values) {
31
    $value = $this->get_value($values);
32
    if (!$value) {
33
      return;
34
    }
35
    $value = unserialize($value);
36
    $format = $this->options['date_format'];
37
    switch ($format) {
38
      case 'custom':
39
        $format = $this->options['custom_date_format'];
40
        break;
41

    
42
      case 'small':
43
        $format = variable_get('date_format_short', 'm/d/Y - H:i');
44
        break;
45

    
46
      case 'medium':
47
        $format = variable_get('date_format_medium', 'D, m/d/Y - H:i');
48
        break;
49

    
50
      case 'large':
51
        $format = variable_get('date_format_long', 'l, F j, Y - H:i');
52
        break;
53
    }
54

    
55
    // Note: Avoid PHP's date() because it does not handle dates before
56
    // 1970 on Windows. This would make the date field useless for e.g.
57
    // birthdays.
58
    // But we *can* deal with non-year stuff.
59
    $date = gmmktime(0, 0, 0, $value['month'], $value['day'], $value['year']);
60

    
61
    $replace = array(
62
      // day.
63
      'd' => sprintf('%02d', $value['day']),
64
      'D' => NULL,
65
      'l' => NULL,
66
      'N' => NULL,
67
      'S' => gmdate('S', $date),
68
      'w' => NULL,
69
      'j' => $value['day'],
70
      // month.
71
      'F' => gmdate('F', $date),
72
      'm' => sprintf('%02d', $value['month']),
73
      'M' => gmdate('M', $date),
74
      'n' => gmdate('n', $date),
75

    
76
      'Y' => $value['year'],
77
      'y' => substr($value['year'], 2, 2),
78

    
79
      // kill time stuff.
80
      'a' => NULL,
81
      'A' => NULL,
82
      'g' => NULL,
83
      'G' => NULL,
84
      'h' => NULL,
85
      'H' => NULL,
86
      'i' => NULL,
87
      's' => NULL,
88
      ':' => NULL,
89
      'T' => NULL,
90
      ' - ' => NULL,
91
      ':' => NULL,
92
    );
93

    
94
    return strtr($format, $replace);
95
  }
96

    
97
}