Projet

Général

Profil

Révision 599a39cd

Ajouté par Assos Assos il y a environ 3 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/date/date_views/includes/date_views_argument_handler_simple.inc
1 1
<?php
2

  
2 3
/**
3 4
 * @file
4 5
 * Date API views argument handler.
5 6
 */
6 7

  
7 8
/**
8
 * Date API argument handler.
9
 * Date API views argument handler.
9 10
 */
10
// @codingStandardsIgnoreStart
11 11
class date_views_argument_handler_simple extends views_handler_argument_date {
12 12

  
13 13
  /**
14
   * Get granularity.
15
   *
16
   * Use it to create the formula and a format for the results.
14
   * {@inheritdoc}
17 15
   */
18 16
  function init(&$view, &$options) {
19 17
    parent::init($view, $options);
......
31 29
      $this->date_handler->local_timezone = date_get_timezone($field['settings']['tz_handling']);
32 30
    }
33 31
    $this->date_handler->granularity = $this->options['granularity'];
34
    // This value needs to be initialized so
35
    // it exists even if the query doesn't run.
32
    // This value needs to be initialized so it exists even if the query
33
    // doesn't run.
36 34
    $this->date_handler->placeholders = array();
37 35

  
38 36
    $this->format = $this->date_handler->views_formats($this->date_handler->granularity, 'display');
39 37
    $this->sql_format = $this->date_handler->views_formats($this->date_handler->granularity, 'sql');
40
    // $this->arg_format is the format the parent date
41
    // handler will use to create a default argument.
38
    // $this->arg_format is the format the parent date handler will use to
39
    // create a default argument.
42 40
    $this->arg_format = $this->format();
43 41

  
44
    // Identify the base table for this field.
45
    // It will be used to call for the right query field options.
42
    // Identify the base table for this field. It will be used to call for the
43
    // right query field options.
46 44
    $this->base_table = $this->table;
47

  
48 45
  }
49 46

  
50 47
  /**
......
60 57
  }
61 58

  
62 59
  /**
63
   * Set the empty argument value to the current date.
64
   *
65
   * Formatted appropriately for this argument.
60
   * {@inheritdoc}
66 61
   */
67 62
  function get_default_argument($raw = FALSE) {
68 63
    $is_default = FALSE;
......
87 82
  }
88 83

  
89 84
  /**
90
   * Default value for the date_fields option.
85
   * {@inheritdoc}
91 86
   */
92 87
  function option_definition() {
88
    // Default value for the date_fields option.
93 89
    $options = parent::option_definition();
94 90
    $options['year_range'] = array('default' => '-3:+3');
95 91
    $options['granularity'] = array('default' => 'month');
......
103 99
  }
104 100

  
105 101
  /**
106
   * Add a form element to select date_fields for this argument.
102
   * {@inheritdoc}
107 103
   */
108 104
  function options_form(&$form, &$form_state) {
109 105
    parent::options_form($form, $form_state);
......
149 145

  
150 146
    // Get default granularity options
151 147
    $options = $this->date_handler->date_parts();
148

  
152 149
    // Add the 'week' option.
153 150
    $options += array(
154 151
      'week' => t('Week', array(), array(
......
214 211
  }
215 212

  
216 213
  /**
217
   * Provide a link to the next level of the view from the summary.
214
   * {@inheritdoc}
218 215
   */
219 216
  function summary_name($data) {
220 217
    $value = $data->{$this->name_alias};
......
230 227
  }
231 228

  
232 229
  /**
233
   * Provide a title for the view based on the argument value.
230
   * {@inheritdoc}
234 231
   */
235 232
  function title() {
236 233
    $format = !empty($this->options['title_format_custom']) && !empty($this->options['title_format_custom']) ? $this->options['title_format_custom'] : $this->date_handler->views_formats($this->options['granularity'], 'display');
......
239 236
  }
240 237

  
241 238
  /**
242
   * Provide the argument to use to link from the summary to the next level.
243
   *
244
   * This will be called once per row of a summary, and used as part of
245
   * $view->get_url().
246
   *
247
   * @param object $data
248
   *   The query results for the row.
239
   * {@inheritdoc}
249 240
   */
250 241
  function summary_argument($data) {
251 242
    $format = $this->date_handler->views_formats($this->options['granularity'], 'sql');
......
258 249
  }
259 250

  
260 251
  /**
261
   * Inject a test for valid date range before the summary query.
252
   * {@inheritdoc}
262 253
   */
263 254
  function summary_query() {
264

  
265
    // @TODO The summary values are computed by the database.
266
    // Unless the database has built-in timezone handling it will use
267
    // a fixed offset, which will not be right for all dates.
268
    // The only way I can see to make this work right is to store the offset
269
    // for each date in the database so it can be added to the base
270
    // date value before the database formats the result. Because this is a huge
271
    // architectural change, it won't go in until we start a new branch.
255
    // Inject a test for valid date range before the summary query.
256
    // @todo The summary values are computed by the database. Unless the
257
    // database has built-in timezone handling it will use a fixed offset,
258
    // which will not be right for all dates. The only way I can see to make
259
    // this work right is to store the offset for each date in the database so
260
    // it can be added to the base date value before the database formats the
261
    // result. Because this is a huge architectural change, it won't go in
262
    // until we start a new branch.
272 263
    $this->formula = $this->date_handler->sql_format($this->sql_format, $this->date_handler->sql_field("***table***.$this->real_field"));
273 264
    $this->ensure_my_table();
265

  
274 266
    // Now that our table is secure, get our formula.
275 267
    $formula = $this->get_formula();
276 268

  
277
    // Add the field, give it an alias that does NOT match the actual
278
    // field name or grouping won't work right.
269
    // Add the field, give it an alias that does NOT match the actual field
270
    // name or grouping won't work right.
279 271
    $this->base_alias = $this->name_alias = $this->query->add_field(NULL, $formula, $this->field . '_summary');
280 272
    $this->query->set_count_field(NULL, $formula, $this->field);
281 273

  
......
283 275
  }
284 276

  
285 277
  /**
286
   * Inject a test for valid date range before the regular query.
287
   *
288
   * Override the parent query to be able to control the $group.
278
   * {@inheritdoc}
289 279
   */
290 280
  function query($group_by = FALSE) {
291

  
292
    // @TODO Not doing anything with $group_by yet,
293
    // need to figure out what has to be done.
294

  
281
    // Inject a test for valid date range before the regular query. Override
282
    // the parent query to be able to control the $group.
283
    // @todo Not doing anything with $group_by yet, need to figure out what has
284
    // to be done.
295 285
    if ($this->date_forbid()) {
296 286
      return;
297 287
    }
298 288

  
299
    // See if we need to reset granularity based on an argument value.
300
    // Make sure we don't try to reset to some bogus value if someone has
301
    // typed in an unexpected argument.
289
    // See if we need to reset granularity based on an argument value. Make
290
    // sure we don't try to reset to some bogus value if someone has typed in
291
    // an unexpected argument.
302 292
    if ($this->options['granularity_reset'] && $granularity = $this->date_handler->arg_granularity($this->argument)) {
303 293
      $this->date_handler->granularity = $granularity;
304 294
      $this->format = $this->date_handler->views_formats($this->date_handler->granularity, 'display');
......
308 298
    $this->ensure_my_table();
309 299
    $group = !empty($this->options['date_group']) ? $this->options['date_group'] : 0;
310 300

  
311
    // If requested, add the delta field to the view so
312
    // we can later find the value that matched our query.
301
    // If requested, add the delta field to the view so we can later find the
302
    // value that matched our query.
313 303
    if (!empty($this->options['add_delta']) && (substr($this->real_field, -6) == '_value' || substr($this->real_field, -7) == '_value2')) {
314 304
      $this->query->add_field($this->table_alias, 'delta');
315 305
      $real_field_name = str_replace(array('_value', '_value2'), '', $this->real_field);
......
324 314
    $view_max_placeholder = $this->placeholder();
325 315
    $this->date_handler->placeholders = array($view_min_placeholder => $view_min, $view_max_placeholder => $view_max);
326 316

  
327
    // Are we comparing this field only or the Start/End date range
328
    // to the view criteria?
317
    // Are we comparing this field only or the Start/End date range to the view
318
    // criteria?
329 319
    if (!empty($this->options['use_fromto'])) {
330

  
331 320
      // The simple case, match the field to the view range.
332 321
      $field = $this->date_handler->sql_field($this->table_alias . '.' . $this->real_field, NULL, $this->min_date);
333 322
      $field = $this->date_handler->sql_format($format, $field);
......
335 324

  
336 325
    }
337 326
    else {
338

  
339
      // Look for the intersection of the range
340
      // of the date field with the range of the view.
341
      // Get the Start/End values for this field.
342
      // Retrieve using the original table name.
343
      // Swap the current table name (adjusted for relationships)
344
      // into the query.
345
      // @TODO We may be able to use Views substitutions here,
346
      // investigate that later.
327
      // Look for the intersection of the range of the date field with the
328
      // range of the view. Get the Start/End values for this field. Retrieve
329
      // using the original table name. Swap the current table name (adjusted
330
      // for relationships) into the query.
331
      // @todo We may be able to use Views substitutions here, investigate that
332
      // later.
347 333
      $fields = date_views_fields($this->base_table);
348 334
      $fields = $fields['name'];
349 335
      $fromto = $fields[$this->original_table . '.' . $this->real_field]['fromto'];
......
361 347
  /**
362 348
   * Add a callback.
363 349
   *
364
   * To determine if we have moved outside
365
   * the valid date range for this argument.
350
   * To determine if we have moved outside the valid date range for this
351
   * argument.
366 352
   */
367 353
  function date_forbid() {
368 354
    if (empty($this->argument)) {
......
384 370
  }
385 371

  
386 372
}
387
// @codingStandardsIgnoreEnd

Formats disponibles : Unified diff