From a025de461aa7447446a9eab77f30a2a48ef8c642 Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos <1697880+AngelFQC@users.noreply.github.com> Date: Mon, 23 Dec 2024 17:53:13 -0500 Subject: [PATCH] =?UTF-8?q?Portfolio:=20Duplicate=20post=20in=20sessi?= =?UTF-8?q?=C3=B3n=20when=20commenting=20if=20portfolio=5Fshow=5Fbase=5Fco?= =?UTF-8?q?urse=5Fpost=5Fin=5Fsessions=20is=20enabled=20-=20refs=20BT#2223?= =?UTF-8?q?2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/inc/lib/PortfolioController.php | 14 ++++++++++++++ src/Chamilo/CoreBundle/Entity/Portfolio.php | 18 ++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/main/inc/lib/PortfolioController.php b/main/inc/lib/PortfolioController.php index 7a86905db2..53b3675a6e 100644 --- a/main/inc/lib/PortfolioController.php +++ b/main/inc/lib/PortfolioController.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']); diff --git a/src/Chamilo/CoreBundle/Entity/Portfolio.php b/src/Chamilo/CoreBundle/Entity/Portfolio.php index b31e54e704..a4045ac473 100644 --- a/src/Chamilo/CoreBundle/Entity/Portfolio.php +++ b/src/Chamilo/CoreBundle/Entity/Portfolio.php @@ -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; + } }