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