| 1 |
<?php
|
| 2 |
// $Id: views_views_plugin_style_timeline.inc,v 1.1.2.3 2009/07/25 01:36:49 xamanu Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Timeline views style plugin
|
| 7 |
*/
|
| 8 |
|
| 9 |
define('TIMELINE_HORIZONTAL', 0);
|
| 10 |
define('TIMELINE_VERTICAL', 1);
|
| 11 |
|
| 12 |
/**
|
| 13 |
* Extending the view_plugin_style class to provide a timeline view style.
|
| 14 |
*/
|
| 15 |
class views_views_plugin_style_timeline extends views_plugin_style {
|
| 16 |
/**
|
| 17 |
* Set default options
|
| 18 |
*/
|
| 19 |
function option_definition() {
|
| 20 |
|
| 21 |
$options = parent::option_definition();
|
| 22 |
$options['display']['contains'] = array(
|
| 23 |
'type' => array('default' => TIMELINE_HORIZONTAL),
|
| 24 |
'appearance' => array(
|
| 25 |
'contains' => array(
|
| 26 |
'theme' => array('default' => 'ClassicTheme'),
|
| 27 |
'bubble_width' => array('default' => '250'),
|
| 28 |
'bubble_height' => array('default' => ''),
|
| 29 |
),
|
| 30 |
),
|
| 31 |
);
|
| 32 |
$options['bands']['contains'] = array(
|
| 33 |
'focus' => array('default' => 'today'),
|
| 34 |
'band1_unit' => array('default' => 'day'),
|
| 35 |
'band2_unit' => array('default' => 'month'),
|
| 36 |
);
|
| 37 |
$options['misc']['contains'] = array('controls' => array('default' => FALSE),);
|
| 38 |
$options['fields']['contains'] = array(
|
| 39 |
'title' => array('default' => ''),
|
| 40 |
'start' => array('default' => ''),
|
| 41 |
'end' => array('default' => ''),
|
| 42 |
'advanced' => array(
|
| 43 |
'contains' => array(
|
| 44 |
'earliestStart' => '',
|
| 45 |
'latestEnd' => '',
|
| 46 |
),
|
| 47 |
),
|
| 48 |
);
|
| 49 |
return $options;
|
| 50 |
}
|
| 51 |
|
| 52 |
/**
|
| 53 |
* Add settings for the particular timeline.
|
| 54 |
*/
|
| 55 |
function options_form(&$form, &$form_state) {
|
| 56 |
parent::options_form($form, $form_state);
|
| 57 |
$form['colors'] = array(
|
| 58 |
'#type' => 'fieldset',
|
| 59 |
'#title' => t('Grouping colors'),
|
| 60 |
'#collapsible' => TRUE, '#collapsed' => TRUE,
|
| 61 |
'#description' => 'You can define the colors that are going to be used for the grouped events. Leave blank to use standard values',
|
| 62 |
);
|
| 63 |
$form['colors']['values'] = array(
|
| 64 |
'#type' => 'textarea',
|
| 65 |
'#title' => t('Color coding'),
|
| 66 |
'#default_value' => isset($this->options['colors']['values']) ? $this->options['colors']['values'] : '',
|
| 67 |
'#description' => t('You can override the colors for your groupings. Enter one hexadecimal RGB color value per line. Examples: #FF00FF #FF0099 #998811'),
|
| 68 |
);
|
| 69 |
|
| 70 |
$form['display'] = array('#type' => 'fieldset', '#title' => t('Display settings'), '#collapsible' => TRUE, '#collapsed' => FALSE);
|
| 71 |
$form['display']['type'] = array(
|
| 72 |
'#type' => 'radios',
|
| 73 |
'#title' => t('Timeline type'),
|
| 74 |
'#options' => array(TIMELINE_HORIZONTAL => t('Horizontal'), TIMELINE_VERTICAL => t('Vertical')),
|
| 75 |
'#default_value' => $this->options['display']['type'],
|
| 76 |
);
|
| 77 |
$form['display']['width'] = array(
|
| 78 |
'#type' => 'textfield',
|
| 79 |
'#title' => t('Width'),
|
| 80 |
'#default_value' => isset($this->options['display']['width']) ? $this->options['display']['width'] : variable_get('timeline_default_width', '100%'),
|
| 81 |
'#size' => 6,
|
| 82 |
'#maxlength' => 6,
|
| 83 |
'#description' => t('The width of the timeline (in units of em, px or %), e.g. 600px or 90%. Leave blank to use default value.'),
|
| 84 |
);
|
| 85 |
$form['display']['height'] = array(
|
| 86 |
'#type' => 'textfield',
|
| 87 |
'#title' => t('Height'),
|
| 88 |
'#default_value' => isset($this->options['display']['height']) ? $this->options['display']['height'] : variable_get('timeline_default_height', '400px'),
|
| 89 |
'#size' => 6,
|
| 90 |
'#maxlength' => 6,
|
| 91 |
'#description' => t('The height of the timeline (in units of em, px or %), e.g. 400px. Leave blank to use default value.'),
|
| 92 |
);
|
| 93 |
// Appearance settings
|
| 94 |
// TODO make theme options flexible
|
| 95 |
$form['display']['appearance'] = array('#type' => 'fieldset', '#title' => t('Appearance and themes'), '#collapsible' => TRUE, '#collapsed' => TRUE);
|
| 96 |
$form['display']['appearance']['theme'] = array(
|
| 97 |
'#type' => 'select',
|
| 98 |
'#title' => t('Theme'),
|
| 99 |
'#default_value' => $this->options['display']['appearance']['theme'],
|
| 100 |
'#options' => timeline_available_themes(),
|
| 101 |
'#description' => t('Select a theme. You can create our own themes. Read documentation.'),
|
| 102 |
);
|
| 103 |
$form['display']['appearance']['bubble_width'] = array(
|
| 104 |
'#type' => 'textfield',
|
| 105 |
'#title' => t('Width of bubbles'),
|
| 106 |
'#default_value' => $this->options['display']['appearance']['bubble_width'],
|
| 107 |
'#size' => 6,
|
| 108 |
'#maxlength' => 6,
|
| 109 |
'#description' => t('The width of the bubbles in the timeline (in units of px), e.g. 250. Leave blank to use default value from theme.'),
|
| 110 |
);
|
| 111 |
$form['display']['appearance']['bubble_height'] = array(
|
| 112 |
'#type' => 'textfield',
|
| 113 |
'#title' => t('Max height of bubbles'),
|
| 114 |
'#default_value' => $this->options['display']['appearance']['bubble_height'],
|
| 115 |
'#size' => 6,
|
| 116 |
'#maxlength' => 6,
|
| 117 |
'#description' => t('The maximum height of the bubbles in the timeline (in units of px), e.g. 400 (Scrollbar will be added for taller bubbles). Leave blank to let the bubbles scale automatically.'),
|
| 118 |
);
|
| 119 |
|
| 120 |
$handlers = $this->display->handler->get_handlers('field');
|
| 121 |
if (empty($handlers)) {
|
| 122 |
$form['error_markup'] = array(
|
| 123 |
'#value' => t('You need at least one field before you can configure your field settings'),
|
| 124 |
'#prefix' => '<div class="error form-item description">',
|
| 125 |
'#suffix' => '</div>',
|
| 126 |
);
|
| 127 |
}
|
| 128 |
else {
|
| 129 |
// Fields
|
| 130 |
$field_names = array('' => '--');
|
| 131 |
$date_field_names = array('' => '--');
|
| 132 |
$supported_date_handlers = array(
|
| 133 |
'views_handler_field_date',
|
| 134 |
'date_handler_field_multiple',
|
| 135 |
);
|
| 136 |
|
| 137 |
foreach ($handlers as $field => $handler) {
|
| 138 |
$field_names[$field] = $handler->ui_name();
|
| 139 |
if ($label = $handler->label()) {
|
| 140 |
$field_names[$field] .= " (\"$label\")";
|
| 141 |
}
|
| 142 |
if (in_array(get_class($handler), $supported_date_handlers)) {
|
| 143 |
$date_field_names[$field] = $field_names[$field];
|
| 144 |
}
|
| 145 |
}
|
| 146 |
|
| 147 |
$form['fields'] = array(
|
| 148 |
'#type' => 'fieldset',
|
| 149 |
'#title' => 'Field usage',
|
| 150 |
'#description' => t('Select the fields that contain the title,
|
| 151 |
start time and end time of each item. If selected,
|
| 152 |
the class field will be used to apply a class to
|
| 153 |
each point. Remaining fields will be available as
|
| 154 |
"content" of the item.'),
|
| 155 |
'#collapsible' => TRUE,
|
| 156 |
'#collapsed' => FALSE,
|
| 157 |
);
|
| 158 |
|
| 159 |
$form['fields']['title'] = array(
|
| 160 |
'#type' => 'select',
|
| 161 |
'#title' => 'Title',
|
| 162 |
'#options' => $field_names,
|
| 163 |
'#default_value' => $this->options['fields']['title'],
|
| 164 |
'#required' => TRUE,
|
| 165 |
);
|
| 166 |
|
| 167 |
$form['fields']['start'] = array(
|
| 168 |
'#type' => 'select',
|
| 169 |
'#title' => 'Start',
|
| 170 |
'#options' => $date_field_names,
|
| 171 |
'#default_value' => $this->options['fields']['start'],
|
| 172 |
'#required' => TRUE,
|
| 173 |
);
|
| 174 |
|
| 175 |
$form['fields']['end'] = array(
|
| 176 |
'#type' => 'select',
|
| 177 |
'#title' => 'End',
|
| 178 |
'#options' => $date_field_names,
|
| 179 |
'#default_value' => $this->options['fields']['end'],
|
| 180 |
);
|
| 181 |
|
| 182 |
$form['fields']['advanced'] = array(
|
| 183 |
'#type' => 'fieldset',
|
| 184 |
'#title' => t('Advanced visualization settings'),
|
| 185 |
'#collapsible' => TRUE, '#collapsed' => TRUE,
|
| 186 |
'#description' => t('For more information on these fields visit !url', array('!url' => l(t('http://wiki.github.com/xamanu/Drupal-Timeline'), 'http://wiki.github.com/xamanu/Drupal-Timeline'))),
|
| 187 |
);
|
| 188 |
$form['fields']['advanced']['earliestStart'] = array(
|
| 189 |
'#type' => 'select',
|
| 190 |
'#title' => t('Earliest start'),
|
| 191 |
'#options' => $date_field_names,
|
| 192 |
'#default_value' => $this->options['fields']['advanced']['earliestStart'],
|
| 193 |
);
|
| 194 |
|
| 195 |
$form['fields']['advanced']['latestEnd'] = array(
|
| 196 |
'#type' => 'select',
|
| 197 |
'#title' => t('Latest end'),
|
| 198 |
'#options' => $date_field_names,
|
| 199 |
'#default_value' => $this->options['fields']['advanced']['latestEnd'],
|
| 200 |
);
|
| 201 |
}
|
| 202 |
|
| 203 |
// Band/interval settings
|
| 204 |
$form['bands'] = array('#type' => 'fieldset', '#title' => t('Band/interval settings'), '#collapsible' => TRUE, '#collapsed' => FALSE);
|
| 205 |
$intervals = array('second' => t('Second'), 'minute' => t('Minute'), 'hour' => t('Hour'), 'day' => t('Day'), 'week' => t('Week'), 'month' => t('Month'), 'year' => t('Year'), 'decade' => t('Decade'), 'century' => t('Century'), 'millennium' => t('Millennium'));
|
| 206 |
$form['bands']['band1_unit'] = array(
|
| 207 |
'#type' => 'select',
|
| 208 |
'#title' => t('Main band interval unit'),
|
| 209 |
'#default_value' => $this->options['bands']['band1_unit'],
|
| 210 |
'#options' => $intervals,
|
| 211 |
'#description' => t(''),
|
| 212 |
);
|
| 213 |
$form['bands']['band2_unit'] = array(
|
| 214 |
'#type' => 'select',
|
| 215 |
'#title' => t('Summary band interval unit'),
|
| 216 |
'#default_value' => $this->options['bands']['band2_unit'],
|
| 217 |
'#options' => array_merge(array('' => t('Not displayed')), $intervals),
|
| 218 |
'#description' => t(''),
|
| 219 |
);
|
| 220 |
$form['bands']['focus'] = array(
|
| 221 |
'#type' => 'select',
|
| 222 |
'#title' => t('Initial date focus'),
|
| 223 |
'#options' => array('today' => t('The current date'), 'first' => t('First event in timeline'), 'last' => t('Last event in timeline'), 'custom' => t('Custom')),
|
| 224 |
'#default_value' => $this->options['bands']['focus'],
|
| 225 |
'#description' => t('Determines which event or date the timeline view should initially be centered on after it has loaded. Leave blank to use default value.'),
|
| 226 |
);
|
| 227 |
$form['bands']['focus_custom'] = array(
|
| 228 |
'#type' => 'textfield',
|
| 229 |
'#title' => t('Custom inicial date focus'),
|
| 230 |
'#default_value' => isset($this->options['bands']['focus_custom']) ? $this->options['bands']['focus_custom'] : '',
|
| 231 |
'#process' => array('views_process_dependency'),
|
| 232 |
'#dependency' => array('edit-style-options-bands-focus' => array('custom')),
|
| 233 |
'#description' => t('Please enter a custom inicial date to focus the timeline on.') .' '. t('Format: %time.', array('%time' => format_date(time(), 'custom', 'Y-m-d H:i:s O'))),
|
| 234 |
);
|
| 235 |
/* js is unstable within timeline. maybe next version the simile grup is going to fix this. - fd
|
| 236 |
$form['limit'] = array('#type' => 'fieldset', '#title' => t('Limit timeline bands'), '#collapsible' => TRUE, '#collapsed' => TRUE);
|
| 237 |
$form['limit']['start'] = array(
|
| 238 |
'#type' => 'select',
|
| 239 |
'#title' => t('Timeline start date'),
|
| 240 |
'#default_value' => isset($this->options['limit']['start']) ? $this->options['limit']['start'] : '',
|
| 241 |
'#options' => array('endless' => 'Endless', 'first' => t('First event in timeline'), 'last' => t('Last event in timeline'), 'today' => t('The current date'), 'custom' => t('Custom')),
|
| 242 |
'#description' => t('Limit timeline bands to start at this defined date'),
|
| 243 |
);
|
| 244 |
|
| 245 |
$form['limit']['custom_start'] = array(
|
| 246 |
'#type' => 'textfield',
|
| 247 |
'#title' => t('Custom start date'),
|
| 248 |
'#default_value' => isset($this->options['limit']['custom_start']) ? $this->options['limit']['custom_start'] : '',
|
| 249 |
'#process' => array('views_process_dependency'),
|
| 250 |
'#dependency' => array('edit-style-options-limit-start' => array('custom')),
|
| 251 |
'#description' => t('Please enter a custom end date for the timeline.') .' '. t('Format: %time.', array('%time' => format_date(time(), 'custom', 'Y-m-d H:i:s O'))),
|
| 252 |
);
|
| 253 |
|
| 254 |
$form['limit']['end'] = array(
|
| 255 |
'#type' => 'select',
|
| 256 |
'#title' => t('Timeline end date'),
|
| 257 |
'#default_value' => isset($this->options['limit']['end']) ? $this->options['limit']['end'] : '',
|
| 258 |
'#options' => array('endless' => 'Endless', 'first' => t('First event in timeline'), 'last' => t('Last event in timeline'), 'today' => t('The current date'), 'custom' => t('Custom')),
|
| 259 |
'#description' => t('Limit timeline bands to end at this defined date'),
|
| 260 |
);
|
| 261 |
$form['limit']['custom_end'] = array(
|
| 262 |
'#type' => 'textfield',
|
| 263 |
'#title' => t('Custom end date'),
|
| 264 |
'#default_value' => isset($this->options['limit']['custom_end']) ? $this->options['limit']['custom_end'] : '',
|
| 265 |
'#process' => array('views_process_dependency'),
|
| 266 |
'#dependency' => array('edit-style-options-limit-end' => array('custom')),
|
| 267 |
'#description' => t('Please enter a custom end date for the timeline.') .' '. t('Format: %time.', array('%time' => format_date(time(), 'custom', 'Y-m-d H:i:s O'))),
|
| 268 |
);
|
| 269 |
|
| 270 |
/* DEPRECATED: Controls -fd
|
| 271 |
// Miscellanous settings
|
| 272 |
$form['misc'] = array('#type' => 'fieldset', '#title' => t('TODO: Miscellaneous settings'), '#collapsible' => TRUE, '#collapsed' => TRUE);
|
| 273 |
$form['misc']['controls'] = array(
|
| 274 |
'#type' => 'radios',
|
| 275 |
'#title' => t('Enable controls'),
|
| 276 |
'#default_value' => $this->options['misc']['controls'],
|
| 277 |
'#options' => array(FALSE => t('Disabled'), TRUE => t('Enabled')),
|
| 278 |
'#description' => t('Whether to display filtering and highlighting controls under the timeline. Not recommended for block mode.'),
|
| 279 |
);
|
| 280 |
*/
|
| 281 |
}
|
| 282 |
|
| 283 |
/**
|
| 284 |
* Render the timeline style.
|
| 285 |
* Data for the simile timeline is getting collected within the view
|
| 286 |
*/
|
| 287 |
function render() {
|
| 288 |
|
| 289 |
// Load only when neccessary
|
| 290 |
module_load_include('inc', 'timeline', 'classes/Timeline.class');
|
| 291 |
module_load_include('inc', 'timeline', 'classes/TimelineEvent.class');
|
| 292 |
|
| 293 |
// Group the rows according to the grouping field, if specified.
|
| 294 |
$sets = $this->render_grouping($this->view->result, $this->options['grouping']);
|
| 295 |
|
| 296 |
// Build data for timeline
|
| 297 |
$timeline = new Timeline($this->view, $sets);
|
| 298 |
$timeline->timelineToJS();
|
| 299 |
|
| 300 |
if (variable_get('timeline_debug', FALSE)) {
|
| 301 |
$this->options['debug'] = $timeline->debug();
|
| 302 |
}
|
| 303 |
// options that are used for template preprocessor
|
| 304 |
$this->options['timeline'] = array(
|
| 305 |
'class' => $this->view->name,
|
| 306 |
'width' => _timeline_to_dim($this->view->style_options['display']['width']),
|
| 307 |
'height' => _timeline_to_dim($this->view->style_options['display']['height']),
|
| 308 |
'align' => '',
|
| 309 |
'controls' => FALSE, // $this->view->style_options['misc']['controls'],
|
| 310 |
'theme' => $this->options['display']['appearance']['theme'],
|
| 311 |
);
|
| 312 |
return theme($this->theme_functions(), $this->view, $this->options);
|
| 313 |
}
|
| 314 |
}
|