source: sipes/modules_contrib/views/handlers/views_handler_argument_date.inc @ 65dadeb

stableversion-3.0
Last change on this file since 65dadeb was 59029b2, checked in by José Gregorio Puentes <jpuentes@…>, 8 años ago

se actualizo la version del modulo views

  • Propiedad mode establecida a 100644
File size: 3.1 KB
Línea 
1<?php
2/**
3 * Abstract argument handler for dates.
4 *
5 * Adds an option to set a default argument based on the current date.
6 *
7 * @param $arg_format
8 *   The format string to use on the current time when
9 *   creating a default date argument.
10 *
11 * Definitions terms:
12 * - many to one: If true, the "many to one" helper will be used.
13 * - invalid input: A string to give to the user for obviously invalid input.
14 *                  This is deprecated in favor of argument validators.
15 * @see views_many_to_one_helper
16 *
17 * @ingroup views_argument_handlers
18 */
19class views_handler_argument_date extends views_handler_argument_formula {
20  var $option_name = 'default_argument_date';
21  var $arg_format = 'Y-m-d';
22
23  /**
24   * Add an option to set the default value to the current date.
25   */
26  function default_argument_form(&$form, &$form_state) {
27    parent::default_argument_form($form, $form_state);
28    $form['default_argument_type']['#options'] += array('date' => t('Current date'));
29    $form['default_argument_type']['#options'] += array('node_created' => t("Current node's creation time"));
30    $form['default_argument_type']['#options'] += array('node_changed' => t("Current node's update time"));  }
31
32  /**
33   * Set the empty argument value to the current date,
34   * formatted appropriately for this argument.
35   */
36  function get_default_argument($raw = FALSE) {
37    if (!$raw && $this->options['default_argument_type'] == 'date') {
38      return date($this->arg_format, time());
39    }
40    else if (!$raw && in_array($this->options['default_argument_type'], array('node_created', 'node_changed'))) {
41      foreach (range(1, 3) as $i) {
42        $node = menu_get_object('node', $i);
43        if (!empty($node)) {
44          continue;
45        }
46      }
47
48      if (arg(0) == 'node' && is_numeric(arg(1))) {
49        $node = node_load(arg(1));
50      }
51
52      if (empty($node)) {
53        return parent::get_default_argument();
54      }
55      else if ($this->options['default_argument_type'] == 'node_created') {
56        return date($this->arg_format, $node->created);
57      }
58      else if ($this->options['default_argument_type'] == 'node_changed') {
59        return date($this->arg_format, $node->changed);
60      }
61    }
62
63    return parent::get_default_argument($raw);
64
65  }
66
67  /**
68   * The date handler provides some default argument types, which aren't argument default plugins,
69   * so addapt the export mechanism.
70   */
71  function export_plugin($indent, $prefix, $storage, $option, $definition, $parents) {
72
73    // Only use a special behaviour for the special argument types, else just
74    // use the default behaviour.
75    if ($option == 'default_argument_type') {
76      $type = 'argument default';
77      $option_name = 'default_argument_options';
78
79      $plugin = $this->get_plugin($type);
80      $name = $this->options[$option];
81      if (in_array($name, array('date', 'node_created', 'node_changed'))) {
82        // Write which plugin to use.
83        $output = $indent . $prefix . "['$option'] = '$name';\n";
84        return $output;
85      }
86    }
87    return parent::export_plugin($indent, $prefix, $storage, $option, $definition, $parents);
88  }
89}
Nota: Vea TracBrowser para ayuda de uso del navegador del repositorio.