Skip to content

Commit 1753e92

Browse files
Course progress: Ensure new sections are active; fix breadcrumb - refs #7052
1 parent 51d3169 commit 1753e92

File tree

2 files changed

+62
-45
lines changed

2 files changed

+62
-45
lines changed

public/main/course_progress/index.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,11 @@ function update_done_thematic_advance(selected_value) {
206206
// get default thematic plan title
207207
$default_thematic_plan_title = $thematicManager->get_default_thematic_plan_title();
208208

209-
$tpl = new Template(get_lang('Thematic control'));
209+
$tpl = new Template('');
210+
$interbreadcrumb[] = [
211+
'url' => 'index.php?'.api_get_cidreq().'&action=thematic_details',
212+
'name' => get_lang('Thematic control')
213+
];
210214

211215
// Dispatch actions to controller
212216
switch ($action) {
@@ -225,8 +229,8 @@ function update_done_thematic_advance(selected_value) {
225229
if ('POST' === $requestMethod && '' !== trim($_POST['title']) &&
226230
api_is_allowed_to_edit(null, true)
227231
) {
228-
$title = trim($_POST['title']);
229-
$content = trim($_POST['content']);
232+
$title = trim($_POST['title'] ?? '');
233+
$content = trim($_POST['content'] ?? '');
230234
$thematicManager->thematicSave($thematicId, $title, $content, $course, $session);
231235
Display::addFlash(Display::return_message(get_lang('Update successful')));
232236

@@ -673,7 +677,6 @@ class="btn btn--default"
673677
$content = $tpl->fetch($thematicLayout);
674678
break;
675679
case 'thematic_list':
676-
$interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Thematic control')];
677680
if (!$readOnly) {
678681
$actionLeft = '<a href="index.php?'.api_get_cidreq().'&action=thematic_add'.$url_token.'">'.
679682
Display::getMdiIcon('progress-star', 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('New thematic section')).'</a>';
@@ -821,8 +824,8 @@ class="btn btn--default"
821824
case 'thematic_plan_list':
822825
if (!empty($thematicEntity)) {
823826
$interbreadcrumb[] = [
824-
'url' => '#',
825-
'name' => get_lang('Thematic plan').' ('.$cleanThematicTitle.') ',
827+
'url' => '#',
828+
'name' => get_lang('Thematic plan').' ('.$cleanThematicTitle.')',
826829
];
827830
}
828831

@@ -1210,8 +1213,10 @@ class="btn btn--default"
12101213
}
12111214
break;
12121215
case 'thematic_advance_list':
1213-
1214-
$interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Thematic advance').' ('.$cleanThematicTitle.')'];
1216+
$interbreadcrumb[] = [
1217+
'url' => '#',
1218+
'name' => get_lang('Thematic advance').' ('.$cleanThematicTitle.')',
1219+
];
12151220

12161221
// thematic advance list toolbar (local)
12171222
$actions = '<a href="'.api_get_self().'?'.api_get_cidreq().'&action=thematic_details">'.

public/main/inc/lib/thematic.lib.php

Lines changed: 49 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ public function thematicSave($id, $title, $content, Course $course, Session $ses
159159
->setContent($content)
160160
->setParent($course)
161161
->addCourseLink($course, $session)
162+
->setActive(true)
162163
;
163164

164165
$repo->create($thematic);
@@ -198,55 +199,66 @@ public function delete(int|array $thematicId): void
198199
}
199200

200201
/**
201-
* @param int $thematicId
202+
* Duplicate a thematic (title, content, plans and advances) into the same Course/Session.
202203
*/
203-
public function copy($thematicId)
204+
public function copy(int $thematicId, ?Course $course = null, ?Session $session = null): ?CThematic
204205
{
205206
$repo = Container::getThematicRepository();
206-
/** @var CThematic $thematic */
207-
$thematic = $repo->find($thematicId);
208-
if (null === $thematic) {
209-
return false;
207+
/** @var CThematic|null $source */
208+
$source = $repo->find($thematicId);
209+
if (!$source) {
210+
return null;
210211
}
211212

212-
$thematicManager = new Thematic();
213+
// Resolve context if not provided
214+
$course = $course ?: api_get_course_entity();
215+
$session = $session ?: api_get_session_entity();
213216

214-
$newThematic = $thematicManager->thematicSave(
217+
// Create the new thematic using the existing helper (keeps linking logic consistent)
218+
$new = $this->thematicSave(
215219
null,
216-
$thematic->getTitle().' - '.get_lang('Copy'),
217-
$thematic->getContent(),
218-
api_get_course_entity(),
219-
api_get_session_entity()
220+
(string) $source->getTitle(),
221+
(string) $source->getContent(),
222+
$course,
223+
$session
220224
);
221225

222-
if (!empty($newThematic->getIid())) {
223-
$thematic_advanced = $thematic->getAdvances();
224-
if (!empty($thematic_advanced)) {
225-
foreach ($thematic_advanced as $item) {
226-
$thematic = new Thematic();
227-
$thematic->thematicAdvanceSave(
228-
$newThematic,
229-
$item->getAttendance(),
230-
null,
231-
$item->getContent(),
232-
$item->getStartDate()->format('Y-m-d H:i:s'),
233-
$item->getDuration()
234-
);
235-
}
236-
}
226+
if (!$new) {
227+
return null;
228+
}
237229

238-
$thematic_plan = $thematic->getPlans();
239-
if (!empty($thematic_plan)) {
240-
foreach ($thematic_plan as $item) {
241-
$thematic->thematicPlanSave(
242-
$newThematic,
243-
$item->getTitle(),
244-
$item->getDescription(),
245-
$item->getDescriptionType()
246-
);
247-
}
230+
// Copy advances
231+
foreach ($source->getAdvances() as $adv) {
232+
// Normalize start date to string Y-m-d H:i:s for thematicAdvanceSave
233+
$startDate = $adv->getStartDate();
234+
if ($startDate instanceof \DateTimeInterface) {
235+
$startDate = $startDate->format('Y-m-d H:i:s');
236+
} else {
237+
$startDate = (string) $startDate;
248238
}
239+
240+
// Keep the same attendance relation if any (same course/session context)
241+
$this->thematicAdvanceSave(
242+
$new,
243+
$adv->getAttendance(),
244+
null,
245+
(string) $adv->getContent(),
246+
$startDate,
247+
(float) $adv->getDuration()
248+
);
249+
}
250+
251+
// Copy plans
252+
foreach ($source->getPlans() as $plan) {
253+
$this->thematicPlanSave(
254+
$new,
255+
(string) $plan->getTitle(),
256+
(string) $plan->getDescription(),
257+
(int) $plan->getDescriptionType()
258+
);
249259
}
260+
261+
return $new;
250262
}
251263

252264
/**

0 commit comments

Comments
 (0)