WYSIJA_model_user_list

The MailPoet Newsletters WYSIJA model user list class.

Defined (1)

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

/models/user_list.php  
  1. class WYSIJA_model_user_list extends WYSIJA_model{ 
  2.  
  3. var $pk=array("list_id", "user_id"); 
  4. var $table_name="user_list"; 
  5. var $columns=array( 
  6. 'list_id'=>array("req"=>true, "type"=>"integer"),  
  7. 'user_id'=>array("req"=>true, "type"=>"integer"),  
  8. 'sub_date' => array("type"=>"integer"),  
  9. 'unsub_date' => array("type"=>"integer") 
  10. ); 
  11.  
  12. function __construct() { 
  13. parent::__construct(); 
  14.  
  15. function hook_subscriber_to_list( $details ) { 
  16.  
  17. $config=WYSIJA::get('config', 'model'); 
  18. $modelUser=WYSIJA::get('user', 'model'); 
  19. $userdata=$modelUser->getOne(false, array('user_id'=>$details['user_id'])); 
  20. $confirmed=true; 
  21.  
  22. /** do not send email if user is not confirmed*/ 
  23. /**if($config->getValue('confirm_dbleoptin') && (int)$userdata['status']!=1) $confirmed=false; 
  24.   
  25. if($confirmed) { 
  26. $helperU=WYSIJA::get('user', 'helper'); 
  27. $helperU->sendAutoNl($details['user_id'], array(0=>$details)); 
  28. }*/ 
  29. $dbloptin=$config->getValue('confirm_dbleoptin'); 
  30. /**only if dbleoptin has been deactivated we send immediately the post notification*/ 
  31.  
  32. if(!$dbloptin || ($dbloptin && (int)$userdata['status']>0)) { 
  33. /**check for auto nl and send if needed*/ 
  34. $helperU=WYSIJA::get('user', 'helper'); 
  35. if(isset($this->backSave) && $this->backSave) { 
  36. $helperU->sendAutoNl($details['user_id'], array(0=>$details), 'subs-2-nl', true); 
  37. }else{ 
  38. $helperU->sendAutoNl($details['user_id'], array(0=>$details)); 
  39.  
  40. return true; 
  41.  
  42. function afterInsert($resultSaveID) { 
  43. if(!isset($this->nohook)) { 
  44. add_action('wysija_subscribed_to', array($this, 'hook_subscriber_to_list'), 1); 
  45.  
  46. do_action('wysija_subscribed_to', $this->values); 
  47.  
  48. /** 
  49. * Get public lists of users 
  50. * @param array $user_ids list of user ids 
  51. * @return array 
  52. * <pre> 
  53. * array( 
  54. * int => array(int, int, ..., int), // user_id => array(list_id, list_id, ..., list_id) 
  55. * int => array(),  
  56. * ... 
  57. * int => array() 
  58. * ) 
  59. */ 
  60. public function get_lists(Array $user_ids = array()) { 
  61. $user_lists = array(); 
  62. if (!empty($user_ids)) { 
  63. $query = ' 
  64. SELECT 
  65. `user_id`,  
  66. GROUP_CONCAT(ul.`list_id`) AS `lists` 
  67. FROM 
  68. `[wysija]user_list` ul 
  69. JOIN 
  70. `[wysija]list` l 
  71. ON 
  72. l.`list_id` = ul.`list_id` 
  73. AND ul.`user_id` IN ('.implode(', ', $user_ids).') 
  74. WHERE 
  75. l.`is_enabled` = 1 
  76. GROUP BY 
  77. `user_id`'; 
  78. $result = $this->get_results($query); 
  79. if (!empty($result)) { 
  80. foreach ($result as $record) { 
  81. $user_lists[$record['user_id']] = explode(', ', $record['lists']); 
  82. return $user_lists; 
  83.