Skip to content

Commit 61767cc

Browse files
committed
Fixed logger data.
1 parent 7a2b21a commit 61767cc

File tree

2 files changed

+51
-50
lines changed

2 files changed

+51
-50
lines changed

classes/Visualizer/Module/Admin.php

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -62,56 +62,6 @@ public function __construct( Visualizer_Plugin $plugin ) {
6262
$this->_addFilter( 'visualizer_get_chart_counts', 'getChartCountsByTypeAndMeta' );
6363
}
6464

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-
}
114-
11565
/**
11666
* Enqueues media scripts and styles.
11767
*

classes/Visualizer/Module/Setup.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,57 @@ public function __construct( Visualizer_Plugin $plugin ) {
4444

4545
$this->_addAction( 'init', 'setupCustomPostTypes' );
4646
$this->_addAction( 'plugins_loaded', 'loadTextDomain' );
47+
$this->_addFilter( 'visualizer_logger_data', 'getLoggerData' );
48+
$this->_addFilter( 'visualizer_get_chart_counts', 'getChartCountsByTypeAndMeta' );
49+
}
50+
/**
51+
* Fetches the SDK logger data.
52+
*
53+
* @param array $data The default data that needs to be sent.
54+
*
55+
* @access public
56+
*/
57+
public function getLoggerData( $data ) {
58+
return $this->getChartCountsByTypeAndMeta();
59+
}
60+
61+
/**
62+
* Fetches the types of charts created and their counts.
63+
*
64+
* @param array $meta_keys An array of name vs. meta keys - to return how many charts have these keys.
65+
* @access private
66+
*/
67+
public function getChartCountsByTypeAndMeta( $meta_keys = array() ) {
68+
$charts = array();
69+
$charts['chart_types'] = array();
70+
// the initial query arguments to fetch charts
71+
$query_args = array(
72+
'post_type' => Visualizer_Plugin::CPT_VISUALIZER,
73+
'posts_per_page' => 300,
74+
'fields' => 'ids',
75+
'no_rows_found' => false,
76+
'update_post_meta_cache' => false,
77+
'update_post_term_cache' => false,
78+
79+
);
80+
81+
$query = new WP_Query( $query_args );
82+
while ( $query->have_posts() ) {
83+
$chart_id = $query->next_post();
84+
$type = get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_TYPE, true );
85+
$charts['chart_types'][ $type ] = isset( $charts['chart_types'][ $type ] ) ? $charts['chart_types'][ $type ] + 1 : 1;
86+
if ( ! empty( $meta_keys ) ) {
87+
foreach ( $meta_keys as $name => $key ) {
88+
$data = get_post_meta( $chart_id, $key, true );
89+
if ( ! empty( $data ) ) {
90+
$charts[ $name ] = isset( $charts[ $name ] ) ? $charts[ $name ] + 1 : 1;
91+
} else {
92+
$charts[ $name ] = 0;
93+
}
94+
}
95+
}
96+
}
97+
return $charts;
4798
}
4899

49100
/**

0 commit comments

Comments
 (0)