WJ_StatsSessionManager

The MailPoet Newsletters WJ StatsSessionManager class.

Defined (1)

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

/classes/WJ_StatsSessionManager.php  
  1. class WJ_StatsSessionManager { 
  2. /** 
  3. * default selection of predefined dates 
  4. * @var WJ_StatsSession 
  5. */ 
  6. protected $default_selection; 
  7.  
  8. protected $pre_defined_dates; 
  9.  
  10. public function __construct() {} 
  11.  
  12. public function set_pre_defined_dates(Array $pre_defined_dates) { 
  13. $this->pre_defined_dates = $pre_defined_dates; 
  14.  
  15. public function get_pre_defined_dates() { 
  16. return $this->pre_defined_dates; 
  17.  
  18. public function set_default_selection(WJ_StatsSession $stats_session) { 
  19. $this->default_selection = $stats_session; 
  20.  
  21. public function get_default_selection() { 
  22. return $this->default_selection; 
  23.  
  24. public function get_last_selection() { 
  25. $last_selection = new WJ_StatsSession(); 
  26.  
  27. $stats_session_last_days = $this->get_stats_session_last_days(); 
  28. if ($stats_session_last_days !== null) { 
  29. $last_selection->last_days = $stats_session_last_days; 
  30. if ($stats_session_last_days == 0) {// custom dates, "from" and "to" are fixed since the last session 
  31. $last_selection->from = $this->get_stats_session_from(); 
  32. $last_selection->to = $this->get_stats_session_to(); 
  33. } else {// pre-defined dates, "from" and "to" are relatively assigned 
  34. $pre_defined_dates = $this->get_pre_defined_dates(); 
  35. foreach ($pre_defined_dates as $pre_defined_date) { 
  36. if ($pre_defined_date['value'] == $stats_session_last_days) { 
  37. $last_selection->from = $pre_defined_date['from']; 
  38. $last_selection->to = $pre_defined_date['to']; 
  39. break; 
  40. } else { 
  41. $last_selection = $this->get_default_selection(); 
  42.  
  43. $this->set_last_selection($last_selection); 
  44.  
  45. return $last_selection; 
  46.  
  47. public function set_last_selection(WJ_StatsSession $stats_session) { 
  48. $this->set_stats_session_last_days($stats_session->last_days); 
  49. $this->set_stats_session_from($stats_session->from); 
  50. $this->set_stats_session_to($stats_session->to); 
  51.  
  52. protected function is_default_selection(WJ_StatsSession $stats_session) { 
  53. $stats_session = $stats_session; 
  54. return true; 
  55.  
  56. protected function set_stats_session_last_days($value) { 
  57. setcookie('stats_session_last_days', $value); 
  58.  
  59. protected function get_stats_session_last_days() { 
  60. return isset($_COOKIE['stats_session_last_days']) ? $_COOKIE['stats_session_last_days'] : null; 
  61.  
  62. protected function set_stats_session_from($value) { 
  63. setcookie('stats_session_from', $value); 
  64.  
  65. protected function get_stats_session_from() { 
  66. return isset($_COOKIE['stats_session_from']) ? $_COOKIE['stats_session_from'] : null; 
  67.  
  68. protected function set_stats_session_to($value) { 
  69. setcookie('stats_session_to', $value); 
  70.  
  71. protected function get_stats_session_to() { 
  72. return isset($_COOKIE['stats_session_to']) ? $_COOKIE['stats_session_to'] : null;