BxBaseLiveUpdates.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. * Load and cache(if it's needed) default(system)
  24. * live updates for current user.
  25. */
  26. $aCached = $this->_getCachedData();
  27. $aParams = array_merge(array(
  28. 'sActionsUrl' => BX_DOL_URL_ROOT . 'live_updates.php',
  29. 'sObjName' => $this->_sJsObject,
  30. 'iInterval' => $this->_iInterval,
  31. 'aSystemsActive' => array_intersect_key($aCached, array_flip($this->_aSystemsActive)),
  32. 'aSystemsTransient' => array_flip($this->_aSystemsTransient),
  33. 'bServerRequesting' => !empty($this->_aSystems),
  34. 'sHash' => base64_encode($this->_sCacheKey),
  35. ), $aParams);
  36. $sContent = "var " . $this->_sJsObject . " = new " . $this->_sJsClass . "(" . json_encode($aParams) . ");";
  37. $oTemplate = BxDolTemplate::getInstance();
  38. $oTemplate->addJs(array('BxDolLiveUpdates.js'));
  39. return $oTemplate->_wrapInTagJsCode($sContent);
  40. }
  41. public function add($sName, $iFrequency, $sServiceCall, $bActive = true)
  42. {
  43. $sCacheKey = $this->_sCacheKey;
  44. $mixedResult = parent::add($sName, $iFrequency, $sServiceCall, $bActive);
  45. if($mixedResult === false)
  46. return '';
  47. $aParams = array('name' => $sName, 'value' => $mixedResult);
  48. if($sCacheKey != $this->_sCacheKey)
  49. $aParams['hash'] = base64_encode($this->_sCacheKey);
  50. $sContent = "if(" . $this->_sJsObject . " != undefined) " . $this->_sJsObject . ".add(" . json_encode($aParams) . ");";
  51. return BxDolTemplate::getInstance()->_wrapInTagJsCode($sContent);
  52. }
  53. }
  54. /** @} */