BxBaseStudioAPI.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 UnaView UNA Studio Representation classes
  7. * @ingroup UnaStudio
  8. * @{
  9. */
  10. class BxBaseStudioAPI extends BxDolStudioAPI
  11. {
  12. protected $sSubpageUrl;
  13. protected $aMenuItems;
  14. protected $aGridObjects;
  15. public function __construct($sPage = '')
  16. {
  17. parent::__construct($sPage);
  18. $this->aPageCss = array_merge($this->aPageCss, ['forms.css', 'paginate.css']);
  19. $this->sSubpageUrl = BX_DOL_URL_STUDIO . 'api.php?page=';
  20. $this->aMenuItems = array(
  21. BX_DOL_STUDIO_API_TYPE_SETTINGS => array('icon' => 'cogs'),
  22. BX_DOL_STUDIO_API_TYPE_CONFIG => array('icon' => 'cogs'),
  23. BX_DOL_STUDIO_API_TYPE_ORIGINS => array('icon' => 'globe'),
  24. BX_DOL_STUDIO_API_TYPE_KEYS => array('icon' => 'key'),
  25. );
  26. $this->aGridObjects = [
  27. 'keys' => 'sys_studio_api_keys',
  28. 'origins' => 'sys_studio_api_origins',
  29. 'configs' => 'sys_studio_api_configs',
  30. ];
  31. }
  32. public function getPageMenu($aMenu = array(), $aMarkers = array())
  33. {
  34. $sJsObject = $this->getPageJsObject();
  35. $aMenu = array();
  36. foreach($this->aMenuItems as $sMenuItem => $aItem)
  37. $aMenu[] = array(
  38. 'name' => $sMenuItem,
  39. 'icon' => $aItem['icon'],
  40. 'link' => $this->sSubpageUrl . $sMenuItem,
  41. 'title' => _t('_adm_lmi_cpt_' . $sMenuItem),
  42. 'selected' => $sMenuItem == $this->sPage
  43. );
  44. return parent::getPageMenu($aMenu);
  45. }
  46. protected function getSettings()
  47. {
  48. $oOptions = new BxTemplStudioOptions(BX_DOL_STUDIO_STG_TYPE_DEFAULT, [
  49. 'api_general',
  50. 'api_layout'
  51. ]);
  52. $this->aPageCss = array_merge($this->aPageCss, $oOptions->getCss());
  53. $this->aPageJs = array_merge($this->aPageJs, $oOptions->getJs());
  54. return $oOptions->getCode();
  55. }
  56. protected function getApiConfig()
  57. {
  58. $oOptions = new BxTemplStudioOptionsApi(BX_DOL_STUDIO_STG_TYPE_DEFAULT, [
  59. 'api_config'
  60. ]);
  61. $this->aPageCss = array_merge($this->aPageCss, $oOptions->getCss());
  62. $this->aPageJs = array_merge($this->aPageJs, $oOptions->getJs());
  63. return [[
  64. 'caption' => '_adm_api_page_block_title_config_system',
  65. 'content' => $oOptions->getCode() . $this->getPageJsCode()
  66. ], [
  67. 'caption' => '_adm_api_page_block_title_config_modules',
  68. 'content' => $this->getGrid($this->aGridObjects['configs'])
  69. ]];
  70. }
  71. protected function getKeys()
  72. {
  73. return $this->getGrid($this->aGridObjects['keys']);
  74. }
  75. protected function getOrigins()
  76. {
  77. return $this->getGrid($this->aGridObjects['origins']);
  78. }
  79. protected function getGrid($sObjectName)
  80. {
  81. $oGrid = BxDolGrid::getObjectInstance($sObjectName);
  82. if(!$oGrid)
  83. return '';
  84. return $oGrid->getCode();
  85. }
  86. }
  87. /** @} */