summaryrefslogtreecommitdiff
path: root/calendario.module
blob: c8e5665d22e40834c9389894f4043b30cbd23be2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php

/**
 * @file
 * Calendario de Movimentos Sociais.
 */

/**
 * Implements hook_theme()
 */
function calendario_theme($existing, $type, $theme, $path) {
  return array(
    'embed-widget' => array(
      'template'   => 'calendario-embed-widget',
      'variables'  => array('link' => NULL),
    ),
  );
}

/**
 * Implements hook_entity_info_alter()
 */
function calendario_entity_info_alter(&$entity_info) {
  $entity_info['taxonomy_term']['uri callback'] = 'calendario_taxonomy_term_uri';
}

/**
 * Include a calendar widget.
 */
function calendario_widget($view = NULL) {
  $display = $view->current_display;
  $path    = explode('/', $view->display[$display]->handler->options['path']);

  switch ($path[1]) {
    case 'dia':
    case 'semana':
    case 'mes':
    case 'ano':
      $type     = NULL;
      $period   = $path[1];
      //$date     = isset($path[2]) ? .'/'. $path[2] : '';
      $date     = isset($view->args[0]) ? '/'. $view->args[0] : '';
      $argument = NULL;
      //$link     = $period . $date;
      $link     = $period;
      break;

    default:
      $type     = $path[1];
      $period   = $path[3];
      //$date     = isset($path[4]) ? .'/'. $path[4] : '';
      $date     = isset($view->args[1]) ? '/'. $view->args[1] : '';
      //$argument = $path[2];
      $argument = isset($view->args[0]) ? '/'. $view->args[0] : '';
      //$link     = $type . $argument .'/'. $period . $date;
      $link     = $type . $argument .'/'. $period;
      break;
  }

  return theme('embed-widget', array('link' => $link));
}

/**
 * Implements hook_views_post_render()
 */
function calendario_views_post_render(&$view, &$output, &$cache) {
  if (substr($view->name, 0, 10) == 'calendario' && substr($view->name, 0, 17) != 'calendario_widget') {
    $output .= calendario_widget($view);
  }
}

/**
 * Entity uri callback.
 */
function calendario_taxonomy_term_uri($term) {
  $type = ($term->vocabulary_machine_name == 'tags') ? 'tag' : $term->vocabulary_machine_name;

  return array(
    'path' => 'calendario/'. $type .'/'. $term->name .'/mes',
  );
}