Skip to content

Commit 4da23a6

Browse files
authored
Merge pull request #7370 from ywarnier/filler
CI: Add illustrations for course data filler
2 parents 563a8ab + 51a7d22 commit 4da23a6

16 files changed

Lines changed: 43 additions & 1 deletion

src/CoreBundle/Helpers/CourseHelper.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Chamilo\CoreBundle\Entity\User;
1818
use Chamilo\CoreBundle\Repository\CourseCategoryRepository;
1919
use Chamilo\CoreBundle\Repository\Node\CourseRepository;
20+
use Chamilo\CoreBundle\Repository\Node\IllustrationRepository;
2021
use Chamilo\CoreBundle\Repository\Node\UserRepository;
2122
use Chamilo\CoreBundle\Settings\SettingsManager;
2223
use Chamilo\CourseBundle\Component\CourseCopy\CourseBuilder;
@@ -39,6 +40,7 @@
3940
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
4041
use Symfony\Component\Finder\Finder;
4142
use Symfony\Component\Finder\SplFileInfo;
43+
use Symfony\Component\HttpFoundation\File\UploadedFile;
4244
use Symfony\Component\HttpFoundation\RequestStack;
4345
use Symfony\Component\Mailer\MailerInterface;
4446
use Symfony\Component\Mime\Email;
@@ -65,7 +67,8 @@ public function __construct(
6567
private readonly EventLoggerHelper $eventLoggerHelper,
6668
private readonly ParameterBagInterface $parameterBag,
6769
private readonly RequestStack $requestStack,
68-
private readonly AccessUrlHelper $accessUrlHelper
70+
private readonly AccessUrlHelper $accessUrlHelper,
71+
private readonly IllustrationRepository $illustrationRepository
6972
) {}
7073

7174
public function createCourse(array $params): ?Course
@@ -196,6 +199,26 @@ public function registerCourse(array $rawParams): ?Course
196199
$this->courseRepository->create($course);
197200
$this->debugLog('registerCourse:persisted', ['courseId' => $course->getId()]);
198201

202+
if (!empty($rawParams['illustration_path'])) {
203+
if (file_exists($rawParams['illustration_path'])) {
204+
$mimeType = mime_content_type($rawParams['illustration_path']);
205+
$uploadedFile = new UploadedFile(
206+
$rawParams['illustration_path'],
207+
basename($rawParams['illustration_path']),
208+
$mimeType,
209+
null,
210+
true // test mode to allow local files
211+
);
212+
213+
$this->illustrationRepository->addIllustration(
214+
$course,
215+
$currentUser,
216+
$uploadedFile
217+
);
218+
$this->debugLog('registerCourse:illustrationAdded', ['path' => $rawParams['illustration_path']]);
219+
}
220+
}
221+
199222
if (!empty($rawParams['exemplary_content'])) {
200223
$this->debugLog('registerCourse:willFillCourse', [
201224
'request_demo' => true,

tests/datafiller/data_courses.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
'user_id' => 1,
2222
'expiration_date' => '2030-09-01 00:00:00',
2323
'exemplary_content' => false,
24+
'illustration_path' => __DIR__.'/images/english101s.png',
2425
];
2526
// 2
2627
$courses[] = [
@@ -32,6 +33,7 @@
3233
'user_id' => 1,
3334
'expiration_date' => '2030-09-01 00:00:00',
3435
'exemplary_content' => false,
36+
'illustration_path' => __DIR__.'/images/spanish101s.png',
3537
];
3638
// 3
3739
$courses[] = [
@@ -43,6 +45,7 @@
4345
'user_id' => 1,
4446
'expiration_date' => '2030-09-01 00:00:00',
4547
'exemplary_content' => false,
48+
'illustration_path' => __DIR__.'/images/french101s.png',
4649
];
4750
// 4
4851
$courses[] = [
@@ -54,6 +57,7 @@
5457
'user_id' => 1,
5558
'expiration_date' => '2030-09-01 00:00:00',
5659
'exemplary_content' => false,
60+
'illustration_path' => __DIR__.'/images/arabic101s.png',
5761
];
5862
// 5
5963
$courses[] = [
@@ -65,6 +69,7 @@
6569
'user_id' => 1,
6670
'expiration_date' => '2030-09-01 00:00:00',
6771
'exemplary_content' => false,
72+
'illustration_path' => __DIR__.'/images/solarsystems.png',
6873
];
6974
// 6
7075
$courses[] = [
@@ -76,6 +81,7 @@
7681
'user_id' => 1,
7782
'expiration_date' => '2030-09-01 00:00:00',
7883
'exemplary_content' => false,
84+
'illustration_path' => __DIR__.'/images/marnavigations.png',
7985
];
8086
// 7
8187
$courses[] = [
@@ -87,6 +93,7 @@
8793
'user_id' => 1,
8894
'expiration_date' => '2030-09-01 00:00:00',
8995
'exemplary_content' => false,
96+
'illustration_path' => __DIR__.'/images/natgeos.png',
9097
];
9198
// 8
9299
$courses[] = [
@@ -98,6 +105,7 @@
98105
'user_id' => 1,
99106
'expiration_date' => '2030-09-01 00:00:00',
100107
'exemplary_content' => false,
108+
'illustration_path' => __DIR__.'/images/japanese101s.png',
101109
];
102110
// 9
103111
$courses[] = [
@@ -109,6 +117,7 @@
109117
'user_id' => 1,
110118
'expiration_date' => '2030-09-01 00:00:00',
111119
'exemplary_content' => false,
120+
'illustration_path' => __DIR__.'/images/timemgmts.png',
112121
];
113122
// 10
114123
$courses[] = [
@@ -120,6 +129,7 @@
120129
'user_id' => 1,
121130
'expiration_date' => '2030-09-01 00:00:00',
122131
'exemplary_content' => false,
132+
'illustration_path' => __DIR__.'/images/hebrew101s.png',
123133
];
124134
// 11
125135
$courses[] = [
@@ -131,6 +141,7 @@
131141
'user_id' => 1,
132142
'expiration_date' => '2030-09-01 00:00:00',
133143
'exemplary_content' => false,
144+
'illustration_path' => __DIR__.'/images/chinese101s.png',
134145
];
135146
// 12
136147
$courses[] = [
@@ -142,4 +153,5 @@
142153
'user_id' => 1,
143154
'expiration_date' => '2030-09-01 00:00:00',
144155
'exemplary_content' => false,
156+
'illustration_path' => __DIR__.'/images/myanmar101s.png',
145157
];

tests/datafiller/fill_courses.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ function fill_courses(): array
5757
'wanted_code' => $course['wanted_code'],
5858
'course_language' => $course['course_language'],
5959
'exemplary_content' => $course['exemplary_content'] ?? false,
60+
'illustration_path' => $course['illustration_path'] ?? null,
6061
]);
6162

6263
if ($created) {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
The images in this folder are used to give a branded illustration to courses created automatically by the courses filler.
2+
A larger version of these images was generated through midjourney.com.
3+
Type of prompt used:
4+
"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"
5+
Images are then resized to 366x188 and text is added in Arial Bold, size 18, pure white.
6+
Image names are defined in ../data_courses.php under 'illustration_path', as the course code + 's' for 'small'.
50.8 KB
Loading
51.4 KB
Loading
51.3 KB
Loading
52.3 KB
Loading
53.7 KB
Loading
49.3 KB
Loading

0 commit comments

Comments
 (0)