Merge pull request #5008 from christianbeeznest/ofaj-21133-2

Platform: Improve sidebar menu for course or sessions items - refs BT#21133
pull/5009/head
christianbeeznest 12 months ago committed by GitHub
commit 736a163281
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 22
      src/CoreBundle/Controller/CourseController.php
  2. 29
      src/CoreBundle/Settings/PlatformSettingsSchema.php

@ -901,7 +901,7 @@ class CourseController extends ToolBaseController
}
#[Route('/check-enrollments', name: 'chamilo_core_check_enrollments', methods: ['GET'])]
public function checkEnrollments(EntityManagerInterface $em): JsonResponse
public function checkEnrollments(EntityManagerInterface $em, SettingsManager $settingsManager): JsonResponse
{
/** @var User|null $user */
$user = $this->getUser();
@ -911,9 +911,14 @@ class CourseController extends ToolBaseController
}
$isEnrolledInCourses = $this->isUserEnrolledInAnyCourse($user, $em);
$isEnrolledInSessions = $this->isUserEnrolledInAnySession($user, $em);
if (!$isEnrolledInCourses && !$isEnrolledInSessions) {
$defaultMenuEntry = $settingsManager->getSetting('platform.default_menu_entry_for_course_or_session');
$isEnrolledInCourses = 'my_courses' === $defaultMenuEntry;
$isEnrolledInSessions = 'my_sessions' === $defaultMenuEntry;
}
return new JsonResponse([
'isEnrolledInCourses' => $isEnrolledInCourses,
'isEnrolledInSessions' => $isEnrolledInSessions,
@ -923,19 +928,20 @@ class CourseController extends ToolBaseController
// Implement the real logic to check course enrollment
private function isUserEnrolledInAnyCourse(User $user, EntityManagerInterface $em): bool
{
$enrollment = $em
$enrollmentCount = $em
->getRepository(CourseRelUser::class)
->findOneBy(['user' => $user]);
->count(['user' => $user]);
return null !== $enrollment;
return $enrollmentCount > 0;
}
// Implement the real logic to check session enrollment
private function isUserEnrolledInAnySession(User $user, EntityManagerInterface $em): bool
{
$enrollment = $em->getRepository(SessionRelUser::class)
->findOneBy(['user' => $user]);
$enrollmentCount = $em->getRepository(SessionRelUser::class)
->count(['user' => $user]);
return null !== $enrollment;
return $enrollmentCount > 0;
}
}

@ -39,10 +39,6 @@ class PlatformSettingsSchema extends AbstractSettingsSchema
'institution_url' => 'http://www.chamilo.org',
'institution_address' => '',
'site_name' => 'Chamilo site',
// 'administrator_email' => 'admin@example.org',
// 'administrator_name' => 'Jane',
// 'administrator_surname' => 'Doe',
// 'administrator_phone' => '123456',
'timezone' => 'Europe/Paris',
'theme' => 'chamilo',
'gravatar_enabled' => 'false',
@ -60,13 +56,8 @@ class PlatformSettingsSchema extends AbstractSettingsSchema
'keep_old_images_after_delete' => 'true',
'load_term_conditions_section' => 'login',
'server_type' => 'prod',
// Chamilo mode
'show_tabs' => array_values(self::$tabs),
'chamilo_database_version' => '2.0.0',
//
//('catalog_show_courses_sessions', '0', 'CatalogueShowOnlyCourses'),
//('catalog_show_courses_sessions', '1', 'CatalogueShowOnlySessions'),
//('catalog_show_courses_sessions', '2', 'CatalogueShowCoursesAndSessions'),
'theme_fallback' => 'chamilo',
'unoconv_binaries' => '/usr/bin/unoconv',
'packager' => 'chamilo',
@ -112,6 +103,7 @@ class PlatformSettingsSchema extends AbstractSettingsSchema
'disable_user_conditions_sender_id' => '0',
'portfolio_advanced_sharing' => 'false',
'redirect_index_to_url_for_logged_users' => '',
'default_menu_entry_for_course_or_session' => 'my_courses',
]
)
->setTransformer(
@ -123,15 +115,10 @@ class PlatformSettingsSchema extends AbstractSettingsSchema
'institution' => ['string'],
'institution_url' => ['string'],
'site_name' => ['string'],
// 'administrator_email' => array('string'),
// 'administrator_name' => array('string'),
// 'administrator_surname' => array('string'),
// 'administrator_phone' => array('string'),
'timezone' => ['string'],
'gravatar_enabled' => ['string'],
'gravatar_type' => ['string'],
'show_tabs' => ['array', 'null'],
//'gamification_mode' => array('string'),
];
$this->setMultipleAllowedTypes($allowedTypes, $builder);
@ -144,10 +131,6 @@ class PlatformSettingsSchema extends AbstractSettingsSchema
->add('institution_url', UrlType::class)
->add('institution_address')
->add('site_name')
// ->add('administrator_email', 'email')
// ->add('administrator_name')
// ->add('administrator_surname')
// ->add('administrator_phone')
->add('timezone', TimezoneType::class)
->add('theme')
->add('gravatar_enabled', YesNoType::class)
@ -351,6 +334,16 @@ class PlatformSettingsSchema extends AbstractSettingsSchema
->add('disable_user_conditions_sender_id', TextType::class)
->add('portfolio_advanced_sharing', TextType::class)
->add('redirect_index_to_url_for_logged_users', TextType::class)
->add(
'default_menu_entry_for_course_or_session',
ChoiceType::class,
[
'choices' => [
'My Courses' => 'my_courses',
'My Sessions' => 'my_sessions',
],
]
)
;
}

Loading…
Cancel
Save