Agenda: Allow teachers/coaches import course agenda reminders - refs BT#20356

pull/4546/head
Angel Fernando Quiroz Campos 3 years ago
parent 618af1b0d1
commit b7f817368c
  1. 2
      main/admin/importCourseEventInCourseExample.csv
  2. 72
      main/admin/import_course_agenda_reminders.php
  3. 8
      main/calendar/agenda.php
  4. 18
      main/inc/lib/agenda.lib.php

@ -0,0 +1,2 @@
UserName;StartDate;EndDate
xxx;YYYY-MM-DD HH:ii:ss;YYYY-MM-DD HH:ii:ss
1 UserName StartDate EndDate
2 xxx YYYY-MM-DD HH:ii:ss YYYY-MM-DD HH:ii:ss

@ -4,7 +4,17 @@
require_once __DIR__.'/../inc/global.inc.php';
api_protect_admin_script();
$courseCode = api_get_course_id();
$sessionId = api_get_session_id();
$loadFromCourse = !empty($courseCode) && api_is_allowed_to_edit(false, true);
$selfUrl = api_get_self();
if ($loadFromCourse) {
api_protect_teacher_script();
$selfUrl = api_get_self().'?'.api_get_cidreq().'&type=course';
} else {
api_protect_admin_script();
}
$isAgendaRemindersEnabled = api_get_configuration_value('agenda_reminders');
@ -24,13 +34,20 @@ $tagsHelp = '<strong>'.get_lang('Tags').'</strong>'
$fileHelpText = get_lang('ImportCSVFileLocation').'<br>'
.Display::url(
get_lang('ExampleCSVFile'),
'importCourseEventsExample.csv',
['target' => '_blank', 'download' => 'importCourseEventsExample.csv']
)
.'<pre>CourseCode;UserName;StartDate;EndDate
xxx;xxx;YYYY-MM-DD HH:ii:ss;YYYY-MM-DD HH:ii:ss</pre>';
$loadFromCourse ? 'importCourseEventInCourseExample.csv' : 'importCourseEventsExample.csv',
[
'target' => '_blank',
'download' => $loadFromCourse ? 'importCourseEventInCourseExample.csv' : 'importCourseEventsExample.csv',
]
);
if ($loadFromCourse) {
$fileHelpText .= '<pre>UserName;StartDate;EndDate<br>xxx;YYYY-MM-DD HH:ii:ss;YYYY-MM-DD HH:ii:ss</pre>';
} else {
$fileHelpText .= '<pre>CourseCode;UserName;StartDate;EndDate<br>xxx;xxx;YYYY-MM-DD HH:ii:ss;YYYY-MM-DD HH:ii:ss</pre>';
}
$form = new FormValidator('agenda_reminders');
$form = new FormValidator('agenda_reminders', 'post', $selfUrl);
$form->addHeader(get_lang('CsvImport'));
$form->addFile(
'events_file',
@ -95,22 +112,26 @@ if ($form->validate()) {
foreach ($csvEvents as $csvEvent) {
$hashDate = base64_encode($csvEvent['StartDate'].'||'.$csvEvent['EndDate']);
$courseInfo = api_get_course_info($csvEvent['CourseCode']);
if (!$courseInfo) {
continue;
}
$userInfo = api_get_user_info_from_username($csvEvent['UserName']);
if (!$userInfo) {
continue;
}
$grouppedData[$courseInfo['code']][$hashDate][] = $userInfo['id'];
if ($loadFromCourse) {
$grouppedData[$courseCode][$hashDate][] = $userInfo['id'];
} else {
$courseInfo = api_get_course_info($csvEvent['CourseCode']);
if (!$courseInfo) {
continue;
}
$grouppedData[$courseInfo['code']][$hashDate][] = $userInfo['id'];
}
}
foreach ($grouppedData as $courseCode => $eventInfo) {
foreach ($grouppedData as $dataCourseCode => $eventInfo) {
foreach ($eventInfo as $hashDate => $userIdList) {
$dateRange = base64_decode($hashDate);
list($dateStart, $dateEnd) = explode('||', $dateRange);
@ -122,8 +143,8 @@ if ($form->validate()) {
$strDateEnd = api_format_date($dateEnd, DATE_TIME_FORMAT_LONG_24H);
foreach ($userIdList as $userId) {
$title = AnnouncementManager::parseContent($userId, $values['title'], $courseCode);
$content = AnnouncementManager::parseContent($userId, $values['description'], $courseCode);
$title = AnnouncementManager::parseContent($userId, $values['title'], $dataCourseCode, $sessionId);
$content = AnnouncementManager::parseContent($userId, $values['description'], $dataCourseCode, $sessionId);
$title = str_replace(['((date_start))', '((date_end))'], [$strDateStart, $strDateEnd], $title);
$content = str_replace(['((date_start))', '((date_end))'], [$strDateStart, $strDateEnd], $content);
@ -153,7 +174,7 @@ if ($form->validate()) {
Display::return_message(get_lang('FileImported'), 'success')
);
header('Location: '.api_get_self());
header("Location: $selfUrl");
exit;
}
@ -170,9 +191,22 @@ $htmlHeadXtra[] = '<script>$(function () {'
$pageTitle = get_lang('ImportCourseEvents');
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
$actions = '';
if (!$loadFromCourse) {
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
} else {
$interbreadcrumb[] = [
"url" => api_get_path(WEB_CODE_PATH).'calendar/agenda_js.php?type=course&'.api_get_cidreq(),
"name" => get_lang('Agenda'),
];
$agenda = new Agenda('course');
$actions = $agenda->displayActions('calendar');
}
$template = new Template($pageTitle);
$template->assign('header', $pageTitle);
$template->assign('actions', $actions);
$template->assign('content', $form->returnForm());
$template->display_one_col_template();

@ -369,6 +369,14 @@ if ($allowToEdit) {
$content = $agenda->deleteEvent($eventId);
}
break;
case 'import_course_agenda_reminders':
if (!empty($course_info)) {
header('Location: '.api_get_path(WEB_CODE_PATH)
.'admin/import_course_agenda_reminders.php?'.api_get_cidreq().'&type=course'
);
exit();
}
}
}

@ -3380,7 +3380,7 @@ class Agenda
return false;
}
public function displayActions(string $view, string $filter = ''): string
public function displayActions(string $view, ?string $filter = ''): string
{
$groupInfo = GroupManager::get_group_properties(api_get_group_id());
$groupIid = $groupInfo['iid'] ?? 0;
@ -3399,8 +3399,10 @@ class Agenda
$codePath."calendar/agenda_list.php?type={$this->type}&$cidReq"
);
$isAllowedToEdit = api_is_allowed_to_edit(false, true);
$form = '';
if (api_is_allowed_to_edit(false, true)
if ($isAllowedToEdit
|| ('personal' === $this->type && !api_is_anonymous() && 'true' === api_get_setting('allow_personal_agenda'))
|| (
'1' === api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous() &&
@ -3438,6 +3440,18 @@ class Agenda
$this->showToForm($form, $selectedValues, $attributes);
$form = $form->returnForm();
}
if (true === api_get_configuration_value('agenda_reminders') && $isAllowedToEdit) {
$actionsLeft .= Display::url(
Display::return_icon(
'course_request_pending.png',
get_lang('ImportCourseEvents'),
[],
ICON_SIZE_MEDIUM
),
$codePath."calendar/agenda.php?action=import_course_agenda_reminders&type={$this->type}&$cidReq"
);
}
}
}

Loading…
Cancel
Save