This repository has been archived on 2026-07-19. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
LegalAssistance/files/custom/Espo/Modules/LegalAssistance/Hooks/Case/CreateDirectAccessTasks.php
T
chaim e3dfd5f960 feat: LegalAssistance extension v1.0.0 — Direct Access Report
- DirectAccessReport entity (48 fields, status lifecycle, Case relationship)
- Case fields: cLegalAidType, cAppointmentDate, cAidType, cUrgencyLevel, cFilingDeadline
- Auto-tasks hook: creates 3 tasks when case set to Direct Access
- DOCX template with 72 placeholders (converted from original form)
- Shira plugin: generate_initial_report tool with structured conversation flow
- AfterInstall/AfterUninstall scripts for plugin deployment
- Hebrew + English translations

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-06 05:03:21 +00:00

77 lines
2.8 KiB
PHP

<?php
namespace Espo\Modules\LegalAssistance\Hooks\Case;
use Espo\ORM\Entity;
use Espo\ORM\EntityManager;
use Espo\Core\Utils\Log;
class CreateDirectAccessTasks
{
public function __construct(
private EntityManager $entityManager,
private Log $log
) {}
public function afterSave(Entity $entity, array $options): void
{
if (!empty($options['skipHooks'])) {
return;
}
if (!$entity->isAttributeChanged('cLegalAidType')) {
return;
}
$newValue = $entity->get('cLegalAidType');
$oldValue = $entity->getFetched('cLegalAidType');
if ($newValue !== 'DirectAccess' || $oldValue === 'DirectAccess') {
return;
}
$this->log->info("LegalAssistance: Creating direct access tasks for case {$entity->getId()}");
$assignedUserId = $entity->get('assignedUserId');
$now = new \DateTime('now', new \DateTimeZone('Asia/Jerusalem'));
$tasks = [
[
'name' => 'שיחת טלפון ראשונה עם הלקוח',
'dateEnd' => (clone $now)->modify('+2 days')->format('Y-m-d'),
'priority' => 'High',
'description' => 'יש ליצור קשר ראשוני עם הלקוח תוך 48 שעות ממועד קבלת המינוי.',
],
[
'name' => 'פגישה עם הלקוח',
'dateEnd' => (clone $now)->modify('+7 days')->format('Y-m-d'),
'priority' => 'Normal',
'description' => 'לקבוע ולקיים פגישה ראשונה עם הלקוח. לתעד נוכחים ותוכן הפגישה.',
],
[
'name' => 'שליחת דוח גישה ישירה',
'dateEnd' => (clone $now)->modify('+14 days')->format('Y-m-d'),
'priority' => 'High',
'description' => 'למלא ולשלוח דוח דיווח ראשוני לסיוע המשפטי. ניתן לבקש משירה: "תיצרי דוח גישה ישירה".',
],
];
foreach ($tasks as $taskData) {
$task = $this->entityManager->getNewEntity('Task');
$task->set([
'name' => $taskData['name'],
'status' => 'Not Started',
'priority' => $taskData['priority'],
'dateEnd' => $taskData['dateEnd'],
'description' => $taskData['description'],
'parentType' => 'Case',
'parentId' => $entity->getId(),
'assignedUserId' => $assignedUserId,
]);
$this->entityManager->saveEntity($task, ['skipHooks' => false]);
}
$this->log->info("LegalAssistance: Created 3 direct access tasks for case {$entity->getId()}");
}
}