| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: views_handler_argument_date.inc,v 1.3.4.2 2010/03/11 00:49:52 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 && in_array($this->options['default_argument_type'], array('node_created', 'node_changed'))) { 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 64 return parent::get_default_argument($raw); 65 66 } 67 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |