PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 1.7.2
Visualizer – Tables & Charts Manager with Built-in AI Generator v1.7.2
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.7.2, 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 * Sources module class.
24 *
25 * @category Visualizer
26 * @package Module
27 *
28 * @since 1.1.0
29 */
30 class Visualizer_Module_Sources extends Visualizer_Module {
31
32 const NAME = __CLASS__;
33
34 /**
35 * The array of fetched sources.
36 *
37 * @since 1.1.0
38 *
39 * @access private
40 * @var array
41 */
42 private $_sources = array();
43
44 /**
45 * Constructor.
46 *
47 * @since 1.1.0
48 *
49 * @access public
50 * @param Visualizer_Plugin $plugin The instance of the plugin.
51 */
52 public function __construct( Visualizer_Plugin $plugin ) {
53 parent::__construct( $plugin );
54
55 $this->_addFilter( Visualizer_Plugin::FILTER_GET_CHART_SERIES, 'filterChartSeries', 1, 2 );
56 $this->_addFilter( Visualizer_Plugin::FILTER_GET_CHART_DATA, 'filterChartData', 1, 2 );
57 }
58
59 /**
60 * Returns appropriate source object for a chart.
61 *
62 * @since 1.1.0
63 *
64 * @access private
65 * @param int $chart_id The chart id.
66 * @return Visualizer_Source The source object if source exists, otherwise FALSE.
67 */
68 private function _getSource( $chart_id ) {
69 if ( ! isset( $this->_sources[ $chart_id ] ) ) {
70 $class = get_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, true );
71 if ( ! class_exists( $class, true ) ) {
72 return false;
73 }
74
75 $this->_sources[ $chart_id ] = new $class();
76 }
77
78 return $this->_sources[ $chart_id ];
79 }
80
81 /**
82 * Filters chart sereis.
83 *
84 * @since 1.1.0
85 *
86 * @access public
87 * @param array $series The array of chart series.
88 * @param int $chart_id The chart id.
89 * @return array The array of filtered series.
90 */
91 public function filterChartSeries( $series, $chart_id ) {
92 $source = $this->_getSource( $chart_id );
93 if ( ! $source ) {
94 return $series;
95 }
96
97 return $source->repopulateSeries( $series, $chart_id );
98 }
99
100 /**
101 * Filters chart data.
102 *
103 * @since 1.1.0
104 *
105 * @access public
106 * @param array $data The array of chart data.
107 * @param int $chart_id The chart id.
108 * @return array The array of filtered data.
109 */
110 public function filterChartData( $data, $chart_id ) {
111 $source = $this->_getSource( $chart_id );
112 if ( ! $source ) {
113 return $data;
114 }
115
116 return $source->repopulateData( $data, $chart_id );
117 }
118
119 }
120