Projet

Général

Profil

Révision b720ea3e

Ajouté par Assos Assos il y a plus de 8 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/date/date_context/plugins/date_context_date_condition.inc
1 1
<?php
2 2

  
3
/**
4
 * @file
5
 * Context date condition plugin.
6
 */
7

  
3 8
/**
4 9
 * Expose term views/term forms by vocabulary as a context condition.
5 10
 */
11
// @codingStandardsIgnoreStart
6 12
class date_context_date_condition extends context_condition_node {
7
  function condition_values() {
13

  
14
  /**
15
   * {@inheritdoc}
16
   */
17
  public function condition_values() {
8 18
    $values = array();
9 19
    $fields = field_info_fields();
10 20
    foreach ($fields as $field_name => $field) {
......
15 25
    return $values;
16 26
  }
17 27

  
18
  function options_form($context) {
28
  /**
29
   * {@inheritdoc}
30
   */
31
  public function options_form($context) {
19 32
    $defaults = $this->fetch_from_context($context, 'options');
20 33
    $options = array(
21
      '<' =>  t('Is less than'),
34
      '<' => t('Is less than'),
22 35
      '<=' => t('Is less than or equal to'),
23 36
      '>=' => t('Is greater than or equal to'),
24 37
      '>' => t('Is greater than'),
......
27 40
      'empty' => t('Is empty'),
28 41
      'not empty' => t('Is not Empty'),
29 42
    );
43
    $dependency_options = array('<', '<=', '>', '>=', '=', '!=');
44

  
30 45
    $form['operation'] = array(
31 46
      '#title' => t('Operation'),
32 47
      '#type' => 'select',
......
41 56
      '#description' => t("The value the field should contain to meet the condition. This can either be an absolute date in ISO format (YYYY-MM-DDTHH:MM:SS) or a relative string like '12AM today'. Examples: 2011-12-31T00:00:00, now, now +1 day, 12AM today, Monday next week. <a href=\"@relative_format\">More examples of relative date formats in the PHP documentation</a>.", array('@relative_format' => 'http://www.php.net/manual/en/datetime.formats.relative.php')),
42 57
      '#default_value' => isset($defaults['value']) ? $defaults['value'] : '',
43 58
      '#process' => array('ctools_dependent_process'),
44
      '#dependency' => array('edit-conditions-plugins-date-context-date-condition-options-operation' => array('<', '<=', '>', '>=', '=', '!=')),
59
      '#dependency' => array('edit-conditions-plugins-date-context-date-condition-options-operation' => $dependency_options),
45 60
    );
46 61
    return $form;
47 62
  }
48 63

  
49
  function execute($entity, $op) {
64
  /**
65
   * {@inheritdoc}
66
   */
67
  public function execute($entity, $op) {
50 68
    if (in_array($op, array('view', 'form'))) {
51 69
      foreach ($this->get_contexts() as $context) {
52 70
        $options = $this->fetch_from_context($context, 'options');
......
91 109
              str_replace('now', 'today', $options['value']);
92 110
              $date = date_create($options['value'], date_default_timezone_object());
93 111
              $compdate = $date->format(DATE_FORMAT_DATETIME);
94
              switch($options['operation']) {
112
              switch ($options['operation']) {
95 113
                case '=':
96 114
                  if ($date2 >= $compdate && $date1 <= $compdate) {
97 115
                    $this->condition_met($context, $field_name);
98 116
                  }
99 117
                  break;
118

  
100 119
                case '>':
101 120
                  if ($date1 > $compdate) {
102 121
                    $this->condition_met($context, $field_name);
103 122
                  }
104 123
                  break;
124

  
105 125
                case '>=':
106 126
                  if ($date1 >= $compdate) {
107 127
                    $this->condition_met($context, $field_name);
108 128
                  }
109 129
                  break;
130

  
110 131
                case '<':
111 132
                  if ($date2 < $compdate) {
112 133
                    $this->condition_met($context, $field_name);
113 134
                  }
114 135
                  break;
136

  
115 137
                case '<=':
116 138
                  if ($date2 <= $compdate) {
117 139
                    $this->condition_met($context, $field_name);
118 140
                  }
119 141
                  break;
142

  
120 143
                case '!=':
121 144
                  if ($date1 < $compdate || $date2 > $compdate) {
122 145
                    $this->condition_met($context, $field_name);
......
130 153
    }
131 154
  }
132 155
}
156
// @codingStandardsIgnoreEnd

Formats disponibles : Unified diff