Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Portfolio: Duplicate post in sessión when commenting if portfolio_sho…
…w_base_course_post_in_sessions is enabled - refs BT#22232
  • Loading branch information
AngelFQC committed Dec 23, 2024
commit a025de461aa7447446a9eab77f30a2a48ef8c642
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;
}
}
Loading