BxDolAIToolCmtsGetSingle.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 BxDolAIToolCmtsGetSingle extends BxDolAITool
  12. {
  13. public function __construct()
  14. {
  15. parent::__construct(
  16. 'comment_get',
  17. 'Get single comment info. Prepend base URL to links in comment info: ' . BX_DOL_URL_ROOT,
  18. );
  19. }
  20. protected function properties(): array
  21. {
  22. return [
  23. new ToolProperty(
  24. name: 'comment_id',
  25. type: PropertyType::INTEGER,
  26. description: 'ID of comment to get.',
  27. required: true
  28. ),
  29. ];
  30. }
  31. public function __invoke(int $comment_id): array
  32. {
  33. $aCmt = BxDolCmtsQuery::getCommentExtendedByUniqId($comment_id);
  34. $oCmtsObject = $aCmt ? BxDolCmts::getObjectInstance($aCmt['system_name'], $aCmt['cmt_object_id']) : null;
  35. if ($oCmtsObject) {
  36. return $oCmtsObject->getDataAPI($aCmt);
  37. }
  38. return ['msg' => '_sys_txt_not_found', 'code' => 404];
  39. }
  40. }