Agenda: Fix save invitations or subscribers

edit event - refs BT#20946
pull/4863/head
Angel Fernando Quiroz Campos 2 years ago
parent 063b4a6b78
commit 73095bccea
  1. 1
      main/calendar/agenda.php
  2. 4
      main/calendar/agenda_js.php
  3. 109
      main/inc/lib/agenda.lib.php
  4. 19
      main/template/default/agenda/month.tpl

@ -183,6 +183,7 @@ if ($allowToEdit) {
$subscriptionItemId = isset($_REQUEST['subscription_item']) ? (int) $_REQUEST['subscription_item'] : null;
$maxSubscriptions = (int) ($_REQUEST['max_subscriptions'] ?? 0);
$reminders = $notificationCount ? array_map(null, $notificationCount, $notificationPeriod) : [];
$eventId = $agenda->addEvent(

@ -290,8 +290,8 @@ $allowEventSubscriptions = api_is_platform_admin()
if ($allowCollectiveInvitations && $allowEventSubscriptions) {
$form->addRadio(
'invintation_type',
get_lang('Allow'),
'invitation_type',
get_lang('Allowed'),
[
'invitations' => get_lang('Invitations'),
'subscriptions' => get_lang('Subscriptions'),

@ -292,6 +292,13 @@ class Agenda
if (api_get_configuration_value('agenda_event_subscriptions') && api_is_platform_admin()) {
$personalEvent = $em->find(PersonalAgenda::class, $id);
if ($personalEvent->hasInvitation()
&& !($personalEvent->getInvitation() instanceof AgendaEventSubscription)
) {
break;
}
$personalEvent
->setSubscriptionVisibility($subscriptionVisibility)
->setSubscriptionItemId($subscriptionItemId ?: null)
@ -3137,9 +3144,9 @@ class Agenda
$allowCollectiveInvitations = $agendaCollectiveInvitations && 'personal' === $this->type;
$allowEventSubscriptions = 'personal' === $this->type && $agendaEventSubscriptions;
if ($allowCollectiveInvitations && $allowEventSubscriptions) {
if ($allowCollectiveInvitations && $allowEventSubscriptions && !$personalEvent->hasInvitation()) {
$form->addRadio(
'invintation_type',
'invitation_type',
get_lang('Allow'),
[
'invitations' => get_lang('Invitations'),
@ -3173,7 +3180,7 @@ class Agenda
if ($allowInvitees) {
$form->addHtml(
'<div id="invitations-block" style="display:'.($allowEventSubscriptions ? 'none;' : 'block;').'">'
'<div id="invitations-block" style="display:'.($allowEventSubscriptions && !$allowInvitees ? 'none;' : 'block;').'">'
);
$form->addHeader(get_lang('Invitations'));
$form->addSelectAjax(
@ -3195,40 +3202,57 @@ class Agenda
}
if ($agendaEventSubscriptions) {
$form->addHtml(
'<div id="subscriptions-block" style="display:'.($allowCollectiveInvitations ? 'none;' : 'block;').'">'
);
$form->addHeader(get_lang('Subscriptions'));
$form->addSelect(
'subscription_visibility',
get_lang('AllowSubscriptions'),
[
AgendaEventSubscription::SUBSCRIPTION_NO => get_lang('No'),
AgendaEventSubscription::SUBSCRIPTION_ALL => get_lang('AllUsersOfThePlatform'),
AgendaEventSubscription::SUBSCRIPTION_CLASS => get_lang('UsersInsideClass'),
]
);
$slctItem = $form->addSelectAjax(
'subscription_item',
get_lang('SocialGroup').' / '.get_lang('Class'),
[],
[
'url' => api_get_path(WEB_AJAX_PATH).'usergroup.ajax.php?a=get_class_by_keyword',
'disabled' => 'disabled',
]
);
$subscribers = [];
$allowSubscribers = true;
$form->addNumeric(
'max_subscriptions',
['', get_lang('MaxSubscriptionsLeaveEmptyToNotLimit')],
[
'disabled' => 'disabled',
'step' => 1,
'min' => 0,
'value' => 0,
]
);
$form->addHtml("<script>
if ($personalEvent) {
$eventInvitation = $personalEvent->getInvitation();
$allowSubscribers = $eventInvitation instanceof AgendaEventSubscription;
$subscribers = self::getInviteesForPersonalEvent($personalEvent->getId(), AgendaEventSubscriber::class);
$subscribers = array_combine(
array_column($subscribers, 'id'),
array_column($subscribers, 'name')
);
$params['subscribers'] = array_keys($subscribers);
}
if ($allowSubscribers) {
$form->addHtml(
'<div id="subscriptions-block" style="display:'.($allowCollectiveInvitations ? 'none;' : 'block;').'">'
);
$form->addHeader(get_lang('Subscriptions'));
$form->addSelect(
'subscription_visibility',
get_lang('AllowSubscriptions'),
[
AgendaEventSubscription::SUBSCRIPTION_NO => get_lang('No'),
AgendaEventSubscription::SUBSCRIPTION_ALL => get_lang('AllUsersOfThePlatform'),
AgendaEventSubscription::SUBSCRIPTION_CLASS => get_lang('UsersInsideClass'),
]
);
$slctItem = $form->addSelectAjax(
'subscription_item',
get_lang('SocialGroup').' / '.get_lang('Class'),
[],
[
'url' => api_get_path(WEB_AJAX_PATH).'usergroup.ajax.php?a=get_class_by_keyword',
'disabled' => 'disabled',
]
);
$form->addNumeric(
'max_subscriptions',
['', get_lang('MaxSubscriptionsLeaveEmptyToNotLimit')],
[
'disabled' => 'disabled',
'step' => 1,
'min' => 0,
'value' => 0,
]
);
$form->addHtml("<script>
$(function () {
$('#add_event_subscription_visibility')
.on('change', function () {
@ -3240,15 +3264,6 @@ class Agenda
</script>
");
if ($personalEvent) {
$subscribers = self::getInviteesForPersonalEvent($personalEvent->getId(), AgendaEventSubscriber::class);
$subscribers = array_combine(
array_column($subscribers, 'id'),
array_column($subscribers, 'name')
);
$params['subscribers'] = array_keys($subscribers);
$form->addSelect(
'subscribers',
get_lang('Subscribers'),
@ -4955,6 +4970,10 @@ class Agenda
*/
public static function saveCollectiveProperties(array $inviteeUserList, bool $isCollective, int $eventId)
{
if (empty($inviteeUserList)) {
return;
}
$em = Database::getManager();
$event = $em->find('ChamiloCoreBundle:PersonalAgenda', $eventId);

@ -350,6 +350,11 @@ $(function() {
$('#form_subscriptions_edit').hide().html('');
{% endif %}
{% if 'personal' == type and agenda_collective_invitations and (agenda_event_subscriptions and api_is_platform_admin()) %}
$('#invitation_type-group').show();
$('#invitations-block, #subscriptions-block').hide();
{% endif %}
$("#dialog-form").dialog("open");
$("#dialog-form").dialog({
buttons: {
@ -507,8 +512,12 @@ $(function() {
var delete_url = '{{ web_agenda_ajax_url }}&a=delete_event&id='+calEvent.id;
$('#invitations-block, #subscriptions-block').hide();
// Edit event.
if (calEvent.editable) {
$('#invitation_type-group').hide();
$('#visible_to_input').hide();
$('#add_as_announcement_div').hide();
{% if type != 'admin' %}
@ -658,6 +667,9 @@ $(function() {
return '';
}
$('#invitation_type-group').hide()
$('#invitations-block').show();
return calEvent.invitees
.map(function (invitee) { return invitee.name; })
.join('<br>');
@ -854,6 +866,8 @@ $(function() {
}
});
} else {
$('#invitation_type-group').show();
// Simple form
$('#simple_start_date').html(startDateToString);
if (diffDays > 1) {
@ -939,6 +953,9 @@ $(function() {
return '';
}
$('#invitation_type-group').hide();
$('#invitations-block').show();
return calEvent.invitees
.map(function (invitee) { return invitee.name; })
.join('<br>');
@ -1064,6 +1081,8 @@ $(function() {
return '';
}
$('#subscriptions-block').show();
var html = '';
html += '<dl class="dl-horizontal">';
html += "<dt>{{ 'AllowSubscriptions'|get_lang }}</dt>";

Loading…
Cancel
Save