BxDolQueuePush.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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->_sParamTime = 'sys_push_queue_time';
  16. $this->_iLimitSend = (int)getParam('sys_push_queue_send_per_start');
  17. $this->_iLimitSendPerRecipient = (int)getParam('sys_push_queue_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 BxDolQueuePush();
  26. return $GLOBALS['bxDolClasses'][__CLASS__];
  27. }
  28. /**
  29. * Add message to push queue
  30. *
  31. * @param integer $iProfileId - recipient profile ID
  32. * @param array $aMessage - array with Push message
  33. * @return true on success, false on error
  34. */
  35. public function add($iProfileId, $aMessage)
  36. {
  37. return (int)$this->_oQuery->insertItem(array(
  38. 'profile_id' => $iProfileId,
  39. 'message' => serialize($aMessage)
  40. )) > 0;
  41. }
  42. /**
  43. * Internal method which performs sending using predefined list of params.
  44. */
  45. protected function _send($iProfileId, $sMessage)
  46. {
  47. if(isset($this->_aSentTo[$iProfileId]) && (int)$this->_aSentTo[$iProfileId] >= $this->_iLimitSendPerRecipient)
  48. return false;
  49. if(!BxDolPush::getObjectInstance()->send($iProfileId, unserialize($sMessage)))
  50. return false;
  51. if(!isset($this->_aSentTo[$iProfileId]))
  52. $this->_aSentTo[$iProfileId] = 0;
  53. $this->_aSentTo[$iProfileId] += 1;
  54. return true;
  55. }
  56. }
  57. /** @} */