source: sipes/0.3-modules/views_semantic/views/views_galleriffic_view.tpl.php~ @ 89c313a

stable
Last change on this file since 89c313a was 89c313a, checked in by Sipes Apn <root@…>, 7 años ago

se agrego el modulo views_semantic

  • Propiedad mode establecida a 100644
File size: 4.1 KB
Línea 
1<?php
2
3/**
4 * @file
5 * Plugin theme file.
6 */
7function template_preprocess_semantic_views(&$vars) {
8  $options = $vars['options'];
9  $view = $vars['view'];
10  $fields = $view->get_items('field');
11  $data = array();
12  $highcharts_config = json_decode(file_get_contents(drupal_get_path("module", "highcharts_views") . '/defaults/bar-basic.json'));
13  $highcharts_config->chart->defaultSeriesType = $options['format']['chart_type'];
14  $highcharts_config->title->text = $options['format']['title'];
15  $highcharts_config->subtitle->text = $options['format']['subtitle'];
16
17  $highcharts_config->legend->enabled = $options['format']['legend_enabled'];
18  if ($options['format']['chart_type']!= 'pie') {
19    $highcharts_config->yAxis->title->text = $options['y_axis']['title'];
20    $highcharts_config->yAxis->title->align = $options['y_axis']['title_align'];
21    if ($options['x_axis']["reversed"] != FALSE) {
22      $highcharts_config->xAxis->reversed = TRUE;
23    }
24    if ($options['y_axis']["reversed"] != FALSE) {
25      $highcharts_config->yAxis->reversed = TRUE;
26    }
27    if ($options['format']['swap_axes'] != FALSE) {
28      $highcharts_config->chart->inverted = TRUE;
29    }
30  }
31
32  $highcharts_config->series = array();
33  $highcharts_config->xAxis->categories = array();
34  if (is_array($options)
35    && is_array($options['x_axis']['dataset_data'])
36    && is_array($fields)) {
37    foreach ($options['x_axis']['dataset_data'] as $key) {
38      if ($key != FALSE) {
39        $vars['fields'][$key] = $fields[$key];
40      }
41    }
42  }
43
44  $highcharts_config->xAxis->categories = array();
45  foreach ($view->style_plugin->render_tokens as $result_index => $row) {
46    foreach ($row as $field_name => $field) {
47      $f = str_replace(array('[',']'), '', $field_name);
48      if ($options['x_axis']['dataset_data'][$f]) {
49        $data[$f][] = (float)$field;
50      }
51    }
52    if (!empty($options['x_axis']['dataset_label'])) {
53      $highcharts_config->xAxis->categories[] = $row["[".$options['x_axis']['dataset_label']."]"];             
54    }
55  }
56  if (function_exists("highcharts_series_" . $options['format']['chart_type'])) {
57    // If there's a specialized data writer, return data from data writer.
58    $highcharts_config->series = array(call_user_func("highcharts_views_series_".$options['format']['chart_type'], $data, $fields, $options));
59  }
60  else {
61    // Get a standard series.
62    $highcharts_config->series = highcharts_views_series($data, $vars['fields']);
63  }
64
65  // Render the chart options object, and retrieve the chart id.
66  highcharts_render($highcharts_config);
67  // Define required and optional chart container attributes.
68  $attributes = array(
69    // Required chart id passed by reference.
70    'id' => $highcharts_config->chart->renderTo,
71    // @todo add optional views config for styles or any other valid attribute.
72    // Example: 'style' => 'height: 400px;'
73  );
74
75  $vars['attributes'] = $attributes;
76}
77
78/**
79 * Standard highcharts views series data writer.
80 *
81 * @param array $data
82 * @param array $fields
83 *
84 * @return
85 *   The highcharts series data object.
86 */
87function highcharts_views_series($data, $fields) {
88  $toReturn = array();
89
90  foreach ($fields as $key => $field) {
91    $item = new stdClass;
92    $item->name = (array_key_exists("label", $field)) ? $field['label'] : $field['id'];
93    $item->data = $data[$key];
94    $toReturn[] = $item;
95  }
96
97  return $toReturn;
98}
99
100/**
101 * Specialized pie highcharts views series data writer.
102 *
103 * @param array $data
104 * @param array $fields
105 * @param array $options
106 *
107 * @return
108 *   The highcharts series data object.
109 */
110function highcharts_views_series_pie($data, $fields, $options) {
111  $toReturn = new StdClass();
112  $toReturn->type = $options['format']['chart_type'];
113  $toReturn->name = $options['format']['title'];
114  $toReturn->data = array();
115
116  foreach ($fields as $key => $field) {
117    $pie = 0;
118    if (array_key_exists($key, $data)) {
119      foreach($data[$key] as $value) {
120        if (is_numeric($value)) {
121          $pie += $value;
122        }
123      }
124      $toReturn->data[] = array(
125        array_key_exists("label", $field) ? $field['label'] : $field['id'],
126        $pie,
127      );
128    }
129  }
130
131  return $toReturn;
132}
Nota: Vea TracBrowser para ayuda de uso del navegador del repositorio.