/includes/admin/abstract-report.php

  1. <?php 
  2. /** 
  3. * Report Abstract  
  4. * 
  5. * Ensures all of the reports have a uniform class with helper functions. 
  6. * 
  7. * @since 6.0.0 
  8. * 
  9. * @package MonsterInsights 
  10. * @subpackage Reports 
  11. * @author Chris Christoff 
  12. */ 
  13.  
  14. // Exit if accessed directly 
  15. if ( ! defined( 'ABSPATH' ) ) { 
  16. exit; 
  17.  
  18. abstract class MonsterInsights_Report { 
  19.  
  20. public $report_name; 
  21.  
  22. public $report_hook; 
  23.  
  24. public $range; 
  25.  
  26. /** 
  27. * Holds the GA client object if using oAuth. 
  28. * 
  29. * @access public 
  30. * @since 6.0.0 
  31. * @var MonsterInsights_GA_Client $client GA client object. 
  32. */ 
  33. public $client; 
  34.  
  35. /** 
  36. * Primary class constructor. 
  37. * 
  38. * @access public 
  39. * @since 6.0.0 
  40. */ 
  41. public function __construct( $range = array() ) { 
  42.  
  43. $this->range = monsterinsights_get_report_date_range(); 
  44.  
  45. // filter to add tab for this report 
  46. add_filter( 'monsterinsights_get_reports', array( $this, 'add_report' ), 10, 1 ); 
  47.  
  48. // filter to show the view for this report 
  49. add_action( 'monsterinsights_tab_reports_' . $this->report_hook, array( $this, 'show_report' ), 10, 1 ); 
  50.  
  51. add_action( 'monsterinsights_add_aggregate_data', array( $this, 'add_report_data' ), 10, 2 ); 
  52. add_action( 'monsterinsights_delete_aggregate_data', array( $this, 'delete_report_data' ), 10, 2 ); 
  53.  
  54.  
  55. // Adds the report to the array of reports. 
  56. public function add_report( $reports ) { 
  57. $reports[ $this->report_hook ] = $this->report_name; 
  58. return $reports; 
  59.  
  60. abstract public function add_report_data( $client, $id ); // Adds/Refreshes the data 
  61. abstract public function get_report_data(); // Gets the data 
  62. abstract public function delete_report_data(); // Removes report data 
  63. abstract public function show_report(); // Outputs the report. 
  64.  
  65. /** 
  66. * Get the start and and date for aggregation functionality. 
  67. * 
  68. * @return array 
  69. */ 
  70. protected function get_date_range() { 
  71. return $this->range; 
  72.  
  73. /** 
  74. * Get the api limit for aggregation functionality. 
  75. * 
  76. * By default Google will return 1000 rows at most. They will return less in certain circumstances. 
  77. * For example, the countries query will never return more than 300 rows as there's not more than 300 values 
  78. * for ga:countries dimension. If you are a large site you might need to use this filter to lower the number requested.  
  79. * We only request 300, as it's the max number for the largest report we need (by country maxes at 300 countries). 
  80. * 
  81. * In the future, we'll likely have each report use the limit returned in this function, or a report-set default limit,  
  82. * whichever is lower. 
  83. * 
  84. * @return int 
  85. */ 
  86. protected function get_api_max_limit() { 
  87. return apply_filters( 'monsterinsights_reporting_get_max_api_limit', 300 ); 
.