/[drupal]/contributions/modules/views/handlers/views_handler_argument_date.inc
ViewVC logotype

Contents of /contributions/modules/views/handlers/views_handler_argument_date.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.3 - (show annotations) (download) (as text)
Tue Mar 24 22:28:26 2009 UTC (8 months ago) by merlinofchaos
Branch: MAIN
CVS Tags: DRUPAL-6--2-7, DRUPAL-6--2-6, DRUPAL-6--2-5, DRUPAL-6--2-4, DRUPAL-6--3-0-ALPHA1, HEAD
Branch point for: DRUPAL-6--2, DRUPAL-6--3, DRUPAL-7--3
Changes since 1.2: +2 -2 lines
File MIME type: text/x-php
#350376 by pfournier: Missing "return" statement caused certain argument date validation to fail.
1 <?php
2 // $Id: views_handler_argument_date.inc,v 1.2 2008/10/07 21:26:23 merlinofchaos Exp $
3 /**
4 * Abstract argument handler for dates.
5 *
6 * Adds an option to set a default argument based on the current date.
7 *
8 * @param $arg_format
9 * The format string to use on the current time when
10 * creating a default date argument.
11 *
12 * Definitions terms:
13 * - many to one: If true, the "many to one" helper will be used.
14 * - invalid input: A string to give to the user for obviously invalid input.
15 * This is deprecated in favor of argument validators.
16 * @see views_many_to_one_helper
17 *
18 * @ingroup views_argument_handlers
19 */
20 class views_handler_argument_date extends views_handler_argument_formula {
21 var $option_name = 'default_argument_date';
22 var $arg_format = 'Y-m-d';
23
24 /**
25 * Add an option to set the default value to the current date.
26 */
27 function default_argument_form(&$form, &$form_state) {
28 parent::default_argument_form($form, $form_state);
29 $form['default_argument_type']['#options'] += array('date' => t('Current date'));
30 $form['default_argument_type']['#options'] += array('node_created' => t("Current node's creation time"));
31 $form['default_argument_type']['#options'] += array('node_changed' => t("Current node's update time")); }
32
33 /**
34 * Set the empty argument value to the current date,
35 * formatted appropriately for this argument.
36 */
37 function get_default_argument($raw = FALSE) {
38 if (!$raw && $this->options['default_argument_type'] == 'date') {
39 return date($this->arg_format, time());
40 }
41 else if (!$raw) {
42 foreach (range(1, 3) as $i) {
43 $node = menu_get_object('node', $i);
44 if (!empty($node)) {
45 continue;
46 }
47 }
48
49 if (arg(0) == 'node' && is_numeric(arg(1))) {
50 $node = node_load(arg(1));
51 }
52
53 if (empty($node)) {
54 return parent::get_default_argument();
55 }
56 else if ($this->options['default_argument_type'] == 'node_created') {
57 return date($this->arg_format, $node->created);
58 }
59 else if ($this->options['default_argument_type'] == 'node_changed') {
60 return date($this->arg_format, $node->changed);
61 }
62 }
63 else {
64 return parent::get_default_argument($raw);
65 }
66 }
67 }

  ViewVC Help
Powered by ViewVC 1.1.2