mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-24 07:35:03 +00:00
Resolve "Fusion actions d'accompagnement"
This commit is contained in:
@@ -63,4 +63,28 @@ class PrivateCommentEmbeddable
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges comments from the provided object into the current object.
|
||||
*
|
||||
* Identifies common user IDs between the current object's comments and the
|
||||
* newComment's comments. If a user ID exists in both, their comments are
|
||||
* concatenated with the provided separator. If a user ID exists only in the
|
||||
* newComment, their comment is added to the current object directly.
|
||||
*
|
||||
* @param self $commentsToAppend the object containing the new comments to be merged
|
||||
* @param string $separator the string used to separate concatenated comments
|
||||
*/
|
||||
public function concatenateComments(self $commentsToAppend, string $separator = "\n\n-----------\n\n"): void
|
||||
{
|
||||
$commonUserIds = array_intersect(array_keys($this->comments), array_keys($commentsToAppend->getComments()));
|
||||
|
||||
foreach ($commentsToAppend->getComments() as $userId => $comment) {
|
||||
if (in_array($userId, $commonUserIds, true)) {
|
||||
$this->comments[$userId] = $this->comments[$userId].$separator.$commentsToAppend->getComments()[$userId];
|
||||
} else {
|
||||
$this->comments[$userId] = $commentsToAppend->getComments()[$userId];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -61,6 +61,9 @@ export interface ConflictHttpExceptionInterface
|
||||
|
||||
/**
|
||||
* Generic api method that can be adapted to any fetch request
|
||||
*
|
||||
* This method is suitable make a single fetch. When performing a GET to fetch a list of elements, always consider pagination
|
||||
* and use of the @link{fetchResults} method.
|
||||
*/
|
||||
export const makeFetch = <Input, Output>(
|
||||
method: "POST" | "GET" | "PUT" | "PATCH" | "DELETE",
|
||||
|
@@ -200,3 +200,7 @@ export interface WorkflowAttachment {
|
||||
updatedBy: User | null;
|
||||
genericDoc: null | GenericDoc;
|
||||
}
|
||||
|
||||
export interface PrivateCommentEmbeddable {
|
||||
comments: Record<number, string>;
|
||||
}
|
||||
|
@@ -11,10 +11,12 @@ const appMessages = {
|
||||
user: "Utilisateurs",
|
||||
person: "Usagers",
|
||||
thirdparty: "Tiers",
|
||||
acpw: "Action d'accompagnements",
|
||||
modal_title_one: "Indiquer un ",
|
||||
user_one: "Utilisateur",
|
||||
thirdparty_one: "Tiers",
|
||||
person_one: "Usager",
|
||||
acpw_one: "Action d'accompagnement",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
@@ -266,6 +266,27 @@
|
||||
data-label="{{ form.vars['label']|trans|escape('html_attr') }}"></div>
|
||||
{% endblock %}
|
||||
|
||||
{% block pick_linked_entities_row %}
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
{{ form_label(form) }}
|
||||
{{ form_help(form) }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="row justify-content-end">
|
||||
<div class="col-md-7 col-sm-12">
|
||||
{{ form_widget(form) }}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block pick_linked_entities_widget %}
|
||||
<input type="hidden" {{ block('widget_attributes') }} {% if value is not empty %}value="{{ value|escape('html_attr') }}" {% endif %} data-input-uniqid="{{ form.vars['uniqid'] }}" />
|
||||
<div data-input-uniqid="{{ form.vars['uniqid'] }}" data-module="pick-linked-entities" data-pick-entities-type="{{ form.vars['pick-entities-type'] }}"
|
||||
></div>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block pick_postal_code_widget %}
|
||||
{{ form_help(form)}}
|
||||
<input type="hidden" {{ block('widget_attributes') }} {% if value is not empty %}value="{{ value }}" {% endif %} data-input-uniqid="{{ form.vars['uniqid'] }}"/>
|
||||
|
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Tests\Entity\Workflow;
|
||||
|
||||
use Chill\MainBundle\Entity\Embeddable\PrivateCommentEmbeddable;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Prophecy\PhpUnit\ProphecyTrait;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @coversNothing
|
||||
*/
|
||||
class PrivateCommentEmbeddableTest extends TestCase
|
||||
{
|
||||
use ProphecyTrait;
|
||||
|
||||
public function testConcatenateComment(): void
|
||||
{
|
||||
$userA = $this->prophesize(User::class);
|
||||
$userA->getId()->willReturn(1);
|
||||
$userB = $this->prophesize(User::class);
|
||||
$userB->getId()->willReturn(2);
|
||||
$userC = $this->prophesize(User::class);
|
||||
$userC->getId()->willReturn(3);
|
||||
|
||||
$toKeep = new PrivateCommentEmbeddable();
|
||||
$toKeep->setCommentForUser($userA->reveal(), 'My comment for A');
|
||||
$toKeep->setCommentForUser($userB->reveal(), 'My comment for B');
|
||||
|
||||
$toDelete = new PrivateCommentEmbeddable();
|
||||
$toDelete->setCommentForUser($userC->reveal(), 'My comment for C');
|
||||
$toDelete->setCommentForUser($userB->reveal(), 'Another comment for B');
|
||||
|
||||
$toKeep->concatenateComments($toDelete, '----');
|
||||
|
||||
self::assertTrue($toKeep->hasCommentForUser($userA->reveal()));
|
||||
self::assertEquals('My comment for A', $toKeep->getCommentForUser($userA->reveal()));
|
||||
|
||||
self::assertTrue($toKeep->hasCommentForUser($userB->reveal()));
|
||||
self::assertEquals('My comment for B----Another comment for B', $toKeep->getCommentForUser($userB->reveal()));
|
||||
|
||||
self::assertTrue($toKeep->hasCommentForUser($userC->reveal()));
|
||||
self::assertEquals('My comment for C', $toKeep->getCommentForUser($userC->reveal()));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user