WYSIJA_module_stats_newsletter_std

The MailPoet Newsletters WYSIJA module stats newsletter std class.

Defined (1)

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

/modules/stats_newsletter_std/stats_newsletter_std.php  
  1. class WYSIJA_module_stats_newsletter_std extends WYSIJA_module_statistics { 
  2.  
  3. public $name = 'stats_newsletter_std'; 
  4.  
  5. public $model = 'WYSIJA_model_stats_newsletter_std'; 
  6.  
  7. public $view = 'stats_newsletter_std_view'; 
  8.  
  9. /** 
  10. * @var type define how charts are displayed 
  11. */ 
  12. protected $chart_stytle = 2; // 1 = open rate and click rate; 2 = all status in a pie; 0: both 
  13.  
  14. /** 
  15. * Map email status to its description 
  16. * @var type 
  17. */ 
  18. protected $emails_status = array( ); 
  19.  
  20. public function __construct() { 
  21. parent::__construct(); 
  22. $this->emails_status = array( 
  23. -3 => __('In queue', WYSIJA),  
  24. -2 => __('Not sent', WYSIJA),  
  25. -1 => __('Bounced', WYSIJA),  
  26. 0 => __('Sent', WYSIJA),  
  27. 1 => __('Opened only', WYSIJA),  
  28. 2 => __('Opened & Clicked', WYSIJA),  
  29. 3 => __('Opened & Unsubscribed', WYSIJA),  
  30. ); 
  31.  
  32. /** 
  33. * @param array $params 
  34. * array( 
  35. * 'email_id' => int,  
  36. * 'email_object' => array( 
  37. * 'email_id' => int,  
  38. * 'campaign_id' => int,  
  39. * 'subject' => string,  
  40. * 'body' => html,  
  41. * 'created_at' => int,  
  42. * 'modified_at' => int,  
  43. * 'sent_at' => int,  
  44. * 'from_email' => string,  
  45. * 'from_name' => string,  
  46. * 'replyto_email' => string,  
  47. * 'replyto_name' => string,  
  48. * 'attachments' => ?,  
  49. * 'status' => int,  
  50. * 'type' => int,  
  51. * 'number_sent' => int,  
  52. * 'number_opened' => int,  
  53. * 'number_clicked' => int,  
  54. * 'number_unsub' => int,  
  55. * 'number_bounce' => int,  
  56. * 'number_forward' => int,  
  57. * 'params' => array( 
  58. * 'quickselection' => array(),  
  59. * 'divider' => array(),  
  60. * 'googletrackingcode' => string,  
  61. * 'schedule' => array(),  
  62. * 'theme' => string 
  63. * ),  
  64. * 'wj_data' => string, (base64) 
  65. * 'wj_styles' => string (base64) 
  66. * ) 
  67. * ) 
  68. * @return html 
  69. */ 
  70. public function hook_newsletter_top($params = array( )) { 
  71. if (empty($params['email_id'])) 
  72. return; 
  73.  
  74. if ($this->is_premium) 
  75. return $this->hook_newsletter_action_buttons($params).$this->hook_newsletter_top_links($params); 
  76.  
  77. // Google Pie chart is available for free users only! 
  78. $this->data['emails_count'] = $this->model_obj->get_emails_count($params['email_id']); 
  79. //$this->data['email_object'] = $params['email_object']; 
  80. $helper_toolbox = WYSIJA::get('toolbox', 'helper'); 
  81. $sent_at = !empty($params['email_object']['sent_at']) ? $params['email_object']['sent_at'] : $params['email_object']['created_at']; 
  82. $title_pattern = $this->data['emails_count'] > 1 ? 'Sent %1$s ago to %2$s subscribers' : 'Sent %1$s ago to %2$s subscriber'; 
  83. $chart_title = sprintf(__($title_pattern, WYSIJA), $helper_toolbox->duration_string($sent_at), $this->data['emails_count']); 
  84.  
  85. $params['chart_title'] = $chart_title; 
  86. $this->data['dataset'] = array( ); 
  87. switch ($this->chart_stytle) { 
  88. case 0: 
  89. $this->data['dataset'][] = $this->get_open_rate_data($params); 
  90. $this->data['dataset'][] = $this->get_click_rate_data($params); 
  91. $this->data['dataset'][] = $this->get_emails_stats($params); 
  92. break; 
  93. case 1: 
  94. $this->data['dataset'][] = $this->get_open_rate_data($params); 
  95. $this->data['dataset'][] = $this->get_click_rate_data($params); 
  96. break; 
  97.  
  98. case 2: 
  99. $this->data['dataset'][] = $this->get_emails_stats($params); 
  100. break; 
  101.  
  102. $this->view_show = 'hook_newsletter_top'; 
  103.  
  104. // quickfix. Module does not support add js by calling $this->js[] 
  105. wp_register_script('wysija-charts', 'https://www.google.com/jsapi', array( 'jquery' ), true); 
  106. wp_enqueue_script('wysija-charts'); 
  107. return $this->render().$this->hook_newsletter_action_buttons($params).$this->hook_newsletter_top_links($params); 
  108.  
  109. /** 
  110. * @param array $params 
  111. * array( 
  112. * 'email_id' => int,  
  113. * 'email_object' => array( 
  114. * 'email_id' => int,  
  115. * 'campaign_id' => int,  
  116. * 'subject' => string,  
  117. * 'body' => html,  
  118. * 'created_at' => int,  
  119. * 'modified_at' => int,  
  120. * 'sent_at' => int,  
  121. * 'from_email' => string,  
  122. * 'from_name' => string,  
  123. * 'replyto_email' => string,  
  124. * 'replyto_name' => string,  
  125. * 'attachments' => ?,  
  126. * 'status' => int,  
  127. * 'type' => int,  
  128. * 'number_sent' => int,  
  129. * 'number_opened' => int,  
  130. * 'number_clicked' => int,  
  131. * 'number_unsub' => int,  
  132. * 'number_bounce' => int,  
  133. * 'number_forward' => int,  
  134. * 'params' => array( 
  135. * 'quickselection' => array(),  
  136. * 'divider' => array(),  
  137. * 'googletrackingcode' => string,  
  138. * 'schedule' => array(),  
  139. * 'theme' => string 
  140. * ),  
  141. * 'wj_data' => string, (base64) 
  142. * 'wj_styles' => string (base64) 
  143. * ) 
  144. * ) 
  145. * @return html 
  146. */ 
  147. public function hook_newsletter_bottom($params = array( )) { 
  148. $html = ''; 
  149. $html .= $this->hook_newsletter_top_links($params); 
  150. return $html; 
  151.  
  152. protected function hook_newsletter_top_links($params = array( )) { 
  153. $this->data['top_links'] = $this->model_obj->get_top_links($params['email_id'], null); 
  154. foreach ($this->data['top_links'] as &$top_link) { 
  155. $top_link['is_viewing'] = !empty($params['url_id']) && $top_link['url_id'] == $params['url_id']; 
  156. $this->view_show = 'hook_newsletter_top_links'; 
  157. return $this->render(); 
  158.  
  159. protected function hook_newsletter_action_buttons($params = array( )) { 
  160. if (empty($params['email_id']) || empty($params['email_object']) || empty($params['email_object']['campaign_id'])) 
  161. return; 
  162. $this->data = array_merge($this->data, $params); 
  163. $this->data['lists'] = $this->model_obj->get_lists($params['email_object']['campaign_id']); 
  164. $this->data['bounce'] = $this->get_bounce_address(); 
  165. $this->view_show = 'hook_newsletter_action_buttons'; 
  166. return $this->render(); 
  167.  
  168. /** 
  169. * Get bounce email address 
  170. * @return string 
  171. */ 
  172. protected function get_bounce_address() { 
  173. $bounce_address = null; 
  174. $config_model = WYSIJA::get('config', 'model'); 
  175. // Test email, host, logi, password to make sure at least Bounce was fully configured 
  176. if ($config_model->getValue('bounce_email') 
  177. && $config_model->getValue('bounce_host') 
  178. && $config_model->getValue('bounce_login') 
  179. && $config_model->getValue('bounce_password') 
  180. ) { 
  181. $bounce_address = $config_model->getValue('bounce_email'); 
  182. return $bounce_address; 
  183.  
  184. /** 
  185. * Get emails stats data, and prepare for Google.visualization.dataTable 
  186. * @param array $params 
  187. * @return array 
  188. */ 
  189. protected function get_emails_stats($params) { 
  190. $emails_stats = $this->model_obj->get_email_status($params['email_id']); 
  191. $_data = array( ); 
  192. foreach ($this->emails_status as $status => $desc) { 
  193. $_data[$desc] = isset($emails_stats[$status]) ? $emails_stats[$status] : 0; 
  194.  
  195. return array( 
  196. 'title' => $params['chart_title'],  
  197. 'columns' => array( 
  198. array( 
  199. 'type' => 'string',  
  200. 'label' => __('Rate', WYSIJA) 
  201. ),  
  202. array( 
  203. 'type' => 'number',  
  204. 'label' => __('Rate', WYSIJA) 
  205. ),  
  206. ),  
  207. 'data' => $_data 
  208. ); 
  209.