summaryrefslogtreecommitdiff
path: root/timelinejs.module
blob: a49c04f509eac52a7cd61f79e832c8c7c2425976 (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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php

/**
 * @file
 * TimelineJS module.
 */

/**
 * Implements hook_field_info().
 */
/*
function timelinejs_field_info() {
  return array(
    'timelinejs' => array(
      'label'             => t('TimelineJS item'),
      'description'       => t('An item in a timeline'),
      'settings'          => array(),
      'instance_settings' => array(),
      'default_widget'    => 'timelinejs_item',
      'default_formatter' => 'timelinejs_default',
    ),
  );
}
 */

/**
 * Implements hook_node_view().
 */
function timelinejs_node_view($node, $view_mode, $langcode) {
  if ($node->type == 'timeline' && $view_mode == 'full') {
    $node->content['timeline']['#markup'] = timelinejs($node->nid);
  }
}

/**
 * Implements hook_node_view_alter.
 */
function timelinejs_node_view_alter(&$build) {
}

/**
 * Implements hook_menu()
 */
function timelinejs_menu() {
  $items['timelinejs/json'] = array(
    'page callback'    => 'timelinejs_json',
    'access arguments' => array('access content'),
    'type'             => MENU_CALLBACK,
  );

  $items['timeline'] = array(
    'page callback'    => 'timelinejs',
    'access arguments' => array('access content'),
    'type'             => MENU_CALLBACK,
  );

  return $items;
}

/**
 * Implements hook_theme()
 */
function timelinejs_theme($existing, $type, $theme, $path) {
  return array(
    'timelinejs' => array(
      'template'  => 'timelinejs',
      'variables' => array(
        'width'         => NULL,
        'height'        => NULL,
        'source'        => NULL,
        'start_at_end'  => 'false',
        'hash_bookmark' => 'true',
        'css'           => NULL,
        'js'            => '/sites/all/libraries/timelinejs/compiled/js/timeline.js',
        'lang'          => '/sites/all/libraries/timelinejs/compiled/js/locale/pt-br.js',
      ),
    ),
    'timelinejs_json' => array(
      'template'  => 'timelinejs_json',
      'variables' => array('headline', 'date', 'text', 'media', 'events'),
    ),
  );
}

/**
 * Get a score nid from an issue nid.
 */
function timelinejs_load_events($nid) {
  $query = db_select('field_data_field_timeline', 't');

  // Basic query.
  $query
    ->fields('t', array('entity_id'))
    ->condition('t.bundle', 'evento')
    ->condition('t.field_timeline_target_id', $nid, '=');

  $result = $query->execute();

  return $result->fetchAll();
}

/**
 * Menu callback.
 * 
 * @todo
 */
function timelinejs_json($nid) {
  // Sanitization and basic data.
  $nid    = (int) $nid;
  $events = timelinejs_load_events($nid);

  print theme('timelinejs_json', array(
    'headline' => $headline,
    'date'     => $date,
    'text'     => $text,
    'media'    => $media,
    'events'   => array(),
  ));

  # Avoid themable output.
  exit;
}

/**
 * Menu callback.
 *
 * @todo
 */
function timelinejs($nid) {
  return theme('timelinejs', array(
    'width'  => '960px',
    'height' => '500px',
    'source' => '/sites/boletim/files/timeline-saude-indigena_2.json',
    'css'    => '/sites/boletim/themes/boletimclean/timeline.css'
  ));
}