WYSIJA_model_stats_subscribers_std

The MailPoet Newsletters WYSIJA model stats subscribers std class.

Defined (1)

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

/modules/stats_subscribers_std/stats_subscribers_std_model.php  
  1. class WYSIJA_model_stats_subscribers_std extends WYSIJA_module_statistics_model { 
  2.  
  3. /** 
  4. * Get all emails which were sent to a specific user 
  5. * @param int $user_id 
  6. * @return array list of emails 
  7. * array( 
  8. * 1 => array( 
  9. * email_id => 1 
  10. * subject => 'lorem ipsum' 
  11. * sent_at => 123456789 
  12. * ),  
  13. * 3 => array( 
  14. * email_id => 3 
  15. * subject => 'lorem ipsum' 
  16. * sent_at => 123456789 
  17. * ),  
  18. * 5 => array( 
  19. * email_id => 5 
  20. * subject => 'lorem ipsum' 
  21. * sent_at => 123456789 
  22. * ) 
  23. * ) 
  24. */ 
  25. public function get_emails_by_user_id($user_id, $opened_only = false) { 
  26. $where = array( 1 ); 
  27. if ($opened_only) { 
  28. $where[] = 'eus.`opened_at` > 0'; 
  29. $where[] = 'eus.`status` > 0'; 
  30.  
  31. $query = ' 
  32. SELECT 
  33. e.`email_id`,  
  34. e.`subject`,  
  35. e.`sent_at`,  
  36. eus.`opened_at` 
  37. FROM 
  38. `[wysija]email_user_stat` eus 
  39. JOIN 
  40. `[wysija]email` e ON e.`email_id` = eus.`email_id` AND eus.`user_id` = '.(int)$user_id.' 
  41. WHERE '.implode(' AND ', $where).' 
  42. ORDER BY eus.`opened_at` DESC 
  43. '; 
  44. $dataset = $this->get_results($query); 
  45. return $this->indexing_dataset_by_field('email_id', $dataset); 
  46.  
  47. /** 
  48. * Get all possible urls embebed in each email 
  49. * @param array $email_ids 
  50. * @return array list of urls 
  51. * array( 
  52. * email_id => array( 
  53. * url_id => array( 
  54. * 'email_id' => 1,  
  55. * 'url_id' => 1,  
  56. * 'url' => 'http://...',  
  57. * 'number_clicked' => 2 
  58. * ) 
  59. * ) 
  60. * ) 
  61. */ 
  62. public function get_urls_by_email_ids(Array $email_ids, $user_id = null) { 
  63. if (empty($email_ids)) 
  64. return array( ); 
  65.  
  66. $where = array( 1 ); 
  67. $where[] = 'euu.`email_id` IN ('.implode(', ', $email_ids).')'; 
  68. if (!empty($user_id)) 
  69. $where[] = 'euu.`user_id` = '.(int)$user_id; 
  70. $query = ' 
  71. SELECT 
  72. euu.`email_id`,  
  73. u.`url_id`,  
  74. u.`url`,  
  75. euu.`number_clicked` 
  76. FROM 
  77. `[wysija]email_user_url` euu 
  78. JOIN 
  79. `[wysija]url` u ON u.`url_id` = euu.`url_id` AND '.implode(' AND ', $where).' 
  80. ORDER BY euu.`email_id`, u.`url` 
  81.  
  82. '; 
  83.  
  84. $dataset = $this->get_results($query); 
  85.  
  86. $tmp = array( ); 
  87. foreach ($dataset as $record) { 
  88. $tmp[$record['email_id']][] = $record; 
  89. foreach ($tmp as $email_id => $_dataset) { 
  90. $tmp[$email_id] = $this->indexing_dataset_by_field('url_id', $_dataset); 
  91. return $tmp; 
  92.