Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion assets/vue/components/ccalendarevent/CCalendarEventInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,25 @@
v-else-if="type.invitation === event.invitationType"
:event="event"
/>
<div
v-else-if="event.objectType === 'learning_calendar' && event.eventType"
class="mt-2"
>
<strong>{{ t("Type") }}:</strong>
{{ event.eventType }}
</div>

<ShowLinks
v-else
:clickable-course="true"
:item="event"
:show-status="false"
/>

<CalendarRemindersInfo :event="event" />
<CalendarRemindersInfo
v-if="event.objectType !== 'learning_calendar'"
:event="event"
/>

<div
v-if="event.room"
Expand Down
81 changes: 68 additions & 13 deletions assets/vue/composables/calendar/calendarEvent.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { DateTime } from "luxon"

import cCalendarEventService from "../../services/ccalendarevent"
const { getCurrentTimezone } = useFormatDate()

import { subscriptionVisibility, type } from "../../constants/entity/ccalendarevent"
import { useFormatDate } from "../formatDate"

const { getCurrentTimezone } = useFormatDate()

export function useCalendarEvent() {
return {
findUserLink,
Expand Down Expand Up @@ -80,25 +80,76 @@ function allowUnsubscribeToEvent(event, userId) {
return !!findUserLink(event, userId)
}

function mapCalendarEvent(event) {
const timezone = getCurrentTimezone()
const start = DateTime.fromISO(event.startDate, { zone: "utc" }).setZone(timezone)
const end = DateTime.fromISO(event.endDate, { zone: "utc" }).setZone(timezone)

return {
...event,
start: start.toString(),
end: end.toString(),
color: event.color || "#007BFF",
}
}

/**
* @param {Object} params
* @returns {Promise<Object[]>}
*/
async function requestCalendarEvents(params) {
const calendarEvents = await cCalendarEventService.findAll({ params }).then((response) => response.json())

return calendarEvents["hydra:member"].map((event) => {
const timezone = getCurrentTimezone()
const start = DateTime.fromISO(event.startDate, { zone: "utc" }).setZone(timezone)
const end = DateTime.fromISO(event.endDate, { zone: "utc" }).setZone(timezone)
return calendarEvents["hydra:member"].map(mapCalendarEvent)
}

return {
...event,
start: start.toString(),
end: end.toString(),
color: event.color || "#007BFF",
}
function shouldLoadLearningCalendarEvents(commonParams) {
if (!commonParams) {
return true
}

if (commonParams.cid || commonParams.sid || commonParams.gid || commonParams.type === "global") {
return false
}

return true
}

/**
* @param {Object} startDate
* @param {Object} endDate
* @param {Object} commonParams
* @returns {Promise<Object[]>}
*/
async function requestLearningCalendarEvents(startDate, endDate, commonParams) {
if (!shouldLoadLearningCalendarEvents(commonParams)) {
return []
}

const params = new URLSearchParams({
startDate: startDate.toISOString(),
endDate: endDate.toISOString(),
})

try {
const response = await fetch(`/plugin/LearningCalendar/my_events.php?${params.toString()}`, {
credentials: "same-origin",
headers: {
Accept: "application/json",
},
})

if (!response.ok) {
return []
}

const payload = await response.json()
const events = Array.isArray(payload.events) ? payload.events : []

return events.map(mapCalendarEvent)
} catch (error) {
return []
}
}

/**
Expand Down Expand Up @@ -126,17 +177,21 @@ async function getCalendarEvents(startDate, endDate, commonParams) {
"startDate[after]": startDate.toISOString(),
})

const [endingEvents, currentEvents, startingEvents] = await Promise.all([
const learningCalendarEventsPromise = requestLearningCalendarEvents(startDate, endDate, commonParams)

const [endingEvents, currentEvents, startingEvents, learningCalendarEvents] = await Promise.all([
endingEventsPromise,
currentEventsPromise,
startingEventsPromise,
learningCalendarEventsPromise,
])

const uniqueEventsMap = new Map()

endingEvents
.concat(startingEvents)
.concat(currentEvents)
.concat(learningCalendarEvents)
.forEach((event) => uniqueEventsMap.set(event.id, event))

return Array.from(uniqueEventsMap.values())
Expand Down
19 changes: 19 additions & 0 deletions assets/vue/views/ccalendarevent/CCalendarEventList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,25 @@ const calendarOptions = ref({
return
}

if (event.extendedProps["objectType"] && event.extendedProps["objectType"] === "learning_calendar") {
item.value = {
...event.extendedProps,
id: event.id,
title: event.title,
startDate: event.start ? new Date(event.start) : null,
endDate: event.end ? new Date(event.end) : null,
type: "personal",
resourceLinkListFromEntity: [],
}

allowToEdit.value = false
allowToSubscribe.value = false
allowToUnsubscribe.value = false
dialogShow.value = true

return
}

item.value = { ...event.extendedProps }

item.value["@id"] = "/api/c_calendar_events/" + event.id.match(/\d+$/)[0]
Expand Down
1 change: 1 addition & 0 deletions public/main/admin/settings.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ function getStablePluginAllowList(): array
'Static',
'ShowUserInfo',
'StudentFollowUp',
'LearningCalendar',
];
}

Expand Down
35 changes: 21 additions & 14 deletions public/main/my_space/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,20 +151,27 @@

// 2) Extra actions: "View my progress", calendar plugin, certificates.

// Optional Learning Calendar plugin entry (teachers only).
$pluginCalendar = 'true' === api_get_plugin_setting('learning_calendar', 'enabled');
if ($pluginCalendar && api_is_teacher()) {
$lpCalendar = \LearningCalendarPlugin::create();
$actionsLeft .= Display::url(
Display::getMdiIcon(
'calendar-text',
'ch-tool-icon',
null,
32,
$lpCalendar->get_lang('Learning calendar')
),
api_get_path(WEB_PLUGIN_PATH).'LearningCalendar/start.php'
);
// Optional Learning Calendar plugin entry for users allowed to access reporting.
$learningCalendarPluginPath = api_get_path(SYS_PLUGIN_PATH).'LearningCalendar/LearningCalendarPlugin.php';
if (file_exists($learningCalendarPluginPath)) {
require_once $learningCalendarPluginPath;
}

$canAccessLearningCalendar = $allowToTrack || $is_drh || $is_coach;
if (class_exists('LearningCalendarPlugin') && $canAccessLearningCalendar) {
$learningCalendarPlugin = LearningCalendarPlugin::create();
if ($learningCalendarPlugin->isEnabled()) {
$actionsLeft .= Display::url(
Display::getMdiIcon(
'calendar-text',
'ch-tool-icon',
null,
32,
$learningCalendarPlugin->get_lang('LearningCalendar')
),
api_get_path(WEB_PLUGIN_PATH).'LearningCalendar/start.php'
);
}
}

// Optional StudentFollowUp plugin entry for users allowed to access reporting.
Expand Down
Loading
Loading