Portfolio: Duplicate post in sessión when commenting if portfolio_show_base_course_post_in_sessions is enabled - refs BT#22232

pull/6001/head
Angel Fernando Quiroz Campos 9 months ago
parent 918416a844
commit a025de461a
No known key found for this signature in database
GPG Key ID: B284841AE3E562CD
  1. 14
      main/inc/lib/PortfolioController.php
  2. 18
      src/Chamilo/CoreBundle/Entity/Portfolio.php

@ -3974,6 +3974,20 @@ class PortfolioController
$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']);

@ -407,4 +407,22 @@ class Portfolio
{
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…
Cancel
Save