WYSIJA_model_stats_newsletter_std

The MailPoet Newsletters WYSIJA model stats newsletter std class.

Defined (1)

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

/modules/stats_newsletter_std/stats_newsletter_std_model.php  
  1. class WYSIJA_model_stats_newsletter_std extends WYSIJA_module_statistics_model { 
  2.  
  3. /** 
  4. * Store email status (output of $this->get_email_status()) 
  5. * @var type 
  6. */ 
  7. protected static $emails_status = array( ); 
  8.  
  9. /** 
  10. * Get and group by status of a specific newsletter which was sent to subscribers 
  11. * @param int $user_id 
  12. * @return array list of emails, group by status. It contains an empy list, or list of one or more status 
  13. * array( 
  14. * status => emails count, // status: -3: inqueue, -2:notsent, -1: bounced, 0: sent, 1: open, 2: clicked, 3: unsubscribed 
  15. * status => emails count,  
  16. * ... 
  17. * status => emails count 
  18. * ) 
  19. */ 
  20. public function get_email_status($email_id) { 
  21. if (!isset(self::$emails_status[$email_id])) { 
  22. // get stats email status 
  23. $query = ' 
  24. SELECT 
  25. count(`email_id`) as emails,  
  26. `status` 
  27. FROM 
  28. `[wysija]email_user_stat` 
  29. WHERE `email_id` = '.(int)$email_id.' 
  30. GROUP BY `status`' 
  31. self::$emails_status[$email_id] = $this->indexing_dataset_by_field('status', $this->get_results($query), false, 'emails'); 
  32. return self::$emails_status[$email_id]; 
  33.  
  34. /** 
  35. * @param int $user_id 
  36. * @return int a number of received / sent newsletters to a specific user 
  37. */ 
  38. public function get_emails_count($email_id) { 
  39. // get emails group by status 
  40. $count = 0; 
  41. $emails_status = $this->get_email_status($email_id); // we don't need to write a separated sql query here, reduce 1 sql request 
  42. if (empty($emails_status)) 
  43. return $count; 
  44. foreach ($emails_status as $emails) 
  45. $count += $emails; 
  46. return $count; 
  47.  
  48. /** 
  49. * Get top links of a newsletters 
  50. * @param type $email_id 
  51. * @return array 
  52. * array( 
  53. * 'email_id' => int, <br /> 
  54. * 'url_id' => int, <br /> 
  55. * 'url' => string, <br /> 
  56. * 'unique_clicks' => int, <br /> 
  57. * 'total_clicks' => int <br /> 
  58. * ) 
  59. */ 
  60. public function get_top_links($email_id, $top = 5, $order_direction = 'DESC') { 
  61. $limit = !empty($top) ? 'LIMIT 0, '.$top : ''; 
  62. $query = ' 
  63. SELECT 
  64. euu.`email_id`,  
  65. u.`url_id`,  
  66. u.`url`,  
  67. COUNT(`number_clicked`) AS `unique_clicks`,  
  68. SUM(`number_clicked`) AS `total_clicks` 
  69. FROM 
  70. [wysija]email_user_url euu 
  71. JOIN 
  72. [wysija]url u ON euu.url_id = u.url_id 
  73. WHERE 
  74. euu.email_id = '.(int)$email_id.' 
  75. GROUP BY 
  76. u.`url_id` 
  77. ORDER BY `total_clicks` '.$order_direction.' 
  78. '.$limit.' 
  79.  
  80. '; 
  81. $top_links = $this->get_results($query); 
  82. foreach ($top_links as &$top_link) { 
  83. $params = array( 
  84. 'action=viewstats',  
  85. 'page=wysija_campaigns',  
  86. 'link_filter=clicked',  
  87. 'id='.$top_link['email_id'],  
  88. 'url_id='.$top_link['url_id'] 
  89. ); 
  90.  
  91. $top_link['view_subscriber_url'] = admin_url('admin.php?'.implode('&', $params)); 
  92.  
  93. return $top_links; 
  94.  
  95. /** 
  96. * Get lists which a campaign was sent to 
  97. * @param int $campaign_id 
  98. * @return array( 
  99. * int => string (id => name),  
  100. * int => string (id => name),  
  101. * int => string (id => name),  
  102. * ) 
  103. */ 
  104. public function get_lists($campaign_id) { 
  105. $campaign_id = (int)$campaign_id; 
  106. $lists = array( ); 
  107. if (!empty($campaign_id)) { 
  108. $query = ' 
  109. SELECT 
  110. l.list_id,  
  111. l.name 
  112. FROM 
  113. `[wysija]campaign_list` cl 
  114. JOIN 
  115. `[wysija]list` l ON cl.`list_id` = l.`list_id` AND `campaign_id` = '.$campaign_id.' 
  116. '; 
  117. $lists = $this->indexing_dataset_by_field('list_id', $this->get_results($query), null, 'name'); 
  118. return $lists; 
  119.