BxDolAIToolCmtsAdd.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 UnaCore UNA Core
  7. * @{
  8. */
  9. use NeuronAI\Tools\PropertyType;
  10. use NeuronAI\Tools\ToolProperty;;
  11. class BxDolAIToolCmtsAdd extends BxDolAITool
  12. {
  13. public function __construct()
  14. {
  15. parent::__construct(
  16. 'comments_add',
  17. 'Use this tool to post comments.',
  18. );
  19. }
  20. protected function properties(): array
  21. {
  22. return [
  23. new ToolProperty(
  24. name: 'module',
  25. type: PropertyType::STRING,
  26. description: 'Module name of the content_id.',
  27. required: true
  28. ),
  29. new ToolProperty(
  30. name: 'content_id',
  31. type: PropertyType::INTEGER,
  32. description: 'Content ID where to to post comments.',
  33. required: true
  34. ),
  35. new ToolProperty(
  36. name: 'comment_text',
  37. type: PropertyType::STRING,
  38. description: 'Comments text to post, in HTML format.',
  39. required: true
  40. ),
  41. new ToolProperty(
  42. name: 'parent_comment_id',
  43. type: PropertyType::INTEGER,
  44. description: 'Parent comment ID, for comment replies, default 0.',
  45. required: false
  46. ),
  47. new ToolProperty(
  48. name: 'author_profile_id',
  49. type: PropertyType::INTEGER,
  50. description: 'Author profile ID of the posted comment.',
  51. required: false
  52. ),
  53. ];
  54. }
  55. public function __invoke(string $module, int $content_id, string $comment_text, ?int $parent_comment_id = null, ?int $author_profile_id = null): array
  56. {
  57. if ($author_profile_id) {
  58. $GLOBALS['glForceCurrentProfileId'] = $author_profile_id;
  59. }
  60. $a = [];
  61. $o = BxDolCmts::getObjectInstance($module, $content_id);
  62. if ($o) {
  63. $aData = [
  64. 'sys' => $module,
  65. 'id' => $content_id,
  66. 'cmt_parent_id' => $parent_comment_id ?? 0,
  67. // 'cmt_image' => [],
  68. 'cmt_text' => $comment_text,
  69. ];
  70. // if ($author_profile_id)
  71. // $aData['cmt_author_id'] = $author_profile_id;
  72. $a = $o->add($aData);
  73. unset($a['count']);
  74. unset($a['countf']);
  75. }
  76. else {
  77. $a = ['msg' => '_sys_txt_not_found', 'code' => 404];
  78. }
  79. $GLOBALS['glForceCurrentProfileId'] = 0;
  80. return $a;
  81. }
  82. }