Skip to content

Commit 419aebf

Browse files
Merge pull request #6504 from christianbeeznest/rna-22255
Course: Fix catalogue shows private courses and fallback radios - refs BT#22255
2 parents 38850d4 + daf4f97 commit 419aebf

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

public/main/inc/lib/extra_field.lib.php

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,9 +1194,7 @@ public function set_extra_fields_in_form(
11941194
break;
11951195
case self::FIELD_TYPE_RADIO:
11961196
$group = [];
1197-
if (isset($field_details['options']) &&
1198-
!empty($field_details['options'])
1199-
) {
1197+
if (isset($field_details['options']) && !empty($field_details['options'])) {
12001198
foreach ($field_details['options'] as $option_details) {
12011199
$options[$option_details['option_value']] = $option_details['display_text'];
12021200
$group[] = $form->createElement(
@@ -1207,6 +1205,33 @@ public function set_extra_fields_in_form(
12071205
$option_details['option_value']
12081206
);
12091207
}
1208+
} else {
1209+
// Fallback: Yes/No
1210+
$currentValue = $extraData["extra_$variable"] ?? null;
1211+
1212+
$group[] = $form->createElement(
1213+
'radio',
1214+
'extra_'.$variable,
1215+
'1',
1216+
get_lang('Yes').'<br />',
1217+
'1'
1218+
);
1219+
$group[] = $form->createElement(
1220+
'radio',
1221+
'extra_'.$variable,
1222+
'0',
1223+
get_lang('No').'<br />',
1224+
'0'
1225+
);
1226+
1227+
// Select default if nothing set
1228+
if (!isset($currentValue)) {
1229+
if (!empty($field_details['default_value'])) {
1230+
$form->setDefaults(['extra_'.$variable => $field_details['default_value']]);
1231+
} else {
1232+
$form->setDefaults(['extra_'.$variable => '0']);
1233+
}
1234+
}
12101235
}
12111236
$form->addGroup(
12121237
$group,

src/CoreBundle/State/PublicCatalogueCourseStateProvider.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
5353
}
5454

5555
$host = $request->getSchemeAndHttpHost().'/';
56+
$hidePrivateCourses = 'true' === $this->settingsManager->getSetting('platform.course_catalog_hide_private', true);
57+
$visibilities = $hidePrivateCourses
58+
? [Course::OPEN_WORLD, Course::OPEN_PLATFORM]
59+
: [Course::OPEN_WORLD, Course::OPEN_PLATFORM, Course::REGISTERED];
5660

5761
/** @var AccessUrl $accessUrl */
5862
$accessUrl = $this->accessUrlRepository->findOneBy(['url' => $host]) ?? $this->accessUrlRepository->find(1);
@@ -61,7 +65,7 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
6165
->andWhere('url_rel.url = :accessUrl')
6266
->andWhere('c.visibility IN (:visibilities)')
6367
->setParameter('accessUrl', $accessUrl->getId())
64-
->setParameter('visibilities', [Course::OPEN_WORLD, Course::OPEN_PLATFORM])
68+
->setParameter('visibilities', $visibilities)
6569
->orderBy('c.title', 'ASC')
6670
->getQuery()
6771
->getResult()

0 commit comments

Comments
 (0)