72 lines
2.1 KiB
PHP
72 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace Espo\Custom\Api\JunctionData;
|
|
|
|
use Espo\Core\Api\Action;
|
|
use Espo\Core\Api\Request;
|
|
use Espo\Core\Api\Response;
|
|
use Espo\Core\Api\ResponseComposer;
|
|
use Espo\Core\Exceptions\BadRequest;
|
|
use Espo\Core\Exceptions\NotFound;
|
|
use Espo\ORM\EntityManager;
|
|
|
|
/**
|
|
* GET /api/v1/JunctionData/CAIKnowledge/:knowledgeId/dokumentes
|
|
*
|
|
* Returns all documents linked to a knowledge entry with junction table data
|
|
*/
|
|
class GetDokumentes implements Action
|
|
{
|
|
public function __construct(
|
|
private EntityManager $entityManager
|
|
) {}
|
|
|
|
public function process(Request $request): Response
|
|
{
|
|
$knowledgeId = $request->getRouteParam('knowledgeId');
|
|
|
|
if (!$knowledgeId) {
|
|
throw new BadRequest('Knowledge ID is required');
|
|
}
|
|
|
|
// Verify knowledge exists
|
|
$knowledge = $this->entityManager->getEntityById('CAIKnowledge', $knowledgeId);
|
|
if (!$knowledge) {
|
|
throw new NotFound('Knowledge entry not found');
|
|
}
|
|
|
|
$pdo = $this->entityManager->getPDO();
|
|
|
|
$sql = "
|
|
SELECT
|
|
j.id as junctionId,
|
|
j.c_a_i_knowledge_id as cAIKnowledgeId,
|
|
j.c_dokumente_id as cDokumenteId,
|
|
j.ai_document_id as aiDocumentId,
|
|
j.syncstatus,
|
|
j.last_sync as lastSync,
|
|
d.id as documentId,
|
|
d.name as documentName,
|
|
d.blake3hash as blake3hash,
|
|
d.created_at as documentCreatedAt,
|
|
d.modified_at as documentModifiedAt
|
|
FROM c_a_i_knowledge_dokumente j
|
|
INNER JOIN c_dokumente d ON j.c_dokumente_id = d.id
|
|
WHERE j.c_a_i_knowledge_id = :knowledgeId
|
|
AND j.deleted = 0
|
|
AND d.deleted = 0
|
|
ORDER BY j.id DESC
|
|
";
|
|
|
|
$sth = $pdo->prepare($sql);
|
|
$sth->execute(['knowledgeId' => $knowledgeId]);
|
|
|
|
$results = $sth->fetchAll(\PDO::FETCH_ASSOC);
|
|
|
|
return ResponseComposer::json([
|
|
'total' => count($results),
|
|
'list' => $results
|
|
]);
|
|
}
|
|
}
|