WYSIJA_model_list

The MailPoet Newsletters WYSIJA model list class.

Defined (1)

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

/models/list.php  
  1. class WYSIJA_model_list extends WYSIJA_model{ 
  2.  
  3. var $pk='list_id'; 
  4. var $table_name='list'; 
  5. var $columns=array( 
  6. 'list_id'=>array('auto'=>true),  
  7. 'name' => array('req'=>true, 'type'=>'text'),  
  8. 'namekey' => array('req'=>true, 'type'=>'text'),  
  9. 'description' => array('type'=>'text'),  
  10. 'unsub_mail_id' => array('req'=>true, 'type'=>'integer'),  
  11. 'welcome_mail_id' => array('req'=>true, 'type'=>'integer'),  
  12. 'is_enabled' => array('req'=>true, 'type'=>'boolean'),  
  13. 'is_public' => array('req'=>true, 'type'=>'boolean'),  
  14. 'ordering' => array('req'=>true, 'type'=>'integer'),  
  15. 'created_at' => array('req'=>true, 'type'=>'integer'),  
  16. ); 
  17. var $escapeFields=array('name', 'description'); 
  18. var $escapingOn=true; 
  19.  
  20. function __construct() { 
  21. $this->columns['name']['label']=__('Name', WYSIJA); 
  22. $this->columns['description']['label']=__('Description', WYSIJA); 
  23. $this->columns['is_enabled']['label']=__('Enabled', WYSIJA); 
  24. $this->columns['ordering']['label']=__('Ordering', WYSIJA); 
  25. parent::__construct(); 
  26.  
  27. function beforeInsert() { 
  28. if(!isset($this->values['namekey']) || !$this->values['namekey']) { 
  29. if(isset($this->values['name'])) $this->values['namekey']=sanitize_title($this->values['name']); 
  30. return true; 
  31.  
  32. function get_one_list($list_id) { 
  33. $query='SELECT A.name, A.list_id, A.description, A.is_enabled, A.is_public, A.namekey 
  34. FROM '.$this->getPrefix().'list as A 
  35. LEFT JOIN '.$this->getPrefix().'email as B on A.welcome_mail_id=B.email_id 
  36. WHERE A.list_id='.(int)$list_id; 
  37. $result = $this->getResults($query); 
  38. $this->escapeQuotesFromRes($result); 
  39. return $result[0]; 
  40.  
  41. /** 
  42. * get the detail about list(s) total of subscribers, unsubscribers, unconfirmed etc 
  43. * @param int $list_id 
  44. * @return type 
  45. */ 
  46. function getLists() { 
  47. $model_user = WYSIJA::get('user', 'model'); 
  48.  
  49. $query='SELECT A.`name`, A.`list_id`, A.`created_at`, A.`is_enabled`, A.`is_public`, A.`namekey`, 0 as subscribers, 0 as campaigns_sent 
  50. FROM '.$this->getPrefix().'list as A ORDER BY A.`name`'; 
  51.  
  52. $this->countRows=$this->count($query); 
  53.  
  54. if(isset($this->_limitison) && $this->_limitison) $query.=$this->setLimit(); 
  55. $result_lists=$this->getResults($query); 
  56.  
  57. $lists_details=array(); 
  58.  
  59. foreach($result_lists as $result) { 
  60. $lists_details[$result['list_id']]=$result; 
  61.  
  62. $list_ids = array_keys($lists_details); 
  63.  
  64.  
  65. $model_config = WYSIJA::get('config' , 'model'); 
  66. if($model_config->getValue('speed_no_count')) { 
  67. // we disable the count in order to speed up the process 
  68. $counts_per_list = array(); 
  69. }else{ 
  70. // these count requests can take a lot of time on big databases, we need to change the db diagram slightly to improve that 
  71. $counts_per_list = $model_user->count_users_per_list($list_ids); 
  72.  
  73.  
  74. // get the count of confirmed user per each and unconfirmed user per list 
  75. foreach($lists_details as $key_list_id => &$result) { 
  76. if(isset($counts_per_list[$key_list_id])) { 
  77. foreach($counts_per_list[$key_list_id] as $property => $value) { 
  78. $result[$property] = $value; 
  79.  
  80.  
  81. // we need to fill in the count value that will be used by the dropdown 
  82. // the value will depend on the status filter 
  83. foreach($lists_details as $key_list_id => &$result) { 
  84.  
  85. if(!isset($result['unsubscribers'])) $result['unsubscribers'] = 0; 
  86. if(!isset($result['subscribers'])) $result['subscribers'] = 0; 
  87. if(!isset($result['unconfirmed'])) $result['unconfirmed'] = 0; 
  88. if(!isset($result['belonging'])) $result['belonging'] = 0; 
  89.  
  90. if(!empty($_REQUEST['link_filter'])) { 
  91. switch($_REQUEST['link_filter']) { 
  92. case 'unsubscribed' : 
  93. $result['users'] = $result['unsubscribers']; 
  94. break; 
  95. case 'subscribed' : 
  96. $result['users'] = $result['subscribers']; 
  97. break; 
  98. case 'unconfirmed' : 
  99. $result['users'] = $result['unconfirmed']; 
  100. break; 
  101. default : 
  102.  
  103. $result['users'] = $result['belonging']; 
  104. }else{ 
  105. $result['users'] = $result['belonging']; 
  106.  
  107.  
  108.  
  109. $this->escapeQuotesFromRes($lists_details); 
  110. return $lists_details; 
  111.