BxDolStudioWidgets.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup DolphinStudio Dolphin Studio
  7. * @{
  8. */
  9. bx_import('BxTemplStudioPage');
  10. bx_import('BxDolStudioWidgetsQuery');
  11. define('BX_DOL_STUDIO_WS_ENABLED', 1);
  12. define('BX_DOL_STUDIO_WS_DISABLED', 2);
  13. class BxDolStudioWidgets extends BxTemplStudioPage
  14. {
  15. protected $sCacheKeyNotices = 'std_widgets_notices';
  16. protected $aWidgets;
  17. protected $aWidgetsNotices;
  18. public function __construct($mixedPageName)
  19. {
  20. parent::__construct($mixedPageName);
  21. $this->oDb = BxDolStudioWidgetsQuery::getInstance();
  22. $this->aWidgets = array();
  23. $this->aWidgetsNotices = array();
  24. if(!$this->bPageMultiple)
  25. $this->oDb->getWidgets(array('type' => 'by_page_id', 'value' => $this->aPage['id']), $this->aWidgets, false);
  26. else
  27. foreach($this->aPage as $sPage => $aPage) {
  28. $this->aWidgets[$sPage] = array();
  29. $this->oDb->getWidgets(array('type' => 'by_page_id', 'value' => $aPage['id']), $this->aWidgets[$sPage], false);
  30. }
  31. //--- Load Cache (Widgets' Notices)
  32. $oCache = $this->oDb->getDbCacheObject();
  33. $sCacheKey = $this->oDb->genDbCacheKey($this->sCacheKeyNotices);
  34. $this->aWidgetsNotices = $oCache->getData($sCacheKey);
  35. }
  36. public function isEnabled($aWidget)
  37. {
  38. return true;
  39. }
  40. public function updateCache()
  41. {
  42. $aWidgets = array();
  43. $this->oDb->getWidgets(array('type' => 'all_with_notices'), $aWidgets, false);
  44. $aResult = array();
  45. foreach($aWidgets as $aWidget) {
  46. if(BxDolService::isSerializedService($aWidget['cnt_notices'])) {
  47. $aService = unserialize($aWidget['cnt_notices']);
  48. $sNotices = BxDolService::call($aService['module'], $aService['method'], array_merge(array($aWidget), $aService['params']), $aService['class']);
  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. /** @} */