BxDolStudioWidget.php 3.4 KB

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