WYSIJA_module_stats_subscribers_std

The MailPoet Newsletters WYSIJA module stats subscribers std class.

Defined (1)

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

/modules/stats_subscribers_std/stats_subscribers_std.php  
  1. class WYSIJA_module_stats_subscribers_std extends WYSIJA_module_statistics { 
  2.  
  3. public $name = 'stats_subscribers_std'; 
  4.  
  5. public $model = 'WYSIJA_model_stats_subscribers_std'; 
  6.  
  7. public $view = 'stats_subscribers_std_view'; 
  8.  
  9. static protected $stats_data; 
  10.  
  11. public function __construct() { 
  12. parent::__construct(); 
  13.  
  14. protected function get_order_direction($params) { 
  15. $order_direction = (!empty($params['order_direction']) && $params['order_direction'] == WYSIJA_module_statistics::ORDER_DIRECTION_ASC ? 'asc' : 'desc'); 
  16. return array( 
  17. 'sent' => !empty($params['order_by']) && $params['order_by'] == WYSIJA_module_statistics::ORDER_BY_SENT ? 'sorted '.$order_direction : '',  
  18. 'opens' => !empty($params['order_by']) && $params['order_by'] == WYSIJA_module_statistics::ORDER_BY_OPEN ? 'sorted '.$order_direction : '',  
  19. 'clicks' => !empty($params['order_by']) && $params['order_by'] == WYSIJA_module_statistics::ORDER_BY_CLICK ? 'sorted '.$order_direction : '' 
  20. ); 
  21.  
  22. public function hook_subscriber_bottom($params = array( )) { 
  23. if (empty($params['user_id'])) 
  24. return; 
  25. $this->data['order_direction'] = $this->get_order_direction($params); 
  26. $this->data['opened_newsletters'] = $this->get_opened_newsletters($params); 
  27. $this->view_show = 'hook_subscriber_bottom'; 
  28. return $this->render(); 
  29.  
  30. /** 
  31. * Get already opened newsletters by current user 
  32. * @param array $params 
  33. Array 
  34. user_id => 2 
  35. * @return array 
  36. * array( 
  37. * 'stats' => array( 
  38. * emails_count => 123,  
  39. * opened_emails_count => 12 
  40. * ),  
  41. * array( 
  42. * 1 => array( // First email 
  43. * email_id => 1,  
  44. * subject => Lorem ipsum,  
  45. * sent_at => 123456789 
  46. * urls => array( 
  47. * 1 => array( // first url in the current email 
  48. * email_id => 1,  
  49. * url_id => 2,  
  50. * url => http://domain.com/link/to/page 
  51. * number_clicked => 234 
  52. * ) 
  53. * ) 
  54. * ) 
  55. * ) 
  56. * ) 
  57.   
  58. */ 
  59. protected function get_opened_newsletters($params) { 
  60. // get emails by user 
  61. $emails = $this->model_obj->get_emails_by_user_id($params['user_id']); 
  62. if (empty($emails)) 
  63. return; 
  64.  
  65. $emails_count = count($emails); 
  66.  
  67. // get urls by email 
  68. $urls = $this->model_obj->get_urls_by_email_ids(array_keys($emails), $params['user_id']); 
  69.  
  70. // combine 
  71. foreach ($emails as $email_id => $email) { 
  72. $emails[$email_id]['urls'] = !empty($urls[$email_id]) ? $urls[$email_id] : array( ); 
  73.  
  74. // filter emails, keep opened or clicked ones only 
  75. foreach ($emails as $email_id => $email) { 
  76. if ((empty($email['opened_at']) || $email['opened_at'] <= 0) AND empty($email['urls'])) { 
  77. unset($emails[$email_id]); 
  78. $opened_emails_count = count($emails); 
  79. return array( 
  80. 'stats' => array( 
  81. 'emails_count' => $emails_count,  
  82. 'opened_emails_count' => $opened_emails_count 
  83. ),  
  84. 'emails' => $emails 
  85. ); 
  86.  
  87. /** 
  88. * hook_newsletter - page MailPoet >> Newsletters >> view detail 
  89. * @param array $params 
  90. * @return string 
  91. */ 
  92. public function hook_newsletter($params) { 
  93. return $this->hook_stats($params); 
  94.