- 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.
47 lines
1.3 KiB
PHP
47 lines
1.3 KiB
PHP
<?php
|
|
namespace Espo\Custom\Hooks\CPuls;
|
|
|
|
use Espo\ORM\Entity;
|
|
use Espo\Core\Hook\Hook\BeforeSave;
|
|
|
|
class UpdateTeamStats implements BeforeSave
|
|
{
|
|
public function __construct(
|
|
private \Espo\ORM\EntityManager $entityManager
|
|
) {}
|
|
|
|
public function beforeSave(Entity $entity, array $options): void
|
|
{
|
|
// Zähle Dokumente
|
|
if ($entity->isNew() || $entity->isAttributeChanged('id')) {
|
|
$dokumenteCount = $this->entityManager
|
|
->getRDBRepository('CDokumente')
|
|
->where(['pulsId' => $entity->getId()])
|
|
->count();
|
|
|
|
$entity->set('anzahlDokumente', $dokumenteCount);
|
|
}
|
|
|
|
// Zähle Team-Zuordnungen
|
|
$zuordnungen = $this->entityManager
|
|
->getRDBRepository('CPulsTeamZuordnung')
|
|
->where(['pulsId' => $entity->getId()])
|
|
->find();
|
|
|
|
$aktiv = 0;
|
|
$abgeschlossen = 0;
|
|
|
|
foreach ($zuordnungen as $z) {
|
|
if ($z->get('aktiv')) {
|
|
$aktiv++;
|
|
if ($z->get('abgeschlossen')) {
|
|
$abgeschlossen++;
|
|
}
|
|
}
|
|
}
|
|
|
|
$entity->set('anzahlTeamsAktiv', $aktiv);
|
|
$entity->set('anzahlTeamsAbgeschlossen', $abgeschlossen);
|
|
}
|
|
}
|