BxDolQueueEmail.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaCore UNA Core
  7. * @{
  8. */
  9. class BxDolQueueEmail extends BxDolQueue implements iBxDolSingleton
  10. {
  11. protected function __construct()
  12. {
  13. parent::__construct();
  14. $this->_oQuery = new BxDolQueueEmailQuery();
  15. $this->_sParamTime = 'sys_eq_time';
  16. $this->_iLimitSend = (int)getParam('sys_eq_send_per_start');
  17. $this->_iLimitSendPerRecipient = (int)getParam('sys_eq_send_per_start_to_recipient');
  18. }
  19. /**
  20. * Get singleton instance of the class
  21. */
  22. static function getInstance()
  23. {
  24. if(!isset($GLOBALS['bxDolClasses'][__CLASS__]))
  25. $GLOBALS['bxDolClasses'][__CLASS__] = new BxDolQueueEmail();
  26. return $GLOBALS['bxDolClasses'][__CLASS__];
  27. }
  28. /**
  29. * Add message to mail queue
  30. *
  31. * @param string $sEmail - recipient email
  32. * @param string $sSubject - message subject
  33. * @param string $sBody - message body
  34. * @return true on success, false on error
  35. */
  36. public function add($sEmail, $sSubject, $sBody, $iRecipientID, $aPlus, $iEmailType, $sEmailFlag, $isDisableAlert, $aCustomHeaders)
  37. {
  38. return (int)$this->_oQuery->insertItem(array(
  39. 'email' => $sEmail,
  40. 'subject' => $sSubject,
  41. 'body' => $sBody,
  42. 'params' => serialize(array($iRecipientID, $aPlus, $iEmailType, $sEmailFlag, $isDisableAlert, $aCustomHeaders))
  43. )) > 0;
  44. }
  45. /**
  46. * Internal method which performs sending using predefined list of params.
  47. */
  48. protected function _send($sEmail, $sSubject, $sBody, $sParams = '')
  49. {
  50. if(isset($this->_aSentTo[$sEmail]) && (int)$this->_aSentTo[$sEmail] >= $this->_iLimitSendPerRecipient)
  51. return false;
  52. $aParams = array();
  53. if(!empty($sParams))
  54. $aParams = unserialize($sParams);
  55. if (false === $aParams)
  56. return false;
  57. if(!call_user_func_array('sendMail', array_merge(array($sEmail, $sSubject, $sBody), $aParams)))
  58. return false;
  59. if(!isset($this->_aSentTo[$sEmail]))
  60. $this->_aSentTo[$sEmail] = 0;
  61. $this->_aSentTo[$sEmail] += 1;
  62. return true;
  63. }
  64. }
  65. /** @} */