Skip to content

Commit c6a652c

Browse files
add tracking data #77
1 parent e35e204 commit c6a652c

File tree

4 files changed

+30
-7
lines changed

4 files changed

+30
-7
lines changed

classes/Visualizer/Module/Admin.php

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public function __construct( Visualizer_Plugin $plugin ) {
5959
$this->_addFilter( 'media_view_strings', 'setupMediaViewStrings' );
6060
$this->_addFilter( 'plugin_action_links', 'getPluginActionLinks', 10, 2 );
6161
$this->_addFilter( 'visualizer_logger_data', 'getLoggerData' );
62+
$this->_addFilter( 'visualizer_get_chart_counts', 'getChartCountsByTypeAndMeta' );
6263
}
6364

6465
/**
@@ -69,31 +70,44 @@ public function __construct( Visualizer_Plugin $plugin ) {
6970
* @access public
7071
*/
7172
public function getLoggerData( $data ) {
72-
return array(
73-
'chart_types' => $this->getChartTypesAndCounts(),
74-
'wordpress_filters' => '',
75-
);
73+
return $this->getChartCountsByTypeAndMeta();
7674
}
7775

7876
/**
7977
* Fetches the types of charts created and their counts.
8078
*
79+
* @param array $meta_keys An array of name vs. meta keys - to return how many charts have these keys.
8180
* @access private
8281
*/
83-
private function getChartTypesAndCounts() {
84-
$charts = array();
82+
public function getChartCountsByTypeAndMeta( $meta_keys = array() ) {
83+
$charts = array();
84+
$charts['chart_types'] = array();
8585
// the initial query arguments to fetch charts
8686
$query_args = array(
8787
'post_type' => Visualizer_Plugin::CPT_VISUALIZER,
8888
'posts_per_page' => 300,
8989
'fields' => 'ids',
90+
'no_rows_found' => false,
91+
'update_post_meta_cache' => false,
92+
'update_post_term_cache' => false,
93+
9094
);
9195

9296
$query = new WP_Query( $query_args );
9397
while ( $query->have_posts() ) {
9498
$chart_id = $query->next_post();
9599
$type = get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_TYPE, true );
96-
$charts[ $type ] = isset( $charts[ $type ] ) ? $charts[ $type ] + 1 : 1;
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+
}
97111
}
98112
return $charts;
99113
}

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)