BxDolAIToolCmtsGet.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 BxDolAIToolCmtsGet extends BxDolAITool
  12. {
  13. public function __construct()
  14. {
  15. parent::__construct(
  16. 'comments_get',
  17. 'Retrieve content\'s comments for a given module and content id. If needed, prepend base URL to links: ' . BX_DOL_URL_ROOT,
  18. );
  19. }
  20. protected function properties(): array
  21. {
  22. return [
  23. new ToolProperty(
  24. name: 'module',
  25. type: PropertyType::STRING,
  26. description: 'The module name to retrieve content info from. Use "system" for site accounts. ',
  27. required: true
  28. ),
  29. new ToolProperty(
  30. name: 'content_id',
  31. type: PropertyType::INTEGER,
  32. description: 'The ID of the content item to retrieve info for.',
  33. required: true
  34. ),
  35. new ToolProperty(
  36. name: 'per_page',
  37. type: PropertyType::INTEGER,
  38. description: 'Pagination, number of comments per page. Default is 10.',
  39. required: false
  40. ),
  41. new ToolProperty(
  42. name: 'start',
  43. type: PropertyType::INTEGER,
  44. description: 'Pagination, start showing comments starting from this number. Default is 0.',
  45. required: false
  46. ),
  47. ];
  48. }
  49. public function __invoke(string $module, int $content_id, int $per_page = 10, int $start = 0): array
  50. {
  51. $o = BxDolCmts::getObjectInstance($module, $content_id);
  52. if ($o->isEnabled()) {
  53. $a = $o->serviceGetAll([
  54. 'type' => 'latest',
  55. 'object_id' => $content_id,
  56. 'start' => $start,
  57. 'per_page' => $per_page
  58. ]);
  59. foreach ($a as $k => $r) {
  60. $a[$k] = $o->getDataAPI($r);
  61. }
  62. return $a;
  63. }
  64. else {
  65. return ['msg' => '_sys_txt_not_found', 'code' => 404];
  66. }
  67. }
  68. }