PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 1.4.2.3
Visualizer – Tables & Charts Manager with Built-in AI Generator v1.4.2.3
4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.10.1 3.10.10 3.10.11 3.10.12 3.10.13 3.10.14 3.10.15 3.10.2 3.10.3 3.10.4 All 148 releases
visualizer / classes / Visualizer / Module / Sources.php

Sources.php in Visualizer – Tables & Charts Manager with Built-in AI Generator 1.4.2.3, at classes/Visualizer/Module/Sources.php

120 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // +----------------------------------------------------------------------+
4 // | Copyright 2013 Madpixels (email : visualizer@madpixels.net) |
5 // +----------------------------------------------------------------------+
6 // | This program is free software; you can redistribute it and/or modify |
7 // | it under the terms of the GNU General Public License, version 2, as |
8 // | published by the Free Software Foundation. |
9 // | |
10 // | This program is distributed in the hope that it will be useful, |
11 // | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 // | GNU General Public License for more details. |
14 // | |
15 // | You should have received a copy of the GNU General Public License |
16 // | along with this program; if not, write to the Free Software |
17 // | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, |
18 // | MA 02110-1301 USA |
19 // +----------------------------------------------------------------------+
20 // | Author: Eugene Manuilov <eugene@manuilov.org> |
21 // +----------------------------------------------------------------------+
22
23 /**
24 * Sources module class.
25 *
26 * @category Visualizer
27 * @package Module
28 *
29 * @since 1.1.0
30 */
31 class Visualizer_Module_Sources extends Visualizer_Module {
32
33 const NAME = __CLASS__;
34
35 /**
36 * The array of fetched sources.
37 *
38 * @since 1.1.0
39 *
40 * @access private
41 * @var array
42 */
43 private $_sources = array();
44
45 /**
46 * Constructor.
47 *
48 * @since 1.1.0
49 *
50 * @access public
51 * @param Visualizer_Plugin $plugin The instance of the plugin.
52 */
53 public function __construct( Visualizer_Plugin $plugin ) {
54 parent::__construct( $plugin );
55
56 $this->_addFilter( Visualizer_Plugin::FILTER_GET_CHART_SERIES, 'filterChartSeries', 1, 2 );
57 $this->_addFilter( Visualizer_Plugin::FILTER_GET_CHART_DATA, 'filterChartData', 1, 2 );
58 }
59
60 /**
61 * Returns appropriate source object for a chart.
62 *
63 * @since 1.1.0
64 *
65 * @access private
66 * @param int $chart_id The chart id.
67 * @return Visualizer_Source The source object if source exists, otherwise FALSE.
68 */
69 private function _getSource( $chart_id ) {
70 if ( !isset( $this->_sources[$chart_id] ) ) {
71 $class = get_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, true );
72 if ( !class_exists( $class, true ) ) {
73 return false;
74 }
75
76 $this->_sources[$chart_id] = new $class();
77 }
78
79 return $this->_sources[$chart_id];
80 }
81
82 /**
83 * Filters chart sereis.
84 *
85 * @since 1.1.0
86 *
87 * @access public
88 * @param array $series The array of chart series.
89 * @param int $chart_id The chart id.
90 * @return array The array of filtered series.
91 */
92 public function filterChartSeries( $series, $chart_id ) {
93 $source = $this->_getSource( $chart_id );
94 if ( !$source ) {
95 return $series;
96 }
97
98 return $source->repopulateSeries( $series, $chart_id );
99 }
100
101 /**
102 * Filters chart data.
103 *
104 * @since 1.1.0
105 *
106 * @access public
107 * @param array $data The array of chart data.
108 * @param int $chart_id The chart id.
109 * @return array The array of filtered data.
110 */
111 public function filterChartData( $data, $chart_id ) {
112 $source = $this->_getSource( $chart_id );
113 if ( !$source ) {
114 return $data;
115 }
116
117 return $source->repopulateData( $data, $chart_id );
118 }
119
120 }