- Created localization JSON files for multiple languages (e.g., Danish, German, Greek, English, Spanish, etc.) for CAkten and CAktenCDokumente. - Added layout configurations for CAkten, including detail views, side panels, and bottom panels. - Implemented metadata definitions for CAkten, including field definitions, relationship panels, and scopes. - Introduced new JSON files for managing document relationships and listing configurations.
84 lines
2.5 KiB
PHP
84 lines
2.5 KiB
PHP
<?php
|
|
namespace Espo\Custom\Hooks\CAkten;
|
|
|
|
use Espo\ORM\Entity;
|
|
use Espo\Core\Hook\Hook\AfterSave;
|
|
|
|
/**
|
|
* Hook: Propagiert Dokumenten-Änderungen von Akten nach oben zu Räumungsklage/Mietinkasso
|
|
*
|
|
* Wenn ein Dokument einer Akte zugewiesen wird (via cAktenId):
|
|
* → verknüpfe mit verbundener Räumungsklage/Mietinkasso
|
|
*/
|
|
class PropagateDocumentsUp implements AfterSave
|
|
{
|
|
private static array $processing = [];
|
|
|
|
public function __construct(
|
|
private \Espo\ORM\EntityManager $entityManager
|
|
) {}
|
|
|
|
public function afterSave(Entity $entity, \Espo\ORM\Repository\Option\SaveOptions $options): void
|
|
{
|
|
// Only process when cAktenId changed
|
|
if (!$entity->isAttributeChanged('cAktenId')) {
|
|
return;
|
|
}
|
|
|
|
$akteId = $entity->get('cAktenId');
|
|
if (!$akteId) {
|
|
return;
|
|
}
|
|
|
|
$key = $akteId . '-' . $entity->getId() . '-propagate';
|
|
if (isset(self::$processing[$key])) {
|
|
return;
|
|
}
|
|
self::$processing[$key] = true;
|
|
|
|
try {
|
|
$akte = $this->entityManager->getEntity('CAkten', $akteId);
|
|
if (!$akte) {
|
|
return;
|
|
}
|
|
|
|
$raumungsklage = $this->entityManager
|
|
->getRDBRepository('CAkten')
|
|
->getRelation($akte, 'vmhRumungsklage')
|
|
->findOne();
|
|
|
|
if ($raumungsklage) {
|
|
$this->relateDocument($raumungsklage, 'dokumentesvmhraumungsklage', $entity);
|
|
}
|
|
|
|
$mietinkasso = $this->entityManager
|
|
->getRDBRepository('CAkten')
|
|
->getRelation($akte, 'mietinkasso')
|
|
->findOne();
|
|
|
|
if ($mietinkasso) {
|
|
$this->relateDocument($mietinkasso, 'dokumentesmietinkasso', $entity);
|
|
}
|
|
|
|
} catch (\Exception $e) {
|
|
$GLOBALS['log']->error('CAkten PropagateDocumentsUp Error: ' . $e->getMessage());
|
|
} finally {
|
|
unset(self::$processing[$key]);
|
|
}
|
|
}
|
|
|
|
private function relateDocument(Entity $parentEntity, string $relationName, Entity $document): void
|
|
{
|
|
$repository = $this->entityManager->getRDBRepository($parentEntity->getEntityType());
|
|
$relation = $repository->getRelation($parentEntity, $relationName);
|
|
|
|
$isRelated = $relation
|
|
->where(['id' => $document->getId()])
|
|
->findOne();
|
|
|
|
if (!$isRelated) {
|
|
$relation->relate($document);
|
|
}
|
|
}
|
|
}
|