1
0

BxBaseStudioAgentsTools.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 BxBaseStudioAgentsTools extends BxDolStudioAgentsInstruments
  11. {
  12. protected $_sUrlPage;
  13. public function __construct ($aOptions, $oTemplate = false)
  14. {
  15. parent::__construct ($aOptions, $oTemplate);
  16. $this->_sUrlPage = BX_DOL_URL_STUDIO . 'agents.php?page=tools';
  17. if (!empty($this->_aOptions['source']) && is_string($this->_aOptions['source']))
  18. $this->_aOptions['source'] = BxDolAiAgentTools::excludeHiddenFromSource($this->_aOptions['source']);
  19. }
  20. public function performActionDuplicate()
  21. {
  22. return parent::_performActionDuplicate('getToolById', 'insertTool');
  23. }
  24. public function performActionEdit()
  25. {
  26. return $this->_performActionEdit('getToolById', '_sys_agents_tools_popup_edit');
  27. }
  28. protected function _getForm($sAction = '', $aTool = [])
  29. {
  30. $sJsObject = $this->getPageJsObject();
  31. if (empty($aTool['params_user'])) {
  32. $aTool['params_user'] = $aTool['params'];
  33. }
  34. $data = json_decode($aTool['params_user'], true);
  35. $aTool['params_user'] = json_encode($data, JSON_PRETTY_PRINT);
  36. $oParsedown = new Parsedown();
  37. $oParsedown->setSafeMode(false);
  38. $sDocs = $oParsedown->text($aTool['docs']);
  39. return [
  40. 'form_attrs' => [
  41. 'id' => 'bx_std_agents_tools_' . $sAction,
  42. 'action' => BX_DOL_URL_ROOT . 'grid.php?o=sys_studio_agents_tools&a=' . $sAction,
  43. 'method' => 'post',
  44. ],
  45. 'params' => array (
  46. 'db' => array(
  47. 'table' => 'sys_agents_tools',
  48. 'key' => 'id',
  49. 'submit_name' => 'do_submit',
  50. ),
  51. ),
  52. 'inputs' => [
  53. 'docs' => [
  54. 'type' => 'custom',
  55. 'name' => 'docs',
  56. 'caption' => '',
  57. 'content' => $sDocs,
  58. ],
  59. 'title' => [
  60. 'type' => 'text',
  61. 'name' => 'title',
  62. 'caption' => _t('_sys_agents_field_title'),
  63. 'required' => true,
  64. 'value' => !empty($aTool['title']) ? $aTool['title'] : '',
  65. 'db' => [
  66. 'pass' => 'Xss'
  67. ]
  68. ],
  69. 'params_user' => [
  70. 'type' => 'textarea',
  71. 'name' => 'params_user',
  72. 'caption' => _t('_sys_agents_tools_field_params'),
  73. 'info' => _t('_sys_agents_tools_field_params_info'),
  74. 'required' => false,
  75. 'value' => !empty($aTool['params_user']) ? $aTool['params_user'] : '',
  76. 'checker' => [
  77. 'func' => 'Json',
  78. 'params' => ['allow_empty' => true],
  79. 'error' => _t('_sys_agents_json_field_err'),
  80. ],
  81. 'db' => [
  82. 'pass' => 'All'
  83. ]
  84. ],
  85. 'submit' => $this->_getFormControls(),
  86. ]
  87. ];
  88. }
  89. protected function _delete ($mixedId)
  90. {
  91. $aTool = $this->_oDb->getToolById($mixedId);
  92. if (empty($aTool) || $aTool['duplicate'] == 0)
  93. return false;
  94. return parent::_delete($mixedId);
  95. }
  96. }
  97. /** @} */