BxDolStudioWidget.php 3.8 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. public function __construct($mixedPageName)
  16. {
  17. parent::__construct($mixedPageName);
  18. $this->sPage = $this->sPageDefault;
  19. if(!$this->bPage)
  20. return;
  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. // Personal pin first (available to everyone), the shared pin beneath it (managers only).
  27. $this->addAction(array(
  28. 'type' => 'switcher',
  29. 'name' => 'bookmark',
  30. 'caption' => '_adm_txt_pca_bookmark',
  31. 'icon' => 'pin',
  32. 'checked' => $this->aPage['bookmark'],
  33. 'onchange' => "javascript:" . $sJsObjectLauncher . ".bookmark('" . $this->aPage['name'] . "', this)"
  34. ));
  35. if(BxDolStudioRolesUtils::getInstance()->isActionAllowed(BX_SRA_MANAGE_APPS))
  36. $this->addAction(array(
  37. 'type' => 'switcher',
  38. 'name' => 'featured',
  39. 'caption' => '_adm_txt_pca_featured',
  40. 'icon' => 'users',
  41. 'checked' => $this->aPage['featured'],
  42. 'onchange' => "javascript:" . $sJsObjectLauncher . ".featured('" . $this->aPage['name'] . "', this)"
  43. ));
  44. $this->addAction(array(
  45. 'type' => 'select',
  46. 'name' => 'rearrange',
  47. 'caption' => '_adm_txt_pca_rearrange',
  48. 'icon' => 'folder-input',
  49. 'value' => '{widget_type}',
  50. 'values' => BxDolFormQuery::getDataItems($this->_sTypesPreList),
  51. 'onchange' => "javascript:" . $sJsObjectLauncher . ".rearrange({widget_id}, this)"
  52. ));
  53. $this->aMarkers['page_name'] = $this->aPage['name'];
  54. }
  55. else
  56. foreach($this->aPage as $sName => $aPage)
  57. $this->aPage[$sName]['featured'] = $this->oDb->isFeatured($aPage);
  58. }
  59. public function addAction($aAction, $bOnRight = true)
  60. {
  61. if($bOnRight)
  62. $this->aActions[] = $aAction;
  63. else
  64. $this->aActions = array_merge(array($aAction), $this->aActions);
  65. }
  66. public function removeActions()
  67. {
  68. $this->aActions = array();
  69. }
  70. public function featured()
  71. {
  72. $bResult = $this->oDb->featured($this->aPage);
  73. if(!$bResult)
  74. return array('code' => 1, 'message' => _t('_adm_err_operation_failed'));
  75. $iWidgetId = (int)$this->aPage['wid_id'];
  76. return array(
  77. 'code' => 0,
  78. 'message' => _t('_adm_scs_operation_done'),
  79. 'widget_id' => $iWidgetId,
  80. 'widget' => !empty($this->aPage['wid_id']) ? BxTemplStudioFunctions::getInstance()->getWidget($iWidgetId) : ''
  81. );
  82. }
  83. public function bookmark()
  84. {
  85. $iProfileId = bx_get_logged_profile_id();
  86. $bResult = $this->oDb->bookmark($this->aPage, $iProfileId);
  87. if(!$bResult)
  88. return array('code' => 1, 'message' => _t('_adm_err_operation_failed'));
  89. return array('code' => 0, 'message' => _t('_adm_scs_operation_done'));
  90. }
  91. }
  92. /** @} */