Yoast_GA_Dashboards_Driver

Base abstract class.

Defined (1)

The class is defined in the following location(s).

/admin/dashboards/drivers/class-admin-dashboards-driver.php  
  1. abstract class Yoast_GA_Dashboards_Driver { 
  2.  
  3. /** 
  4. * Container for holding set dashboards 
  5. * @var array 
  6. */ 
  7. protected $dashboards = array(); 
  8.  
  9. /** 
  10. * This will initialize the AJAX request 
  11. */ 
  12. public function __construct() { 
  13. $this->initialize_ajax(); 
  14.  
  15. /** 
  16. * Method which will be called by AJAX 
  17. * Will echo json for graph 
  18. */ 
  19. public function get_ajax_data() { 
  20. check_ajax_referer( 'yoast-ga-dashboard-nonce', '_ajax_nonce' ); 
  21.  
  22. $generator = $this->get_dashboard_generate_object(); 
  23. $json = $generator->get_json(); 
  24.  
  25. echo $json; 
  26. die(); 
  27.  
  28. /** 
  29. * Register a dashboard with settings. 
  30. * Dashboard can contain multiple dashboard-types. If so, $values shouldn't be passed and $dashboard argument 
  31. * should be key->value, key = dashboard and value should contain the values 
  32. * Given arguments will be marge with objects property dashboards 
  33. * @param mixed $dashboard 
  34. * @param mixed $values 
  35. */ 
  36. public function register( $dashboard, $values = false ) { 
  37.  
  38. if ( ! is_array( $dashboard ) ) { 
  39. $dashboard = array( $dashboard => $values ); 
  40.  
  41. $this->dashboards = array_merge( $this->dashboards, $dashboard ); 
  42.  
  43. /** 
  44. * Giving the dashboardname to show 
  45. * @param string $dashboard 
  46. */ 
  47. public function display( $dashboard ) { 
  48. $settings = $this->dashboards[ $dashboard ]; 
  49. require dirname( GAWP_FILE ) . '/admin/dashboards/views/' . $this->dashboard_type . '.php'; 
  50.  
  51. /** 
  52. * Setting hook for doing ajax request 
  53. */ 
  54. protected function initialize_ajax() { 
  55. add_action( $this->ajax_hook, array( $this, 'get_ajax_data' ) ); 
  56.  
  57. /** 
  58. * This method should always be available 
  59. * @return mixed 
  60. */ 
  61. abstract protected function get_dashboard_generate_object(); 
  62.