Skip to content

Commit

Permalink
Portfolio: Duplicate post in sessión when commenting if portfolio_sho…
Browse files Browse the repository at this point in the history
…w_base_course_post_in_sessions is enabled - refs BT#22232
  • Loading branch information
AngelFQC committed Dec 23, 2024
1 parent 918416a commit a025de4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
14 changes: 14 additions & 0 deletions main/inc/lib/PortfolioController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3974,6 +3974,20 @@ private function createCommentForm(Portfolio $item): string
$form->addButtonSave(get_lang('Save'));

if ($form->validate()) {
if ($this->session
&& true === api_get_configuration_value('portfolio_show_base_course_post_in_sessions')
&& !$item->getSession()
) {
$duplicate = $item->duplicateInSession($this->session);

$this->em->persist($duplicate);
$this->em->flush();

$item = $duplicate;

$formAction = $this->baseUrl.http_build_query(['action' => 'view', 'id' => $item->getId()]);
}

$values = $form->exportValues();

$parentComment = $this->em->find(PortfolioComment::class, $values['parent']);
Expand Down
18 changes: 18 additions & 0 deletions src/Chamilo/CoreBundle/Entity/Portfolio.php
Original file line number Diff line number Diff line change
Expand Up @@ -407,4 +407,22 @@ public function isDuplicatedInSessionId(int $sessionId): bool
{
return $this->duplicates->exists(fn($key, Portfolio $duplicated): bool => $duplicated->session && $duplicated->session->getId() === $sessionId);
}

public function reset()
{
$this->id = null;
$this->duplicates = new ArrayCollection();
$this->comments = new ArrayCollection();
}

public function duplicateInSession(Session $session): Portfolio
{
$duplicate = clone $this;
$duplicate->reset();

$duplicate->setSession($session);
$this->addDuplicate($duplicate);

return $duplicate;
}
}

0 comments on commit a025de4

Please sign in to comment.