BxDolStudioWidgets.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 UnaStudio UNA Studio
  7. * @{
  8. */
  9. define('BX_DOL_STUDIO_WS_ENABLED', 1);
  10. define('BX_DOL_STUDIO_WS_DISABLED', 2);
  11. define('BX_DOL_STUDIO_WTYPE_DEFAULT', '');
  12. class BxDolStudioWidgets extends BxTemplStudioPage
  13. {
  14. protected $sCacheKeyNotices = 'std_widgets_notices';
  15. protected $_sType;
  16. protected $aWidgets;
  17. protected $aWidgetsNotices;
  18. public function __construct($mixedPageName)
  19. {
  20. parent::__construct($mixedPageName);
  21. $this->oDb = BxDolStudioWidgetsQuery::getInstance();
  22. $this->_sType = BX_DOL_STUDIO_WTYPE_DEFAULT;
  23. if(($sType = bx_get('type')) !== false)
  24. $this->_sType = bx_process_input($sType);
  25. $this->aWidgets = array();
  26. $this->aWidgetsNotices = array();
  27. $sWType = $this->_sType != BX_DOL_STUDIO_WTYPE_DEFAULT ? $this->_sType : '';
  28. if(!$this->bPageMultiple) {
  29. $this->aWidgets = $this->oDb->getWidgets(array('type' => 'by_page_id', 'value' => $this->aPage['id'], 'wtype' => $sWType));
  30. }
  31. else
  32. foreach($this->aPage as $sPage => $aPage)
  33. $this->aWidgets[$sPage] = $this->oDb->getWidgets(array('type' => 'by_page_id', 'value' => $aPage['id'], 'wtype' => $sWType));
  34. //--- Load Cache (Widgets' Notices)
  35. $oCache = $this->oDb->getDbCacheObject();
  36. $sCacheKey = $this->oDb->genDbCacheKey($this->sCacheKeyNotices);
  37. $this->aWidgetsNotices = $oCache->getData($sCacheKey);
  38. }
  39. public function updateCache()
  40. {
  41. $aWidgets = $this->oDb->getWidgets(array('type' => 'all_with_notices'));
  42. $aResult = array();
  43. foreach($aWidgets as $aWidget) {
  44. $sNotices = '';
  45. if(BxDolService::isSerializedService($aWidget['cnt_notices'])) {
  46. $aService = BxDolService::decodeServiceCall($aWidget['cnt_notices']);
  47. if ($aService)
  48. $sNotices = BxDolService::call($aService['module'], $aService['method'], array_merge(array($aWidget), isset($aService['params']) ? $aService['params'] : array()), isset($aService['class']) ? $aService['class'] : 'Module');
  49. }
  50. $aResult[$aWidget['id']] = $sNotices;
  51. }
  52. $oCache = $this->oDb->getDbCacheObject();
  53. $sCacheKey = $this->oDb->genDbCacheKey($this->sCacheKeyNotices);
  54. return $oCache->setData($sCacheKey, $aResult);
  55. }
  56. }
  57. /** @} */