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