MCPcopy Create free account
hub / github.com/Rello/analytics / ContextChatManager

Class ContextChatManager

lib/ContextChat/ContextChatManager.php:19–121  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17use OCA\Analytics\Service\DatasetService;
18
19class ContextChatManager {
20 private $userId;
21 private $logger;
22 private $l10n;
23 private $StorageService;
24 private $DatasetService;
25 private $ContentManager;
26
27 public function __construct(
28 $userId,
29 IL10N $l10n,
30 LoggerInterface $logger,
31 StorageService $StorageService,
32 DatasetService $DatasetService,
33 ContentManager $ContentManager
34 ) {
35 $this->userId = $userId;
36 $this->l10n = $l10n;
37 $this->logger = $logger;
38 $this->StorageService = $StorageService;
39 $this->DatasetService = $DatasetService;
40 $this->ContentManager = $ContentManager;
41 }
42
43 /**
44 * Providers can use this to submit content for indexing in context chat
45 *
46 * @param int $datasetId
47 * @return bool
48 * @throws Exception
49 */
50 public function submitContent(int $datasetId): bool {
51 $datasetMetadata = $this->DatasetService->read($datasetId);
52 if ($datasetMetadata['ai_index'] !== 1) return false;
53
54 $columns = $datasetMetadata['dimension1'] .', '.$datasetMetadata['dimension2'].', '.$datasetMetadata['value'];
55
56 $storageData = $this->StorageService->read($datasetId, null);
57 $data = array_map(function ($subArray) {
58 return implode(",", $subArray);
59 }, $storageData['data']);
60 $dataString = implode("\n", $data);
61
62 $content = 'This is a set of statistical data. The name of the report is: ' . $datasetMetadata['name'] . '. ';
63 $content .= 'The description of the data is: ' . $datasetMetadata['subheader'] . '. ';
64 $content .= 'The data comes in multiple rows which 3 columns separated by a comma. ';
65 $content .= 'The columns are ' . $columns . '. ';
66 $content .= 'The data is: ' . $dataString;
67
68 $contentItem = new ContentItem(
69 $datasetId,
70 'report',
71 $datasetMetadata['name'],
72 $content,
73 'Report',
74 new \DateTime(),
75 [$datasetMetadata['user_id']]
76 );

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected