Add vizualisation of public views in the workflow history

This commit is contained in:
2024-10-08 16:17:11 +02:00
parent b99ea3b17a
commit 40b8fae8ba
6 changed files with 93 additions and 8 deletions

View File

@@ -183,8 +183,45 @@ class EntityWorkflowSend implements TrackCreationInterface
return $this->views->count() > 0;
}
public function isExpired(\DateTimeImmutable $now): bool
public function isExpired(?\DateTimeImmutable $now = null): bool
{
return $now >= $this->expireAt;
return ($now ?? new \DateTimeImmutable('now')) >= $this->expireAt;
}
/**
* Retrieves the most recent view.
*
* @return EntityWorkflowSendView|null returns the last view or null if there are no views
*/
public function getLastView(): ?EntityWorkflowSendView
{
$last = null;
foreach ($this->views as $view) {
if (null === $last) {
$last = $view;
} else {
if ($view->getViewAt() > $last->getViewAt()) {
$last = $view;
}
}
}
return $last;
}
/**
* Retrieves an array of views grouped by their remote IP address.
*
* @return array<string, list<EntityWorkflowSendView>> an associative array where the keys are IP addresses and the values are arrays of views associated with those IPs
*/
public function getViewsByIp(): array
{
$views = [];
foreach ($this->getViews() as $view) {
$views[$view->getRemoteIp()][] = $view;
}
return $views;
}
}