WYSIJA_model_archive_std

The MailPoet Newsletters WYSIJA model archive std class.

Defined (1)

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

/modules/archive_std/archive_std_model.php  
  1. class WYSIJA_model_archive_std extends WYSIJA_model { 
  2.  
  3. /** 
  4. * allowed newsletters to be listed 
  5. * @var array 
  6. */ 
  7. protected $email_types = array( 
  8. 1, // standard newsletter 
  9. 2 // AutoNL (we will remove all AutoResponders, but keep Post Notification. Refer to self::remove_auto_responders() 
  10. ); 
  11.  
  12. /** 
  13. * allowed newsletter's statuses 
  14. * @var array 
  15. */ 
  16. protected $email_status = array( 
  17. 1, // sending 
  18. 3, // sending 
  19. 99, // sending 
  20. 2 // sent 
  21. ); 
  22.  
  23. /** 
  24. * Get newsletters, based on list ids 
  25. * @param array $list_ids 
  26. * @return array 
  27. */ 
  28. public function get_newsletters(Array $list_ids = array( )) { 
  29. $where = array( 1 ); 
  30. $where[] = 'e.`type` IN ('.implode(', ', $this->email_types).')'; 
  31. $where[] = 'e.`status` IN ('.implode(', ', $this->email_status).')'; 
  32. $where[] = 'e.`sent_at` IS NOT NULL'; 
  33. $where_join = ''; 
  34. if (!empty($list_ids)) 
  35. $where_join = ' AND cl.`list_id` IN ('.implode(', ', $list_ids).')'; 
  36. $query = ' 
  37. SELECT 
  38. e.`email_id`,  
  39. e.`type`,  
  40. e.`subject`,  
  41. e.`created_at`,  
  42. e.`sent_at`,  
  43. e.`params` 
  44. FROM 
  45. `[wysija]email` e 
  46. JOIN 
  47. `[wysija]campaign` c ON e.`campaign_id` = c.`campaign_id` 
  48. JOIN 
  49. `[wysija]campaign_list` cl ON c.`campaign_id` = cl.`campaign_id` '.$where_join.' 
  50. WHERE 
  51. '.implode(' AND ', $where).' 
  52. GROUP BY 
  53. e.`email_id` 
  54. ORDER BY 
  55. e.`sent_at` DESC 
  56. '; 
  57. return $this->replace_shortcodes( 
  58. $this->remove_auto_responders( 
  59. $this->get_results($query, OBJECT) // get in object please. We need to pass them to Shortcodes factory. Shortcodes factory accepts Object instead of Array 
  60. ); 
  61.  
  62. /** 
  63. * Remove AutoResponders from the dataset, but keep post notification. 
  64. * Refer to WYSIJA_help_autonews::getNextSend() 
  65. * @param type $newsletters 
  66. */ 
  67. protected function remove_auto_responders($newsletters) { 
  68. foreach ($newsletters as $index => $newsletter) { 
  69. $newsletters[$index]->params = unserialize(base64_decode($newsletter->params)); 
  70. if (!empty($newsletters[$index]->type) && (int)$newsletters[$index]->type === 2) { 
  71. if (isset($newsletters[$index]->params['autonl']['event']) && $newsletters[$index]->params['autonl']['event'] === 'new-articles') { 
  72. // keep post notification 
  73. else { 
  74. unset($newsletters[$index]); 
  75. return $newsletters; 
  76.  
  77. /** 
  78. * Render shortcodes 
  79. * @param array $newsletters a list of object Email 
  80. * @return array a list of object Email, with renedered shortcodes at subject 
  81. */ 
  82. protected function replace_shortcodes($newsletters) { 
  83. $helper_mailer = WYSIJA::get('mailer', 'helper'); 
  84. $helper_shortcodes = WYSIJA::get('shortcodes', 'helper'); 
  85. foreach ($newsletters as &$newsletter) { 
  86. $helper_mailer->parseSubjectUserTags($newsletter); 
  87. $newsletter->subject = $helper_shortcodes->replace_subject($newsletter); 
  88. return $newsletters; 
  89.