Skip to content

Commit d8d1790

Browse files
Merge pull request #5294 from christianbeeznest/fixes-updates15
Calendar: Adapt event colors from settings and fix event updates
2 parents be08774 + 5efd8e4 commit d8d1790

File tree

4 files changed

+40
-17
lines changed

4 files changed

+40
-17
lines changed

assets/vue/views/ccalendarevent/CCalendarEventList.vue

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -213,14 +213,7 @@ async function getCalendarEvents({ startStr, endStr }) {
213213
const calendarEvents = await cCalendarEventService.findAll({ params }).then((response) => response.json())
214214
215215
return calendarEvents["hydra:member"].map((event) => {
216-
let color = '#007BFF'
217-
if (event.type === 'global') {
218-
color = '#FF0000'
219-
} else if (event.type === 'course') {
220-
color = '#28a745'
221-
} else if (event.type === 'session') {
222-
color = '#800080'
223-
}
216+
let color = event.color || '#007BFF'
224217
225218
return {
226219
...event,
@@ -267,6 +260,7 @@ const calendarOptions = ref({
267260
selectable: true,
268261
eventClick(eventClickInfo) {
269262
eventClickInfo.jsEvent.preventDefault()
263+
currentEvent = eventClickInfo.event
270264
271265
let event = eventClickInfo.event.toPlainObject()
272266
@@ -277,8 +271,6 @@ const calendarOptions = ref({
277271
return
278272
}
279273
280-
currentEvent = event
281-
282274
item.value = { ...event.extendedProps }
283275
284276
item.value["title"] = event.title
@@ -320,21 +312,21 @@ const currentContext = computed(() => {
320312
} else {
321313
return 'personal'
322314
}
323-
});
315+
})
324316
325317
const allowAction = (eventType) => {
326318
const contextRules = {
327319
global: ['global'],
328320
course: ['course'],
329321
session: ['session'],
330322
personal: ['personal']
331-
};
323+
}
332324
333-
return contextRules[currentContext.value].includes(eventType);
334-
};
325+
return contextRules[currentContext.value].includes(eventType)
326+
}
335327
336-
const showEditButton = computed(() => allowAction(item.value.type));
337-
const showDeleteButton = computed(() => allowAction(item.value.type));
328+
const showEditButton = computed(() => allowAction(item.value.type))
329+
const showDeleteButton = computed(() => allowAction(item.value.type))
338330
339331
const cal = ref(null)
340332

src/CoreBundle/ApiResource/CalendarEvent.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ public function __construct(
4444
public ?ResourceNode $resourceNode = null,
4545
?array $resourceLinkListFromEntity = null,
4646
#[Groups(['calendar_event:read'])]
47+
public ?string $color = null,
48+
#[Groups(['calendar_event:read'])]
4749
public ?string $type = null,
4850
) {
4951
$this->resourceLinkListFromEntity = $resourceLinkListFromEntity;

src/CoreBundle/DataTransformer/CalendarEventTransformer.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Chamilo\CoreBundle\Entity\Session;
1212
use Chamilo\CoreBundle\Entity\SessionRelCourse;
1313
use Chamilo\CoreBundle\Repository\Node\UsergroupRepository;
14+
use Chamilo\CoreBundle\Settings\SettingsManager;
1415
use Chamilo\CourseBundle\Entity\CCalendarEvent;
1516
use Chamilo\CourseBundle\Repository\CCalendarEventRepository;
1617
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
@@ -21,7 +22,8 @@ class CalendarEventTransformer implements DataTransformerInterface
2122
public function __construct(
2223
private readonly RouterInterface $router,
2324
private readonly UsergroupRepository $usergroupRepository,
24-
private readonly CCalendarEventRepository $calendarEventRepository
25+
private readonly CCalendarEventRepository $calendarEventRepository,
26+
private readonly SettingsManager $settingsManager
2527
) {}
2628

2729
public function transform($object, string $to, array $context = []): object
@@ -51,6 +53,8 @@ private function mapCCalendarToDto(object $object): CalendarEvent
5153
}
5254

5355
$eventType = $this->calendarEventRepository->determineEventType($object);
56+
$color = $this->determineEventColor($eventType);
57+
5458
$calendarEvent = new CalendarEvent(
5559
'calendar_event_'.$object->getIid(),
5660
$object->getTitle(),
@@ -67,6 +71,7 @@ private function mapCCalendarToDto(object $object): CalendarEvent
6771
$object->getMaxAttendees(),
6872
$object->getResourceNode(),
6973
$object->getResourceLinkListFromEntity(),
74+
$color
7075
);
7176
$calendarEvent->setType($eventType);
7277

@@ -99,4 +104,27 @@ private function mapSessionToDto(object $object): CalendarEvent
99104
$sessionUrl,
100105
);
101106
}
107+
108+
private function determineEventColor(string $eventType): string
109+
{
110+
$agendaColors = [
111+
'platform' => 'red',
112+
'course' => '#458B00',
113+
'session' => '#00496D',
114+
'personal' => 'steel blue',
115+
];
116+
117+
$settingAgendaColors = $this->settingsManager->getSetting('agenda.agenda_colors');
118+
if (is_array($settingAgendaColors)) {
119+
$agendaColors = array_merge($agendaColors, $settingAgendaColors);
120+
}
121+
122+
$colorKeyMap = [
123+
'global' => 'platform',
124+
];
125+
126+
$colorKey = $colorKeyMap[$eventType] ?? $eventType;
127+
128+
return $agendaColors[$colorKey] ?? $agendaColors['personal'];
129+
}
102130
}

src/CourseBundle/Entity/CCalendarEvent.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ class CCalendarEvent extends AbstractResource implements ResourceInterface, Stri
132132
#[ORM\Column(name: 'comment', type: 'text', nullable: true)]
133133
protected ?string $comment = null;
134134

135+
#[Groups(['calendar_event:write', 'calendar_event:read'])]
135136
#[ORM\Column(name: 'color', type: 'string', length: 20, nullable: true)]
136137
protected ?string $color = null;
137138

0 commit comments

Comments
 (0)