mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2026-03-12 00:47:45 +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];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user