BxDolStudioWidget.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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_WGT_TYPE_SETTINGS', 'settings');
  10. define('BX_DOL_STUDIO_WGT_TYPE_DEFAULT', BX_DOL_STUDIO_WGT_TYPE_SETTINGS);
  11. class BxDolStudioWidget extends BxTemplStudioPage
  12. {
  13. protected $sPage;
  14. protected $sPageDefault = BX_DOL_STUDIO_WGT_TYPE_DEFAULT;
  15. protected $aActions;
  16. public function __construct($mixedPageName)
  17. {
  18. parent::__construct($mixedPageName);
  19. $this->sPage = $this->sPageDefault;
  20. $this->aActions = array();
  21. if(!$this->bPage)
  22. return;
  23. if(!$this->bPageMultiple) {
  24. $this->sPageRssHelpId = $this->aPage['name'];
  25. $this->aPage['featured'] = $this->oDb->isFeatured($this->aPage);
  26. $this->aPage['bookmark'] = $this->oDb->isBookmarked($this->aPage, bx_get_logged_profile_id());
  27. $sJsObjectLauncher = BxTemplStudioLauncher::getInstance()->getPageJsObject();
  28. if(BxDolStudioRolesUtils::getInstance()->isActionAllowed(BX_SRA_MANAGE_APPS))
  29. $this->addAction(array(
  30. 'type' => 'switcher',
  31. 'name' => 'featured',
  32. 'caption' => '_adm_txt_pca_featured',
  33. 'checked' => $this->aPage['featured'],
  34. 'onchange' => "javascript:" . $sJsObjectLauncher . ".featured('" . $this->aPage['name'] . "', this)"
  35. ));
  36. $this->addAction(array(
  37. 'type' => 'switcher',
  38. 'name' => 'bookmark',
  39. 'caption' => '_adm_txt_pca_bookmark',
  40. 'checked' => $this->aPage['bookmark'],
  41. 'onchange' => "javascript:" . $sJsObjectLauncher . ".bookmark('" . $this->aPage['name'] . "', this)"
  42. ));
  43. $this->addAction(array(
  44. 'type' => 'select',
  45. 'name' => 'rearrange',
  46. 'caption' => '_adm_txt_pca_rearrange',
  47. 'value' => '{widget_type}',
  48. 'values' => BxDolFormQuery::getDataItems($this->_sTypesPreList),
  49. 'onchange' => "javascript:" . $sJsObjectLauncher . ".rearrange({widget_id}, this)"
  50. ));
  51. $this->aMarkers['page_name'] = $this->aPage['name'];
  52. }
  53. else
  54. foreach($this->aPage as $sName => $aPage)
  55. $this->aPage[$sName]['featured'] = $this->oDb->isFeatured($aPage);
  56. }
  57. public function addAction($aAction, $bOnRight = true)
  58. {
  59. if($bOnRight)
  60. $this->aActions[] = $aAction;
  61. else
  62. $this->aActions = array_merge(array($aAction), $this->aActions);
  63. }
  64. public function removeActions()
  65. {
  66. $this->aActions = array();
  67. }
  68. public function featured()
  69. {
  70. $bResult = $this->oDb->featured($this->aPage);
  71. if(!$bResult)
  72. return array('code' => 1, 'message' => _t('_adm_err_operation_failed'));
  73. $iWidgetId = (int)$this->aPage['wid_id'];
  74. return array(
  75. 'code' => 0,
  76. 'message' => _t('_adm_scs_operation_done'),
  77. 'widget_id' => $iWidgetId,
  78. 'widget' => !empty($this->aPage['wid_id']) ? BxTemplStudioFunctions::getInstance()->getWidget($iWidgetId) : ''
  79. );
  80. }
  81. public function bookmark()
  82. {
  83. $iProfileId = bx_get_logged_profile_id();
  84. $bResult = $this->oDb->bookmark($this->aPage, $iProfileId);
  85. if(!$bResult)
  86. return array('code' => 1, 'message' => _t('_adm_err_operation_failed'));
  87. return array('code' => 0, 'message' => _t('_adm_scs_operation_done'));
  88. }
  89. }
  90. /** @} */