Skip to content

Commit

Permalink
Announcement: Allow to add event reminders to event created from anno…
Browse files Browse the repository at this point in the history
…uncement - refs BT#21582
  • Loading branch information
AngelFQC committed Jun 12, 2024
1 parent 602d1ac commit b5e86d1
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 2 deletions.
28 changes: 27 additions & 1 deletion public/main/announcements/announcements.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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

use Chamilo\CoreBundle\Component\Utils\ActionIcon;
use Chamilo\CoreBundle\Entity\AbstractResource;
use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CourseBundle\Entity\CAnnouncement;
Expand Down Expand Up @@ -624,6 +625,24 @@
$form->addHtml('<div id="add_event_options" style="display:none;">');
$form->addDateTimePicker('event_date_start', get_lang('Date start'));
$form->addDateTimePicker('event_date_end', get_lang('Date end'));

$form->addHtml('<hr><div id="notification_list"></div>');
$form
->addButton(
'add_notification',
get_lang('Add reminder'),
ActionIcon::ADD_EVENT_REMINDER->value,
'plain'
)
->setType('button')
;
$form->addHtml('<hr>');

$htmlHeadXtra[] = '<script>$(function () {'
.Agenda::getJsForReminders('#announcement_add_notification')
.'});</script>'
;

$form->addHtml('</div>');
}

Expand All @@ -646,6 +665,12 @@
$data['users'] = $data['users'] ?? [];
$sendToUsersInSession = isset($data['send_to_users_in_session']);
$sendMeCopy = isset($data['send_me_a_copy_by_email']);

$notificationCount = $data['notification_count'] ?? [];
$notificationPeriod = $data['notification_period'] ?? [];

$reminders = $notificationCount ? array_map(null, $notificationCount, $notificationPeriod) : [];

if (isset($id) && $id) {
// there is an Id => the announcement already exists => update mode
$file_comment = $announcementAttachmentIsDisabled ? null : $_POST['file_comment'];
Expand Down Expand Up @@ -725,7 +750,8 @@
$data['users'],
api_get_course_entity(),
api_get_session_entity(),
api_get_group_entity()
api_get_group_entity(),
$reminders
);
}

Expand Down
30 changes: 30 additions & 0 deletions public/main/inc/lib/agenda.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -3594,4 +3594,34 @@ public function formatEventDate($utcTime)

return $eventDate->format(DateTime::ISO8601);
}

public static function getJsForReminders(string $cssSelectorBtnAdd): string
{
return '
var template = \'<div class="flex flex-row items-center gap-4">\' +
\'<input min="0" step="1" id="notification_count[]" type="number" name="notification_count[]">\' +
\'<select name="notification_period[]" id="form_notification_period[]">\' +
\'<option value="i">'.get_lang('Minutes').'</option>\' +
\'<option value="h">'.get_lang('Hours').'</option>\' +
\'<option value="d">'.get_lang('Days').'</option>\' +
\'</select>\' +
\'<p class="form-control-static">'.get_lang('Before').'</p>\' +
\'<button class="btn btn--danger delete-notification" type="button" aria-label="'.get_lang('Delete').'">\' +
\'<i class="mdi mdi-close" aria-hidden="true"></i>\' +
\'</button>\' +
\'</div>\';
$("'.$cssSelectorBtnAdd.'").on("click", function (e) {
e.preventDefault();
$(template).appendTo("#notification_list");
$("#notification_list select").selectpicker("refresh");
});
$("#notification_list").on("click", ".delete-notification", function (e) {
e.preventDefault();
$(this).parents(".form-group").remove();
});';
}
}
14 changes: 13 additions & 1 deletion src/CourseBundle/Repository/CCalendarEventRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
namespace Chamilo\CourseBundle\Repository;

use Chamilo\CoreBundle\Entity\AbstractResource;
use Chamilo\CoreBundle\Entity\AgendaReminder;
use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Entity\Session;
use Chamilo\CoreBundle\Entity\User;
Expand All @@ -31,7 +32,8 @@ public function createFromAnnouncement(
array $users,
Course $course,
?Session $session = null,
?CGroup $group = null
?CGroup $group = null,
array $remindersInfo = [],
): CCalendarEvent {
$event = (new CCalendarEvent())
->setTitle($announcement->getTitle())
Expand Down Expand Up @@ -71,6 +73,16 @@ public function createFromAnnouncement(
}
}

foreach ($remindersInfo as $reminderInfo) {
$reminder = new AgendaReminder();
$reminder->count = (int) $reminderInfo[0];
$reminder->period = $reminderInfo[1];

$reminder->decodeDateInterval();

$event->addReminder($reminder);
}

$em->persist($event);
$em->flush();

Expand Down

0 comments on commit b5e86d1

Please sign in to comment.