Skip to content

Commit a025de4

Browse files
committed
Portfolio: Duplicate post in sessión when commenting if portfolio_show_base_course_post_in_sessions is enabled - refs BT#22232
1 parent 918416a commit a025de4

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

main/inc/lib/PortfolioController.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3974,6 +3974,20 @@ private function createCommentForm(Portfolio $item): string
39743974
$form->addButtonSave(get_lang('Save'));
39753975

39763976
if ($form->validate()) {
3977+
if ($this->session
3978+
&& true === api_get_configuration_value('portfolio_show_base_course_post_in_sessions')
3979+
&& !$item->getSession()
3980+
) {
3981+
$duplicate = $item->duplicateInSession($this->session);
3982+
3983+
$this->em->persist($duplicate);
3984+
$this->em->flush();
3985+
3986+
$item = $duplicate;
3987+
3988+
$formAction = $this->baseUrl.http_build_query(['action' => 'view', 'id' => $item->getId()]);
3989+
}
3990+
39773991
$values = $form->exportValues();
39783992

39793993
$parentComment = $this->em->find(PortfolioComment::class, $values['parent']);

src/Chamilo/CoreBundle/Entity/Portfolio.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,4 +407,22 @@ public function isDuplicatedInSessionId(int $sessionId): bool
407407
{
408408
return $this->duplicates->exists(fn($key, Portfolio $duplicated): bool => $duplicated->session && $duplicated->session->getId() === $sessionId);
409409
}
410+
411+
public function reset()
412+
{
413+
$this->id = null;
414+
$this->duplicates = new ArrayCollection();
415+
$this->comments = new ArrayCollection();
416+
}
417+
418+
public function duplicateInSession(Session $session): Portfolio
419+
{
420+
$duplicate = clone $this;
421+
$duplicate->reset();
422+
423+
$duplicate->setSession($session);
424+
$this->addDuplicate($duplicate);
425+
426+
return $duplicate;
427+
}
410428
}

0 commit comments

Comments
 (0)