feat(CPuls): Enhance CPuls entity with new fields, tooltips, and options; add localization for German and English

- Added new fields to CPuls entity including status, syncStatus, kiAnalyse, and others.
- Implemented localization for CPuls in German (de_DE) and English (en_US).
- Introduced new API actions for team activation and completion of CPuls.
- Created hooks to update team statistics and manage document counts.
- Added new entity definitions and metadata for CPulsTeamZuordnung and Team.
- Implemented validation logic in formulas to prevent completion of unclean Puls.
- Updated layouts for detail and list views of CPuls.
- Enhanced user entity with absence tracking fields.
- Added scopes for CPuls and CPulsTeamZuordnung.
This commit is contained in:
2026-02-13 10:09:19 +01:00
parent 0faf1c0657
commit e1a963ffab
22 changed files with 1073 additions and 374 deletions

View File

@@ -0,0 +1,121 @@
<?php
namespace Espo\Custom\Api\CPuls;
use Espo\Core\Api\Action;
use Espo\Core\Api\Request;
use Espo\Core\Api\Response;
use Espo\Core\Exceptions\BadRequest;
use Espo\Core\Exceptions\Forbidden;
use Espo\Core\Exceptions\NotFound;
class AbschliessenFuerTeam implements Action
{
public function __construct(
private \Espo\ORM\EntityManager $entityManager,
private \Espo\Core\Acl\Table $acl,
private \Espo\Entities\User $user,
private \Espo\Core\Utils\Log $log
) {}
public function process(Request $request): Response
{
$pulsId = $request->getRouteParam('id');
$data = $request->getParsedBody();
$teamId = $data->teamId ?? null;
if (!$pulsId || !$teamId) {
throw new BadRequest('pulsId oder teamId fehlt');
}
// 1. Validierung: Ist User in diesem Team?
$userTeams = $this->user->getLinkMultipleIdList('teams');
if (!in_array($teamId, $userTeams)) {
throw new Forbidden('User nicht in angegebenem Team');
}
// 2. Lade Puls
$puls = $this->entityManager->getEntity('CPuls', $pulsId);
if (!$puls) {
throw new NotFound('Puls nicht gefunden');
}
// 3. Validierung: syncStatus = clean?
if ($puls->get('syncStatus') !== 'clean') {
throw new BadRequest('Puls hat neue Dokumente (unclean) - bitte warten Sie auf die KI-Analyse');
}
// 4. Finde Zuordnung
$zuordnung = $this->entityManager
->getRDBRepository('CPulsTeamZuordnung')
->where([
'pulsId' => $pulsId,
'teamId' => $teamId,
'aktiv' => true
])
->findOne();
if (!$zuordnung) {
throw new NotFound('Team-Zuordnung nicht gefunden oder nicht aktiv');
}
// 5. Bereits abgeschlossen?
if ($zuordnung->get('abgeschlossen')) {
return Response::json([
'success' => true,
'message' => 'Bereits abgeschlossen',
'alreadyCompleted' => true
]);
}
// 6. Abschluss setzen
$zuordnung->set([
'abgeschlossen' => true,
'abgeschlossenAm' => date('Y-m-d H:i:s'),
'abgeschlossenVonId' => $this->user->getId()
]);
$this->entityManager->saveEntity($zuordnung);
// 6.5. FIRST-READ-CLOSES: Finalisiere Block bei erstem Abschluss
if (!$puls->get('finalisiert')) {
$puls->set([
'finalisiert' => true,
'finalisierungsGrund' => 'Erstes Team',
'finalisiertAm' => date('Y-m-d H:i:s'),
'finalisiertVonId' => $this->user->getId()
]);
$this->log->info("Block finalisiert durch erstes Team (Team {$teamId}, User {$this->user->getId()})");
}
// 7. Prüfe: Alle Teams abgeschlossen?
$offeneTeams = $this->entityManager
->getRDBRepository('CPulsTeamZuordnung')
->where([
'pulsId' => $pulsId,
'aktiv' => true,
'abgeschlossen' => false
])
->count();
// 8. Update Puls-Status
if ($offeneTeams === 0) {
$puls->set('status', 'Abgeschlossen');
} else {
$puls->set('status', 'Teilweise abgeschlossen');
}
$this->entityManager->saveEntity($puls);
$this->log->info("Team {$teamId} hat Puls {$pulsId} abgeschlossen");
return Response::json([
'success' => true,
'status' => $puls->get('status'),
'finalisiert' => $puls->get('finalisiert'),
'offeneTeams' => $offeneTeams
]);
}
}

View File

@@ -0,0 +1,99 @@
<?php
namespace Espo\Custom\Api\CPuls;
use Espo\Core\Api\Action;
use Espo\Core\Api\Request;
use Espo\Core\Api\Response;
use Espo\Core\Exceptions\BadRequest;
use Espo\Core\Exceptions\NotFound;
class AktiviereTeams implements Action
{
public function __construct(
private \Espo\ORM\EntityManager $entityManager,
private \Espo\Core\Utils\Log $log
) {}
public function process(Request $request): Response
{
$id = $request->getRouteParam('id');
if (!$id) {
throw new BadRequest('ID fehlt');
}
$puls = $this->entityManager->getEntity('CPuls', $id);
if (!$puls) {
throw new NotFound('Puls nicht gefunden');
}
$data = $request->getParsedBody();
// 1. Update Puls
$puls->set([
'kiAnalyse' => $data->kiAnalyse ?? null,
'zusammenfassung' => $data->zusammenfassung ?? null,
'status' => $data->status ?? 'Bereit',
'syncStatus' => $data->syncStatus ?? 'clean'
]);
$this->entityManager->saveEntity($puls);
// 2. Lösche alte Zuordnungen (soft delete - setze inaktiv)
$this->entityManager
->getQueryBuilder()
->update()
->in('CPulsTeamZuordnung')
->set(['aktiv' => false])
->where(['pulsId' => $id])
->execute();
// 3. Erstelle neue Zuordnungen
if (isset($data->teams) && is_array($data->teams)) {
foreach ($data->teams as $teamData) {
$teamId = $teamData->teamId ?? null;
if (!$teamId) {
$this->log->warning("Team-ID fehlt in teams-Array");
continue;
}
// Prüfe ob bereits existiert
$existing = $this->entityManager
->getRDBRepository('CPulsTeamZuordnung')
->where([
'pulsId' => $id,
'teamId' => $teamId
])
->findOne();
if ($existing) {
// Reaktiviere
$existing->set([
'aktiv' => true,
'abgeschlossen' => false,
'prioritaet' => $teamData->prioritaet ?? 'Normal'
]);
$this->entityManager->saveEntity($existing);
} else {
// Erstelle neu
$zuordnung = $this->entityManager->createEntity('CPulsTeamZuordnung', [
'pulsId' => $id,
'teamId' => $teamId,
'aktiv' => true,
'abgeschlossen' => false,
'prioritaet' => $teamData->prioritaet ?? 'Normal'
]);
}
}
}
$this->log->info("Teams aktiviert für Puls {$id}");
return Response::json([
'success' => true,
'pulsId' => $id
]);
}
}