| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
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 */ 19 class 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 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Jul 9 18:01:44 2012 | Cross-referenced by PHPXref 0.7 |