diff --git a/src/CoreBundle/Helpers/CourseHelper.php b/src/CoreBundle/Helpers/CourseHelper.php index c46c1ba6806..c8c7d07fdff 100644 --- a/src/CoreBundle/Helpers/CourseHelper.php +++ b/src/CoreBundle/Helpers/CourseHelper.php @@ -17,6 +17,7 @@ use Chamilo\CoreBundle\Entity\User; use Chamilo\CoreBundle\Repository\CourseCategoryRepository; use Chamilo\CoreBundle\Repository\Node\CourseRepository; +use Chamilo\CoreBundle\Repository\Node\IllustrationRepository; use Chamilo\CoreBundle\Repository\Node\UserRepository; use Chamilo\CoreBundle\Settings\SettingsManager; use Chamilo\CourseBundle\Component\CourseCopy\CourseBuilder; @@ -39,6 +40,7 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\Finder\Finder; use Symfony\Component\Finder\SplFileInfo; +use Symfony\Component\HttpFoundation\File\UploadedFile; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\Mailer\MailerInterface; use Symfony\Component\Mime\Email; @@ -65,7 +67,8 @@ public function __construct( private readonly EventLoggerHelper $eventLoggerHelper, private readonly ParameterBagInterface $parameterBag, private readonly RequestStack $requestStack, - private readonly AccessUrlHelper $accessUrlHelper + private readonly AccessUrlHelper $accessUrlHelper, + private readonly IllustrationRepository $illustrationRepository ) {} public function createCourse(array $params): ?Course @@ -196,6 +199,26 @@ public function registerCourse(array $rawParams): ?Course $this->courseRepository->create($course); $this->debugLog('registerCourse:persisted', ['courseId' => $course->getId()]); + if (!empty($rawParams['illustration_path'])) { + if (file_exists($rawParams['illustration_path'])) { + $mimeType = mime_content_type($rawParams['illustration_path']); + $uploadedFile = new UploadedFile( + $rawParams['illustration_path'], + basename($rawParams['illustration_path']), + $mimeType, + null, + true // test mode to allow local files + ); + + $this->illustrationRepository->addIllustration( + $course, + $currentUser, + $uploadedFile + ); + $this->debugLog('registerCourse:illustrationAdded', ['path' => $rawParams['illustration_path']]); + } + } + if (!empty($rawParams['exemplary_content'])) { $this->debugLog('registerCourse:willFillCourse', [ 'request_demo' => true, diff --git a/tests/datafiller/data_courses.php b/tests/datafiller/data_courses.php index 41caaa37908..9780699ab5a 100755 --- a/tests/datafiller/data_courses.php +++ b/tests/datafiller/data_courses.php @@ -21,6 +21,7 @@ 'user_id' => 1, 'expiration_date' => '2030-09-01 00:00:00', 'exemplary_content' => false, + 'illustration_path' => __DIR__.'/images/english101s.png', ]; // 2 $courses[] = [ @@ -32,6 +33,7 @@ 'user_id' => 1, 'expiration_date' => '2030-09-01 00:00:00', 'exemplary_content' => false, + 'illustration_path' => __DIR__.'/images/spanish101s.png', ]; // 3 $courses[] = [ @@ -43,6 +45,7 @@ 'user_id' => 1, 'expiration_date' => '2030-09-01 00:00:00', 'exemplary_content' => false, + 'illustration_path' => __DIR__.'/images/french101s.png', ]; // 4 $courses[] = [ @@ -54,6 +57,7 @@ 'user_id' => 1, 'expiration_date' => '2030-09-01 00:00:00', 'exemplary_content' => false, + 'illustration_path' => __DIR__.'/images/arabic101s.png', ]; // 5 $courses[] = [ @@ -65,6 +69,7 @@ 'user_id' => 1, 'expiration_date' => '2030-09-01 00:00:00', 'exemplary_content' => false, + 'illustration_path' => __DIR__.'/images/solarsystems.png', ]; // 6 $courses[] = [ @@ -76,6 +81,7 @@ 'user_id' => 1, 'expiration_date' => '2030-09-01 00:00:00', 'exemplary_content' => false, + 'illustration_path' => __DIR__.'/images/marnavigations.png', ]; // 7 $courses[] = [ @@ -87,6 +93,7 @@ 'user_id' => 1, 'expiration_date' => '2030-09-01 00:00:00', 'exemplary_content' => false, + 'illustration_path' => __DIR__.'/images/natgeos.png', ]; // 8 $courses[] = [ @@ -98,6 +105,7 @@ 'user_id' => 1, 'expiration_date' => '2030-09-01 00:00:00', 'exemplary_content' => false, + 'illustration_path' => __DIR__.'/images/japanese101s.png', ]; // 9 $courses[] = [ @@ -109,6 +117,7 @@ 'user_id' => 1, 'expiration_date' => '2030-09-01 00:00:00', 'exemplary_content' => false, + 'illustration_path' => __DIR__.'/images/timemgmts.png', ]; // 10 $courses[] = [ @@ -120,6 +129,7 @@ 'user_id' => 1, 'expiration_date' => '2030-09-01 00:00:00', 'exemplary_content' => false, + 'illustration_path' => __DIR__.'/images/hebrew101s.png', ]; // 11 $courses[] = [ @@ -131,6 +141,7 @@ 'user_id' => 1, 'expiration_date' => '2030-09-01 00:00:00', 'exemplary_content' => false, + 'illustration_path' => __DIR__.'/images/chinese101s.png', ]; // 12 $courses[] = [ @@ -142,4 +153,5 @@ 'user_id' => 1, 'expiration_date' => '2030-09-01 00:00:00', 'exemplary_content' => false, + 'illustration_path' => __DIR__.'/images/myanmar101s.png', ]; diff --git a/tests/datafiller/fill_courses.php b/tests/datafiller/fill_courses.php index 87ad30a89e7..8530b712330 100755 --- a/tests/datafiller/fill_courses.php +++ b/tests/datafiller/fill_courses.php @@ -57,6 +57,7 @@ function fill_courses(): array 'wanted_code' => $course['wanted_code'], 'course_language' => $course['course_language'], 'exemplary_content' => $course['exemplary_content'] ?? false, + 'illustration_path' => $course['illustration_path'] ?? null, ]); if ($created) { diff --git a/tests/datafiller/images/psyche/README.md b/tests/datafiller/images/psyche/README.md new file mode 100644 index 00000000000..1b23d7fe00c --- /dev/null +++ b/tests/datafiller/images/psyche/README.md @@ -0,0 +1,6 @@ +The images in this folder are used to give a branded illustration to courses created automatically by the courses filler. +A larger version of these images was generated through midjourney.com. +Type of prompt used: +"dense psychedelic blue-and-gold line art, intricate obsessive detailing, illuminated manuscript meets mandala surrealism, deep cobalt base + radiant gold-orange accents, hyper-patterned, empty center --ar 16:9 --stylize 50" +Images are then resized to 366x188 and text is added in Arial Bold, size 18, pure white. +Image names are defined in ../data_courses.php under 'illustration_path', as the course code + 's' for 'small'. diff --git a/tests/datafiller/images/psyche/arabic101s.png b/tests/datafiller/images/psyche/arabic101s.png new file mode 100644 index 00000000000..4a72ee7288a Binary files /dev/null and b/tests/datafiller/images/psyche/arabic101s.png differ diff --git a/tests/datafiller/images/psyche/chinese101s.png b/tests/datafiller/images/psyche/chinese101s.png new file mode 100644 index 00000000000..64e7d8f5dd5 Binary files /dev/null and b/tests/datafiller/images/psyche/chinese101s.png differ diff --git a/tests/datafiller/images/psyche/english101s.png b/tests/datafiller/images/psyche/english101s.png new file mode 100644 index 00000000000..607bc77566f Binary files /dev/null and b/tests/datafiller/images/psyche/english101s.png differ diff --git a/tests/datafiller/images/psyche/french101s.png b/tests/datafiller/images/psyche/french101s.png new file mode 100644 index 00000000000..9fa0b3e77e6 Binary files /dev/null and b/tests/datafiller/images/psyche/french101s.png differ diff --git a/tests/datafiller/images/psyche/hebrew101s.png b/tests/datafiller/images/psyche/hebrew101s.png new file mode 100644 index 00000000000..0e286946adf Binary files /dev/null and b/tests/datafiller/images/psyche/hebrew101s.png differ diff --git a/tests/datafiller/images/psyche/japanese101s.png b/tests/datafiller/images/psyche/japanese101s.png new file mode 100644 index 00000000000..74a5e357d71 Binary files /dev/null and b/tests/datafiller/images/psyche/japanese101s.png differ diff --git a/tests/datafiller/images/psyche/marnavigations.png b/tests/datafiller/images/psyche/marnavigations.png new file mode 100644 index 00000000000..32e77e90ae1 Binary files /dev/null and b/tests/datafiller/images/psyche/marnavigations.png differ diff --git a/tests/datafiller/images/psyche/myanmar101s.png b/tests/datafiller/images/psyche/myanmar101s.png new file mode 100644 index 00000000000..09a5d39566d Binary files /dev/null and b/tests/datafiller/images/psyche/myanmar101s.png differ diff --git a/tests/datafiller/images/psyche/natgeos.png b/tests/datafiller/images/psyche/natgeos.png new file mode 100644 index 00000000000..7497320c2ff Binary files /dev/null and b/tests/datafiller/images/psyche/natgeos.png differ diff --git a/tests/datafiller/images/psyche/solarsystems.png b/tests/datafiller/images/psyche/solarsystems.png new file mode 100644 index 00000000000..726ec186da1 Binary files /dev/null and b/tests/datafiller/images/psyche/solarsystems.png differ diff --git a/tests/datafiller/images/psyche/spanish101s.png b/tests/datafiller/images/psyche/spanish101s.png new file mode 100644 index 00000000000..7866ed8e1c0 Binary files /dev/null and b/tests/datafiller/images/psyche/spanish101s.png differ diff --git a/tests/datafiller/images/psyche/timemgmts.png b/tests/datafiller/images/psyche/timemgmts.png new file mode 100644 index 00000000000..813009d75d4 Binary files /dev/null and b/tests/datafiller/images/psyche/timemgmts.png differ