Last active
September 7, 2020 08:55
-
-
Save sungraiz/794ba045fb7a2eec687f55bdfa8ec6d1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function inspiry_top_properties_widgets() { | |
| ?> | |
| <div class="col-sm-12"> | |
| <div class="widget-common widget-small inspiry-top-properties-wrapper clearfix"> | |
| <div class="widget-body clearfix"> | |
| <h4 class="text-center"><?php esc_html_e( 'Top Visited Properties of this Month', 'framework' ); ?></h4> | |
| <div id="inspiry-top-properties" class="clearfix" style="height: 400px; width: 100%;"></div> | |
| </div> | |
| </div> | |
| </div> | |
| <?php | |
| } | |
| add_action( 'realhomes_dashboard_add_large_widget', 'inspiry_top_properties_widgets', 20 ); | |
| if ( isset( $_GET['module'] ) && 'dashboard' === $_GET['module'] ) { | |
| wp_enqueue_script( 'child-canvas-js', get_stylesheet_directory_uri() . '/js/canvasjs.min.js', array( 'jquery' ), '3.0' ); | |
| global $wpdb; | |
| $sql_query = "SELECT DISTINCT IP,PID FROM {$wpdb->prefix}inspiry_property_analytics WHERE timestamp >= DATE_SUB(CURDATE(), INTERVAL DAYOFMONTH(CURDATE())-1 DAY)"; | |
| $result = $wpdb->get_results( $sql_query, ARRAY_A ); | |
| if ( $result ) { | |
| $current_user = wp_get_current_user(); | |
| $agent_id = get_user_meta( $current_user->ID, 'inspiry_role_post_id', true ); | |
| $prepare_array = array_count_values( array_column( $result, 'PID' ) ); | |
| $final_object = array(); | |
| $prepare_array = array_walk( | |
| $prepare_array, | |
| function( &$val, $key ) use ( &$final_object, $agent_id ) { | |
| $property_agent = get_post_meta( $key, 'REAL_HOMES_agents', true ); | |
| if ( $agent_id === $property_agent ) { | |
| $final_object[] = array( | |
| 'y' => $val, | |
| 'indexLabel' => get_the_title( $key ), | |
| ); | |
| } | |
| } | |
| ); | |
| wp_localize_script( | |
| 'child-custom', | |
| 'inspiry_top_properties_analytics', | |
| array( | |
| 'data_label' => esc_html__( 'Top Visited Properties of this Month', 'framework' ), | |
| 'dataPoints' => $final_object, | |
| ) | |
| ); | |
| } | |
| } | |
| ?> | |
| <script> | |
| window.onload = function () { | |
| const inspiryTopProperties = document.getElementById('inspiry-top-properties'); | |
| if (inspiryTopProperties && typeof inspiry_top_properties_analytics !== 'undefined') { | |
| var chart = new CanvasJS.Chart("inspiry-top-properties", { | |
| animationEnabled: true, | |
| // exportEnabled: true, | |
| theme: "light1", // "light1", "light2", "dark1", "dark2" | |
| data: [{ | |
| type: "column", //change type to column, bar, line, area, pie, etc | |
| indexLabelFontColor: "#000000", | |
| indexLabelFontSize :'14', | |
| indexLabelOrientation: 'horizontal', | |
| indexLabelPlacement: 'inside', | |
| indexLabelFontWeight: 'bolder', | |
| indexLabelMaxWidth: 100, | |
| indexLabelWrap: true, | |
| dataPoints: inspiry_top_properties_analytics.dataPoints | |
| }] | |
| }); | |
| chart.render(); | |
| } | |
| } | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment