BxDolQueuePush.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 BxDolQueuePush extends BxDolQueue implements iBxDolSingleton
  10. {
  11. protected function __construct()
  12. {
  13. parent::__construct();
  14. $this->_oQuery = new BxDolQueuePushQuery();
  15. $this->_iLimitSend = (int)getParam('sys_push_queue_send_per_start');
  16. $this->_iLimitSendPerRecipient = (int)getParam('sys_push_queue_send_per_start_to_recipient');
  17. }
  18. /**
  19. * Get singleton instance of the class
  20. */
  21. static function getInstance()
  22. {
  23. if(!isset($GLOBALS['bxDolClasses'][__CLASS__]))
  24. $GLOBALS['bxDolClasses'][__CLASS__] = new BxDolQueuePush();
  25. return $GLOBALS['bxDolClasses'][__CLASS__];
  26. }
  27. /**
  28. * Add message to push queue
  29. *
  30. * @param integer $iProfileId - recipient profile ID
  31. * @param array $aMessage - array with Push message
  32. * @return true on success, false on error
  33. */
  34. public function add($iProfileId, $aMessage)
  35. {
  36. return (int)$this->_oQuery->insertItem(array(
  37. 'profile_id' => $iProfileId,
  38. 'message' => serialize($aMessage)
  39. )) > 0;
  40. }
  41. /**
  42. * Internal method which performs sending using predefined list of params.
  43. */
  44. protected function _send($iProfileId, $sMessage)
  45. {
  46. if(isset($this->_aSentTo[$iProfileId]) && (int)$this->_aSentTo[$iProfileId] >= $this->_iLimitSendPerRecipient)
  47. return false;
  48. if(!BxDolPush::getInstance()->send($iProfileId, unserialize($sMessage)))
  49. return false;
  50. if(!isset($this->_aSentTo[$iProfileId]))
  51. $this->_aSentTo[$iProfileId] = 0;
  52. $this->_aSentTo[$iProfileId] += 1;
  53. return true;
  54. }
  55. }
  56. /** @} */