Skip to content

Commit 8faaf0b

Browse files
committed
Calendar: export members subscribed or invited to an event to csv -refs BT#20952
1 parent 3fd9985 commit 8faaf0b

File tree

3 files changed

+94
-1
lines changed

3 files changed

+94
-1
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/* For licensing terms, see /license.txt */
3+
4+
/**
5+
* This file exclusively export event members for invitation or subscription.
6+
*
7+
* @author Nicolas Ducoulombier <nicolas.ducoulombier@beeznest.com>
8+
*/
9+
// setting the global file that gets the general configuration, the databases, the languages, ...
10+
require_once __DIR__.'/../inc/global.inc.php';
11+
$this_section = SECTION_MYAGENDA;
12+
api_block_anonymous_users();
13+
14+
$type = 'personal';
15+
$id = (int) explode('_', $_REQUEST['id'])[1];
16+
$action = $_REQUEST['a'] ?? null;
17+
18+
if (empty($id)) {
19+
exit;
20+
}
21+
$agenda = new Agenda($type);
22+
23+
switch ($action) {
24+
case 'export_invitees' :
25+
if (!$agenda->getIsAllowedToEdit()) {
26+
break;
27+
}
28+
$data = $agenda->exportEventMembersToCsv($id, "Invitee");
29+
Export::arrayToCsv($data);
30+
break;
31+
case 'export_subscribers' :
32+
if (!$agenda->getIsAllowedToEdit()) {
33+
break;
34+
}
35+
$data = $agenda->exportEventMembersToCsv($id, "Subscriber");
36+
Export::arrayToCsv($data);
37+
break;
38+
}
39+
exit;
40+

main/inc/lib/agenda.lib.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,6 +1414,38 @@ public function deleteEvent($id, $deleteAllItemsFromSerie = false)
14141414
break;
14151415
}
14161416
}
1417+
1418+
public function exportEventMembersToCsv(int $id, $type = "Invitee")
1419+
{
1420+
if (false === api_get_configuration_value('agenda_event_subscriptions') && false === api_get_configuration_value('agenda_collective_invitations')) {
1421+
return;
1422+
}
1423+
if ('personal' !== $this->type) {
1424+
return;
1425+
}
1426+
if ($type === "Invitee") {
1427+
$members = self::getInviteesForPersonalEvent($id, AgendaEventInvitee::class);
1428+
} elseif ($type === "Subscriber") {
1429+
$members = self::getInviteesForPersonalEvent($id, AgendaEventSubscriber::class);
1430+
}
1431+
$data = [];
1432+
$data[] = [
1433+
'OfficialCode',
1434+
'Lastname',
1435+
'Firsname',
1436+
'Email',
1437+
];
1438+
$count = 1;
1439+
foreach ($members as $member) {
1440+
$user = api_get_user_info($member['id']);
1441+
$data[$count][] = $user['official_code'];
1442+
$data[$count][] = $user['lastname'];
1443+
$data[$count][] = $user['firstname'];
1444+
$data[$count][] = $user['email'];
1445+
$count++;
1446+
}
1447+
return $data;
1448+
}
14171449

14181450
public function subscribeCurrentUserToEvent(int $id)
14191451
{

main/template/default/agenda/month.tpl

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,18 @@ $(function() {
828828
$("#dialog-form").dialog('close');
829829
}
830830
});
831-
}
831+
},
832+
{% if (agenda_collective_invitations or agenda_event_subscriptions) and 'personal' == type %}
833+
'{{ "ExportUsers" | get_lang }}' : function() {
834+
if (isInvitation(calEvent)) {
835+
url = "{{ _p.web_main }}calendar/exportEventMembers.php?a=export_invitees&id=" + calEvent.id;
836+
} else {
837+
url = "{{ _p.web_main }}calendar/exportEventMembers.php?a=export_subscribers&id=" + calEvent.id;
838+
}
839+
window.location.href = url;
840+
},
841+
{% endif %}
842+
832843
},
833844
close: function() {
834845
$("#title_edit").hide();
@@ -1074,6 +1085,16 @@ $(function() {
10741085
10751086
{{ agenda_reminders_js }}
10761087
1088+
function isInvitation (calEvent) {
1089+
if ((calEvent.invitees && calEvent.invitees.length)
1090+
|| !calEvent.subscription_visibility
1091+
) {
1092+
return true;
1093+
} else {
1094+
return false;
1095+
}
1096+
}
1097+
10771098
function showSubcriptionsContainer (calEvent) {
10781099
if ((calEvent.invitees && calEvent.invitees.length)
10791100
|| !calEvent.subscription_visibility

0 commit comments

Comments
 (0)