1 <?php
defined('SYSPATH') OR die('No direct access allowed.');
8 class gridstat_Widget
extends widget_Base
{
10 * Set if this widget is duplicatable
12 protected $duplicatable = true;
15 * An array containing the settings for this widget; which filters to use
17 protected $settings = false;
20 * Constructor. This should be overloaded, to upadte the settings-attribute
21 * when making a custom widget of this type
23 public function __construct($widget_model) {
24 parent
::__construct($widget_model);
25 $this->settings
= array();
29 * Disable everything configurable. This is useful when including the widget with generetated parameters from a controller.
31 public function set_fixed() {
32 $this->movable
= false;
33 $this->removable
= false;
34 $this->closeconfirm
= false;
35 $this->editable
= false;
36 $this->duplicatable
= false;
40 * Load the options for this widget.
42 public function options() {
43 $options = parent
::options();
47 private function grab_filters( $arr ) {
49 foreach( $arr as $key => $value ) {
50 if( is_array( $value ) ) {
51 $filters = array_merge($filters, $this->grab_filters($value));
52 } else if( $key === 'filter' ) {
59 private function apply_filters( $arr, $results ) {
61 foreach( $arr as $key => $value ) {
62 if( is_array( $value ) ) {
63 $res = $this->apply_filters($value, $results);
65 if( $res !== false ) {
66 if( $key === 'fields' ) {
67 if( count($res) == 0 ) {
71 $filters[$key] = $res;
74 $filters[$key] = $value;
76 if( $key === 'filter' ) {
77 $filters['count'] = $results[$value];
78 if( $results[$value] == 0 ) {
88 * Fetch the data and show the widget
90 public function index() {
92 $filters = $this->grab_filters($this->settings
);
94 foreach( $filters as $filter ) {
95 $results[$filter] = count(ObjectPool_Model
::get_by_query($filter));
97 $this->data
= $this->apply_filters($this->settings
, $results);
98 if(empty($this->data
)) {
101 'icon' => 'shield-not-disabled',
108 } catch( ORMException
$e ) {
109 require('view_error.php');
110 } catch( op5LivestatusException
$e ) {
111 require('view_error.php');
112 } catch( Exception
$e ) {