histogram: Make histograms crash less
[ninja.git] / application / controllers / tac.php
blobf5dd6871778421ad5c278fd0cfa924829c4d739f
1 <?php defined('SYSPATH') OR die('No direct access allowed.');
2 /**
3 * Tactical overview controller
4 * Requires authentication
6 * op5, and the op5 logo are trademarks, servicemarks, registered servicemarks
7 * or registered trademarks of op5 AB.
8 * All other trademarks, servicemarks, registered trademarks, and registered
9 * servicemarks mentioned herein may be the property of their respective owner(s).
10 * The information contained herein is provided AS IS with NO WARRANTY OF ANY
11 * KIND, INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY, AND FITNESS FOR A
12 * PARTICULAR PURPOSE.
14 class Tac_Controller extends Authenticated_Controller {
15 public function __call($method, $args)
17 $this->template->content = $this->add_view('tac/index');
18 $this->template->title = _('Monitoring ยป Tactical overview');
19 $this->xtra_js[] = $this->add_path('/js/widgets.js');
20 $this->template->disable_refresh = true;
22 # make sure we have this done before letting widgets near
23 $model = Current_status_Model::instance();
24 $model->analyze_status_data();
26 # fetch data for all widgets
27 $widget_objs = Ninja_widget_Model::fetch_all(Router::$controller.'/'.Router::$method);
28 $db_widgets = widget::add_widgets(Router::$controller.'/'.Router::$method, $widget_objs, $this);
30 if (empty($db_widgets) && $method=='index') {
31 /* No Empty defalut tac isn't allowed, populate with the set of widgets */
32 foreach ($widget_objs as $obj) {
33 $obj->save();
35 $db_widgets = widget::add_widgets(Router::$controller.'/'.Router::$method, $widget_objs, $this);
38 if(empty($db_widgets)) {
39 /* Force the widgets variable to be an array...
40 * empty array kohana-style is defined as false, by some wierd
41 * reason
43 $db_widgets = array();
46 $tac_column_count_str = config::get('tac.column_count', 'tac/'.$method);
48 $tac_column_count = array_map('intval',explode(',',$tac_column_count_str));
49 $n_placeholders = array_sum( $tac_column_count );
51 $widgets = array();
52 $unknown_widgets = array();
54 foreach( $db_widgets as $placeholder => $widgetlist ) {
55 $id = false;
56 if( preg_match( '/^widget-placeholder([0-9]*)$/', $placeholder, $matches ) ) {
57 $id = intval($matches[1]);
58 } if( is_numeric( $placeholder ) ) {
59 $id = intval($placeholder);
61 if( $id !== false && $id >= 0 && $id < $n_placeholders ) {
62 if( !isset( $widgets[$id] ) )
63 $widgets[$id] = array();
64 $widgets[$id] = array_merge( $widgets[$id], $widgetlist );
65 } else {
66 $unknown_widgets = array_merge( $unknown_widgets, $widgetlist );
70 $placeholder_id = 0;
71 foreach( $unknown_widgets as $name => $widget ) {
72 $widgets[$placeholder_id][$name] = $widget;
73 $placeholder_id = ($placeholder_id+1)%$n_placeholders;
76 $this->template->content->widgets = $widgets;
77 $this->template->content->tac_column_count = $tac_column_count;
78 $this->template->widgets = $widget_objs;
79 $this->template->inline_js = $this->inline_js;