Skip to content

Commit b5e86d1

Browse files
committed
Announcement: Allow to add event reminders to event created from announcement - refs BT#21582
1 parent 602d1ac commit b5e86d1

File tree

3 files changed

+70
-2
lines changed

3 files changed

+70
-2
lines changed

public/main/announcements/announcements.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
/* For licensing terms, see /license.txt */
44

5+
use Chamilo\CoreBundle\Component\Utils\ActionIcon;
56
use Chamilo\CoreBundle\Entity\AbstractResource;
67
use Chamilo\CoreBundle\Framework\Container;
78
use Chamilo\CourseBundle\Entity\CAnnouncement;
@@ -624,6 +625,24 @@
624625
$form->addHtml('<div id="add_event_options" style="display:none;">');
625626
$form->addDateTimePicker('event_date_start', get_lang('Date start'));
626627
$form->addDateTimePicker('event_date_end', get_lang('Date end'));
628+
629+
$form->addHtml('<hr><div id="notification_list"></div>');
630+
$form
631+
->addButton(
632+
'add_notification',
633+
get_lang('Add reminder'),
634+
ActionIcon::ADD_EVENT_REMINDER->value,
635+
'plain'
636+
)
637+
->setType('button')
638+
;
639+
$form->addHtml('<hr>');
640+
641+
$htmlHeadXtra[] = '<script>$(function () {'
642+
.Agenda::getJsForReminders('#announcement_add_notification')
643+
.'});</script>'
644+
;
645+
627646
$form->addHtml('</div>');
628647
}
629648

@@ -646,6 +665,12 @@
646665
$data['users'] = $data['users'] ?? [];
647666
$sendToUsersInSession = isset($data['send_to_users_in_session']);
648667
$sendMeCopy = isset($data['send_me_a_copy_by_email']);
668+
669+
$notificationCount = $data['notification_count'] ?? [];
670+
$notificationPeriod = $data['notification_period'] ?? [];
671+
672+
$reminders = $notificationCount ? array_map(null, $notificationCount, $notificationPeriod) : [];
673+
649674
if (isset($id) && $id) {
650675
// there is an Id => the announcement already exists => update mode
651676
$file_comment = $announcementAttachmentIsDisabled ? null : $_POST['file_comment'];
@@ -725,7 +750,8 @@
725750
$data['users'],
726751
api_get_course_entity(),
727752
api_get_session_entity(),
728-
api_get_group_entity()
753+
api_get_group_entity(),
754+
$reminders
729755
);
730756
}
731757

public/main/inc/lib/agenda.lib.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3594,4 +3594,34 @@ public function formatEventDate($utcTime)
35943594

35953595
return $eventDate->format(DateTime::ISO8601);
35963596
}
3597+
3598+
public static function getJsForReminders(string $cssSelectorBtnAdd): string
3599+
{
3600+
return '
3601+
var template = \'<div class="flex flex-row items-center gap-4">\' +
3602+
\'<input min="0" step="1" id="notification_count[]" type="number" name="notification_count[]">\' +
3603+
\'<select name="notification_period[]" id="form_notification_period[]">\' +
3604+
\'<option value="i">'.get_lang('Minutes').'</option>\' +
3605+
\'<option value="h">'.get_lang('Hours').'</option>\' +
3606+
\'<option value="d">'.get_lang('Days').'</option>\' +
3607+
\'</select>\' +
3608+
\'<p class="form-control-static">'.get_lang('Before').'</p>\' +
3609+
\'<button class="btn btn--danger delete-notification" type="button" aria-label="'.get_lang('Delete').'">\' +
3610+
\'<i class="mdi mdi-close" aria-hidden="true"></i>\' +
3611+
\'</button>\' +
3612+
\'</div>\';
3613+
3614+
$("'.$cssSelectorBtnAdd.'").on("click", function (e) {
3615+
e.preventDefault();
3616+
3617+
$(template).appendTo("#notification_list");
3618+
$("#notification_list select").selectpicker("refresh");
3619+
});
3620+
3621+
$("#notification_list").on("click", ".delete-notification", function (e) {
3622+
e.preventDefault();
3623+
3624+
$(this).parents(".form-group").remove();
3625+
});';
3626+
}
35973627
}

src/CourseBundle/Repository/CCalendarEventRepository.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace Chamilo\CourseBundle\Repository;
88

99
use Chamilo\CoreBundle\Entity\AbstractResource;
10+
use Chamilo\CoreBundle\Entity\AgendaReminder;
1011
use Chamilo\CoreBundle\Entity\Course;
1112
use Chamilo\CoreBundle\Entity\Session;
1213
use Chamilo\CoreBundle\Entity\User;
@@ -31,7 +32,8 @@ public function createFromAnnouncement(
3132
array $users,
3233
Course $course,
3334
?Session $session = null,
34-
?CGroup $group = null
35+
?CGroup $group = null,
36+
array $remindersInfo = [],
3537
): CCalendarEvent {
3638
$event = (new CCalendarEvent())
3739
->setTitle($announcement->getTitle())
@@ -71,6 +73,16 @@ public function createFromAnnouncement(
7173
}
7274
}
7375

76+
foreach ($remindersInfo as $reminderInfo) {
77+
$reminder = new AgendaReminder();
78+
$reminder->count = (int) $reminderInfo[0];
79+
$reminder->period = $reminderInfo[1];
80+
81+
$reminder->decodeDateInterval();
82+
83+
$event->addReminder($reminder);
84+
}
85+
7486
$em->persist($event);
7587
$em->flush();
7688

0 commit comments

Comments
 (0)