Skip to content

Commit dd1145f

Browse files
authored
Merge pull request #199 from contactashish13/issue-77
add tracking data #77
2 parents 0807065 + 4350936 commit dd1145f

File tree

4 files changed

+60
-1
lines changed

4 files changed

+60
-1
lines changed

classes/Visualizer/Module/Admin.php

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,59 @@ public function __construct( Visualizer_Plugin $plugin ) {
5858
$this->_addAction( 'admin_menu', 'registerAdminMenu' );
5959
$this->_addFilter( 'media_view_strings', 'setupMediaViewStrings' );
6060
$this->_addFilter( 'plugin_action_links', 'getPluginActionLinks', 10, 2 );
61-
$this->_addFilter( 'plugin_row_meta', 'getPluginMetaLinks', 10, 2 );
61+
$this->_addFilter( 'visualizer_logger_data', 'getLoggerData' );
62+
$this->_addFilter( 'visualizer_get_chart_counts', 'getChartCountsByTypeAndMeta' );
6263
}
6364

65+
/**
66+
* Fetches the SDK logger data.
67+
*
68+
* @param array $data The default data that needs to be sent.
69+
*
70+
* @access public
71+
*/
72+
public function getLoggerData( $data ) {
73+
return $this->getChartCountsByTypeAndMeta();
74+
}
75+
76+
/**
77+
* Fetches the types of charts created and their counts.
78+
*
79+
* @param array $meta_keys An array of name vs. meta keys - to return how many charts have these keys.
80+
* @access private
81+
*/
82+
public function getChartCountsByTypeAndMeta( $meta_keys = array() ) {
83+
$charts = array();
84+
$charts['chart_types'] = array();
85+
// the initial query arguments to fetch charts
86+
$query_args = array(
87+
'post_type' => Visualizer_Plugin::CPT_VISUALIZER,
88+
'posts_per_page' => 300,
89+
'fields' => 'ids',
90+
'no_rows_found' => false,
91+
'update_post_meta_cache' => false,
92+
'update_post_term_cache' => false,
93+
94+
);
95+
96+
$query = new WP_Query( $query_args );
97+
while ( $query->have_posts() ) {
98+
$chart_id = $query->next_post();
99+
$type = get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_TYPE, true );
100+
$charts['chart_types'][ $type ] = isset( $charts['chart_types'][ $type ] ) ? $charts['chart_types'][ $type ] + 1 : 1;
101+
if ( ! empty( $meta_keys ) ) {
102+
foreach ( $meta_keys as $name => $key ) {
103+
$data = get_post_meta( $chart_id, $key, true );
104+
if ( ! empty( $data ) ) {
105+
$charts[ $name ] = isset( $charts[ $name ] ) ? $charts[ $name ] + 1 : 1;
106+
} else {
107+
$charts[ $name ] = 0;
108+
}
109+
}
110+
}
111+
}
112+
return $charts;
113+
}
64114

65115
/**
66116
* Enqueues media scripts and styles.

classes/Visualizer/Module/Chart.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,12 @@ public function uploadData() {
412412
if ( ! isset( $_POST['vz-import-time'] ) ) {
413413
apply_filters( 'visualizer_pro_remove_schedule', $chart_id );
414414
}
415+
416+
if ( ! isset( $_POST['chart_data_src'] ) || Visualizer_Plugin::CF_SOURCE_FILTER !== $_POST['chart_data_src'] ) {
417+
// delete the filters in case this chart is being uploaded from other data sources
418+
delete_post_meta( $chart_id, 'visualizer-filter-config' );
419+
}
420+
415421
$source = null;
416422
$render = new Visualizer_Render_Page_Update();
417423
if ( isset( $_POST['remote_data'] ) && filter_var( $_POST['remote_data'], FILTER_VALIDATE_URL ) ) {

classes/Visualizer/Plugin.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ class Visualizer_Plugin {
4040
const CF_DEFAULT_DATA = 'visualizer-default-data';
4141
const CF_SETTINGS = 'visualizer-settings';
4242

43+
const CF_SOURCE_FILTER = 'visualizer-source-filter';
44+
4345
// custom actions
4446
const ACTION_GET_CHARTS = 'visualizer-get-charts';
4547
const ACTION_CREATE_CHART = 'visualizer-create-chart';

classes/Visualizer/Render/Page/Data.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ class="dashicons dashicons-lock"></span></h2>
222222
class="dashicons dashicons-lock"></span></h2>
223223
<form id="editor-form" action="<?php echo $upload_link; ?>" method="post" target="thehole">
224224
<input type="hidden" id="chart-data" name="chart_data">
225+
<input type="hidden" id="chart-data-src" name="chart_data_src">
225226
</form>
226227

227228
<div class="group-content edit-data-content">

0 commit comments

Comments
 (0)