BxDolStudioWidget.php 3.6 KB

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