Add getSuggestedUsers method in EntityWorkflowManager

Implemented the method to retrieve a list of suggested users for an entity workflow, filtering out duplicates. Added corresponding unit tests to verify the method's functionality and ensure its correctness in various scenarios.
This commit is contained in:
2024-10-22 23:35:13 +02:00
parent c877076429
commit 85dc9bdb2f
2 changed files with 76 additions and 0 deletions

View File

@@ -12,6 +12,7 @@ declare(strict_types=1);
namespace Chill\MainBundle\Workflow;
use Chill\DocStoreBundle\Entity\StoredObject;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Entity\Workflow\EntityWorkflow;
use Chill\MainBundle\Entity\Workflow\EntityWorkflowSend;
use Chill\MainBundle\Workflow\Exception\HandlerNotFoundException;
@@ -93,4 +94,30 @@ class EntityWorkflowManager
throw new HandlerWithPublicViewNotFoundException();
}
/**
* @return list<User>
*/
public function getSuggestedUsers(EntityWorkflow $entityWorkflow, bool $addUsersInvolved = true): array
{
$users = [];
if ($addUsersInvolved) {
foreach ($entityWorkflow->getUsersInvolved() as $user) {
$users[] = $user;
}
}
foreach ($this->getHandler($entityWorkflow)->getSuggestedUsers($entityWorkflow) as $user) {
$users[] = $user;
}
return array_values(
// filter objects to remove duplicates
array_filter(
$users,
fn ($o, $k) => array_search($o, $users, true) === $k,
ARRAY_FILTER_USE_BOTH
)
);
}
}