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