Announcement: Allow to add event reminders to event created from announcement - refs BT#21582

pull/5585/head
Angel Fernando Quiroz Campos 1 year ago
parent 602d1ac5c2
commit b5e86d12a1
  1. 28
      public/main/announcements/announcements.php
  2. 30
      public/main/inc/lib/agenda.lib.php
  3. 14
      src/CourseBundle/Repository/CCalendarEventRepository.php

@ -2,6 +2,7 @@
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Component\Utils\ActionIcon;
use Chamilo\CoreBundle\Entity\AbstractResource; use Chamilo\CoreBundle\Entity\AbstractResource;
use Chamilo\CoreBundle\Framework\Container; use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CourseBundle\Entity\CAnnouncement; use Chamilo\CourseBundle\Entity\CAnnouncement;
@ -624,6 +625,24 @@ switch ($action) {
$form->addHtml('<div id="add_event_options" style="display:none;">'); $form->addHtml('<div id="add_event_options" style="display:none;">');
$form->addDateTimePicker('event_date_start', get_lang('Date start')); $form->addDateTimePicker('event_date_start', get_lang('Date start'));
$form->addDateTimePicker('event_date_end', get_lang('Date end')); $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>'); $form->addHtml('</div>');
} }
@ -646,6 +665,12 @@ switch ($action) {
$data['users'] = $data['users'] ?? []; $data['users'] = $data['users'] ?? [];
$sendToUsersInSession = isset($data['send_to_users_in_session']); $sendToUsersInSession = isset($data['send_to_users_in_session']);
$sendMeCopy = isset($data['send_me_a_copy_by_email']); $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) { if (isset($id) && $id) {
// there is an Id => the announcement already exists => update mode // there is an Id => the announcement already exists => update mode
$file_comment = $announcementAttachmentIsDisabled ? null : $_POST['file_comment']; $file_comment = $announcementAttachmentIsDisabled ? null : $_POST['file_comment'];
@ -725,7 +750,8 @@ switch ($action) {
$data['users'], $data['users'],
api_get_course_entity(), api_get_course_entity(),
api_get_session_entity(), api_get_session_entity(),
api_get_group_entity() api_get_group_entity(),
$reminders
); );
} }

@ -3594,4 +3594,34 @@ class Agenda
return $eventDate->format(DateTime::ISO8601); 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();
});';
}
} }

@ -7,6 +7,7 @@ declare(strict_types=1);
namespace Chamilo\CourseBundle\Repository; namespace Chamilo\CourseBundle\Repository;
use Chamilo\CoreBundle\Entity\AbstractResource; use Chamilo\CoreBundle\Entity\AbstractResource;
use Chamilo\CoreBundle\Entity\AgendaReminder;
use Chamilo\CoreBundle\Entity\Course; use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Entity\Session; use Chamilo\CoreBundle\Entity\Session;
use Chamilo\CoreBundle\Entity\User; use Chamilo\CoreBundle\Entity\User;
@ -31,7 +32,8 @@ final class CCalendarEventRepository extends ResourceRepository
array $users, array $users,
Course $course, Course $course,
?Session $session = null, ?Session $session = null,
?CGroup $group = null ?CGroup $group = null,
array $remindersInfo = [],
): CCalendarEvent { ): CCalendarEvent {
$event = (new CCalendarEvent()) $event = (new CCalendarEvent())
->setTitle($announcement->getTitle()) ->setTitle($announcement->getTitle())
@ -71,6 +73,16 @@ final class CCalendarEventRepository extends ResourceRepository
} }
} }
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->persist($event);
$em->flush(); $em->flush();

Loading…
Cancel
Save