BxBaseStudioAPI.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 = array(
  27. 'keys' => 'sys_studio_api_keys',
  28. 'origins' => 'sys_studio_api_origins',
  29. );
  30. }
  31. public function getPageMenu($aMenu = array(), $aMarkers = array())
  32. {
  33. $sJsObject = $this->getPageJsObject();
  34. $aMenu = array();
  35. foreach($this->aMenuItems as $sMenuItem => $aItem)
  36. $aMenu[] = array(
  37. 'name' => $sMenuItem,
  38. 'icon' => $aItem['icon'],
  39. 'link' => $this->sSubpageUrl . $sMenuItem,
  40. 'title' => _t('_adm_lmi_cpt_' . $sMenuItem),
  41. 'selected' => $sMenuItem == $this->sPage
  42. );
  43. return parent::getPageMenu($aMenu);
  44. }
  45. protected function getSettings()
  46. {
  47. $oOptions = new BxTemplStudioOptions(BX_DOL_STUDIO_STG_TYPE_DEFAULT, [
  48. 'api_general',
  49. 'api_layout'
  50. ]);
  51. $this->aPageCss = array_merge($this->aPageCss, $oOptions->getCss());
  52. $this->aPageJs = array_merge($this->aPageJs, $oOptions->getJs());
  53. return $oOptions->getCode();
  54. }
  55. protected function getApiConfig()
  56. {
  57. $oOptions = new BxTemplStudioOptionsApi(BX_DOL_STUDIO_STG_TYPE_DEFAULT, [
  58. 'api_config'
  59. ]);
  60. return $oOptions->getCode() . $this->getPageJsCode();
  61. }
  62. protected function getKeys()
  63. {
  64. return $this->getGrid($this->aGridObjects['keys']);
  65. }
  66. protected function getOrigins()
  67. {
  68. return $this->getGrid($this->aGridObjects['origins']);
  69. }
  70. protected function getGrid($sObjectName)
  71. {
  72. $oGrid = BxDolGrid::getObjectInstance($sObjectName);
  73. if(!$oGrid)
  74. return '';
  75. return $oGrid->getCode();
  76. }
  77. }
  78. /** @} */