BxDolQueue.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 BxDolQueue extends BxDolFactory
  10. {
  11. protected $_oQuery;
  12. protected function __construct()
  13. {
  14. if (isset($GLOBALS['bxDolClasses'][get_class($this)]))
  15. trigger_error ('Multiple instances are not allowed for the class: ' . get_class($this), E_USER_ERROR);
  16. parent::__construct();
  17. }
  18. /**
  19. * Prevent cloning the instance
  20. */
  21. public function __clone()
  22. {
  23. if (isset($GLOBALS['bxDolClasses'][get_class($this)]))
  24. trigger_error('Clone is not allowed for the class: ' . get_class($this), E_USER_ERROR);
  25. }
  26. /**
  27. * Send some number of email form mail queue
  28. *
  29. * @param int $iLimit - number of emails to send
  30. * @return real number of sent emails
  31. */
  32. public function send($iLimit = 1)
  33. {
  34. $aSent = array();
  35. $aMails = $this->_oQuery->getItems(array('type' => 'to_send', 'start' => 0, 'per_page' => $iLimit));
  36. foreach($aMails as $iId => $aMail)
  37. if(call_user_func_array(array($this, '_send'), array_slice($aMail, 1)))
  38. $aSent[] = $iId;
  39. if(!empty($aSent) && is_array($aSent))
  40. $this->_oQuery->deleteItem($aSent);
  41. return count($aSent);
  42. }
  43. }
  44. /** @} */