BxBaseLiveUpdates.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 UnaBaseView UNA Base Representation Classes
  7. * @{
  8. */
  9. /**
  10. * @see BxDolLiveUpdates
  11. */
  12. class BxBaseLiveUpdates extends BxDolLiveUpdates
  13. {
  14. public function __construct()
  15. {
  16. parent::__construct();
  17. }
  18. public function init($aParams = array())
  19. {
  20. if(!$this->_iProfileId)
  21. return '';
  22. /*
  23. * Clear cache for current user.
  24. * It's needed to reset Transient live updates.
  25. */
  26. //$this->_clearCached();
  27. /*
  28. * Load and cache(if it's needed) default(system)
  29. * live updates for current user.
  30. */
  31. $aCached = $this->_getCachedData();
  32. $aParams = array_merge(array(
  33. 'sActionsUrl' => BX_DOL_URL_ROOT . 'live_updates.php',
  34. 'sObjName' => $this->_sJsObject,
  35. 'iInterval' => $this->_iInterval,
  36. 'aSystemsActive' => array_intersect_key($aCached, array_flip($this->_aSystemsActive)),
  37. 'aSystemsTransient' => array_flip($this->_aSystemsTransient),
  38. 'bServerRequesting' => !empty($this->_aSystems),
  39. 'sHash' => base64_encode($this->_sCacheKey),
  40. ), $aParams);
  41. $sContent = "var " . $this->_sJsObject . " = new " . $this->_sJsClass . "(" . json_encode($aParams) . ");";
  42. $oTemplate = BxDolTemplate::getInstance();
  43. $oTemplate->addJs(array('BxDolLiveUpdates.js'));
  44. return $oTemplate->_wrapInTagJsCode($sContent);
  45. }
  46. public function add($sName, $iFrequency, $sServiceCall, $bActive = true)
  47. {
  48. $sCacheKey = $this->_sCacheKey;
  49. $mixedResult = parent::add($sName, $iFrequency, $sServiceCall, $bActive);
  50. if($mixedResult === false)
  51. return '';
  52. $aParams = array('name' => $sName, 'value' => $mixedResult);
  53. if($sCacheKey != $this->_sCacheKey)
  54. $aParams['hash'] = base64_encode($this->_sCacheKey);
  55. $sContent = "if(" . $this->_sJsObject . " != undefined) " . $this->_sJsObject . ".add(" . json_encode($aParams) . ");";
  56. return BxDolTemplate::getInstance()->_wrapInTagJsCode($sContent);
  57. }
  58. }
  59. /** @} */