1 | <?php |
---|
2 | /** |
---|
3 | * @file |
---|
4 | * Date navigation style handler. |
---|
5 | */ |
---|
6 | |
---|
7 | /** |
---|
8 | * Style plugin to create date back/next navigation. |
---|
9 | * |
---|
10 | * The style plugin passes some argument values to the theme, and |
---|
11 | * ensures that the date argument is present and that the default |
---|
12 | * value is set to the current date. |
---|
13 | */ |
---|
14 | class date_navigation_plugin_style extends views_plugin_style { |
---|
15 | |
---|
16 | /** |
---|
17 | * Style validation. |
---|
18 | */ |
---|
19 | function validate() { |
---|
20 | $errors = parent::validate(); |
---|
21 | |
---|
22 | $arguments = $this->display->handler->get_option('arguments'); |
---|
23 | $count = 0; |
---|
24 | $found = FALSE; |
---|
25 | foreach ($arguments as $id => $argument) { |
---|
26 | if ($argument['field'] == 'date_argument') { |
---|
27 | if ($count > 0) { |
---|
28 | $errors[] = t('The %style cannot use more than one Date: Date argument.', array('%style' => $this->definition['title'])); |
---|
29 | } |
---|
30 | elseif ($argument['default_argument_type'] != 'date') { |
---|
31 | $errors[] = t('The %style requires the Date: Date argument be set to default to the current date.', array('%style' => $this->definition['title'])); |
---|
32 | } |
---|
33 | $count++; |
---|
34 | $found = TRUE; |
---|
35 | } |
---|
36 | } |
---|
37 | if (!$found) { |
---|
38 | $errors[] = t('The %style requires the Date: Date argument.', array('%style' => $this->definition['title'])); |
---|
39 | } |
---|
40 | return $errors; |
---|
41 | } |
---|
42 | |
---|
43 | function query() { |
---|
44 | require_once('./'. drupal_get_path('module', 'date_api') .'/date_api_sql.inc'); |
---|
45 | |
---|
46 | // Bring the argument information into the view so our theme can access it. |
---|
47 | $i = 0; |
---|
48 | foreach ($this->view->argument as $id => $argument) { |
---|
49 | if ($id == 'date_argument') { |
---|
50 | $this->view->date_info->granularity = $argument->granularity; |
---|
51 | $this->view->date_info->date_arg = !empty($this->view->args) && count($this->view->args) > $argument->position ? $this->view->args[$argument->position] : ''; |
---|
52 | $this->view->date_info->date_arg_pos = $i; |
---|
53 | $this->view->date_info->year = isset($argument->year) ? $argument->year : NULL; |
---|
54 | $this->view->date_info->month = isset($argument->month) ? $argument->month: NULL; |
---|
55 | $this->view->date_info->day = isset($argument->day) ? $argument->day : NULL; |
---|
56 | $this->view->date_info->week = isset($argument->week) ? $argument->week : NULL; |
---|
57 | $this->view->date_info->min_date = $argument->min_date; |
---|
58 | $this->view->date_info->max_date = $argument->max_date; |
---|
59 | $this->view->date_info->url = $this->view->get_url(); |
---|
60 | } |
---|
61 | $i++; |
---|
62 | } |
---|
63 | |
---|
64 | // bring the node type into the query so we can use it in the theme |
---|
65 | $this->view->query->add_field('node', 'type'); |
---|
66 | |
---|
67 | } |
---|
68 | } |
---|