reporting.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * MonsterInsights Reporting.
  4. *
  5. * Handles aggregating data.
  6. *
  7. * @since 7.0.0
  8. *
  9. * @package MonsterInsights
  10. * @subpackage GA Reporting
  11. * @author Chris Christoff
  12. */
  13. // Exit if accessed directly
  14. if ( ! defined( 'ABSPATH' ) ) {
  15. exit;
  16. }
  17. final class MonsterInsights_Reporting {
  18. public $reports = array();
  19. public function __construct( ) {
  20. }
  21. public function add_report( $report = false ){
  22. if ( empty( $report ) || ! is_object( $report ) ) {
  23. return;
  24. }
  25. if ( version_compare( $report->version, '1.0.0', '<' ) ) {
  26. return;
  27. }
  28. $this->reports[] = $report;
  29. }
  30. public function get_aggregate_data() {
  31. if ( ! empty( $this->reports ) ) {
  32. foreach ( $this->reports as $report ) {
  33. $report->get_data( array( 'default' => true ) );
  34. }
  35. }
  36. }
  37. // $where possible values: auto, site, network, both
  38. public function delete_aggregate_data( $where = 'site' ) {
  39. if ( ! empty( $this->reports ) ) {
  40. foreach ( $this->reports as $report ) {
  41. $report->delete_cache( $where );
  42. }
  43. }
  44. }
  45. public function get_report( $name = '' ) {
  46. if ( empty( $name ) || empty( $this->reports ) ) {
  47. return false;
  48. }
  49. foreach ( $this->reports as $report ) {
  50. if ( $name === $report->name ) {
  51. return $report;
  52. }
  53. }
  54. return false;
  55. }
  56. }