From abd85fc6feeee1754ef43b70d1acc6b18764b50a Mon Sep 17 00:00:00 2001 From: Mark Overmeer Date: Tue, 16 Mar 2021 10:20:41 +0100 Subject: [PATCH] issue #371 Show roles in H/H calling list --- CHANGES | 1 + pm/Taranis/CallingList.pm | 8 +-- pm/Taranis/Publish.pm | 83 ++++++++++++++----------- templates/publish_call_list_savefile.tt | 2 +- templates/publish_details.tt | 2 +- 5 files changed, 52 insertions(+), 44 deletions(-) diff --git a/CHANGES b/CHANGES index 4e3dd4d..4ff5ae6 100644 --- a/CHANGES +++ b/CHANGES @@ -4,3 +4,4 @@ CHANGES from 3.7.4 onwards - #361 Individuals without roles not shown in call list - #365 = E41: correct use of AND between keyword lists - E47: change in SQL::Abstract v2 breaks sqlJoin +- #371 Show roles in H/H calling list diff --git a/pm/Taranis/CallingList.pm b/pm/Taranis/CallingList.pm index d7137ed..86b6f9e 100644 --- a/pm/Taranis/CallingList.pm +++ b/pm/Taranis/CallingList.pm @@ -43,7 +43,7 @@ our @EXPORT_OK = qw( # getCallingList: retrieve an array of hashes consisting of constituent groups. Each group has the following keys: # -# * individuals, is also an ARRAY of HASES which has the C, C, C, C and +# * individuals, is also an ARRAY of HASES which has the C, C, C, C and # C per individual. # * comments, concerning the call # * group_id and constituent_group_id, internal id of constituent group @@ -91,7 +91,7 @@ sub getCallingList($;$) { constituent_individual|ci id=constituent_id membership|m /], - -columns => 'ci.firstname, ci.lastname, ci.tel_mobile, ci.tel_regular, ci.call247', + -columns => 'ci.firstname, ci.lastname, ci.tel_mobile, ci.tel_regular, ci.call247, ci.id', -where => { 'm.group_id' => $group->{constituent_group_id}, 'ci.status' => 0, @@ -103,8 +103,8 @@ sub getCallingList($;$) { @indiv or next; foreach my $indiv (@indiv) { - $indiv->{role_name} = join ', ', sort - map $_->{role_name}, $ci->getRolesForIndividual($indiv); + $indiv->{role_names} = join ', ', sort + map $_->{role_name}, $ci->getRolesForIndividual($indiv->{id}); } $group->{individuals} = diff --git a/pm/Taranis/Publish.pm b/pm/Taranis/Publish.pm index c0b7eb1..0e26ac4 100644 --- a/pm/Taranis/Publish.pm +++ b/pm/Taranis/Publish.pm @@ -10,6 +10,7 @@ use Taranis qw(:all); use Taranis::Database; use Taranis::Config; use Taranis::Publication; +use Taranis::Constituent::Individual; use Taranis::FunctionalWrapper qw(Config Database Sql); use Taranis::Mail (); @@ -463,46 +464,52 @@ sub setSendingResult { sub getPublishDetails { my ($self, $publication_id, $publication_type) = @_; - return { - receivers_list => [ - Database->simple->select( - -from => [-join => qw/ - publication2constituent|p2c - constituent_id=id constituent_individual|ci - id=constituent_id membership - group_id=id constituent_group|cg - /], - -columns => [ - "array_to_string(array_agg(cg.name), ', ')|groupname", # group names, joined by ', ' - 'ci.id|ci_id', - 'ci.firstname', - 'ci.lastname', - 'ci.emailaddress', - "to_char(p2c.timestamp, 'DD-MM-YYYY HH24:MI:SS')|timestamp_str", - ], - -where => {'p2c.publication_id' => $publication_id, 'p2c.channel' => 1}, - -group_by => [qw/ci.id ci.firstname ci.lastname ci.emailaddress timestamp_str p2c.id/], - -order_by => [qw/lastname firstname/], - )->hashes + my @receivers = Database->simple->select( + -from => [ -join => qw/ + publication2constituent|p2c + constituent_id=id constituent_individual|ci + id=constituent_id membership + group_id=id constituent_group|cg + / ], + -columns => [ + "array_to_string(array_agg(cg.name), ', ')|groupname", # group names, joined by ', ' + 'ci.id|ci_id', + 'ci.firstname', + 'ci.lastname', + 'ci.emailaddress', + "to_char(p2c.timestamp, 'DD-MM-YYYY HH24:MI:SS')|timestamp_str", ], + -where => {'p2c.publication_id' => $publication_id, 'p2c.channel' => 1}, + -group_by => [qw/ci.id ci.firstname ci.lastname ci.emailaddress timestamp_str p2c.id/], + -order_by => [qw/lastname firstname/], + )->hashes; + + my $indivs = Taranis::Constituent::Individual->new; + foreach my $indiv (@receivers) { + my @roles = $indivs->getRolesForIndividual($indiv->{ci_id}); + $indiv->{role_names} = join ', ', map $_->{role_name}, @roles; + } - publication => Database->simple->select( - -from => lc($publication_type) eq 'advisory' - ? [-join => qw/publication|pu id=publication_id publication_advisory|pa/] - : 'publication as pu', - - -columns => [ - 'pu.approved_by', 'pu.published_by', - "to_char(pu.approved_on, 'DD-MM-YYYY HH24:MI:SS')|approved_on_str", - "to_char(pu.published_on, 'DD-MM-YYYY HH24:MI:SS')|published_on_str", - - lc($publication_type) eq 'advisory' - ? ('pa.title|pub_title', 'pa.damage', 'pa.probability') - : ('pu.title|pub_title'), - ], - -where => {'pu.id' => $publication_id}, - )->hash, - }; + my $publication = Database->simple->select( + -from => lc($publication_type) eq 'advisory' + ? [-join => qw/publication|pu id=publication_id publication_advisory|pa/] + : 'publication as pu', + + -columns => [ + 'pu.approved_by', 'pu.published_by', + "to_char(pu.approved_on, 'DD-MM-YYYY HH24:MI:SS')|approved_on_str", + "to_char(pu.published_on, 'DD-MM-YYYY HH24:MI:SS')|published_on_str", + + lc($publication_type) eq 'advisory' + ? ('pa.title|pub_title', 'pa.damage', 'pa.probability') + : ('pu.title|pub_title'), + ], + -where => {'pu.id' => $publication_id}, + )->hash; + + +{ receivers_list => \@receivers, + publication => $publication, + }; } # setAnalysisToDoneStatus( $publicationId, $namedPublicationId ) diff --git a/templates/publish_call_list_savefile.tt b/templates/publish_call_list_savefile.tt index 22202ef..c8fbf27 100644 --- a/templates/publish_call_list_savefile.tt +++ b/templates/publish_call_list_savefile.tt @@ -5,7 +5,7 @@ [% FOREACH contact IN group.individuals %] [% IF contact.call247 %][% " 24/7 " %][% ELSE %][% " day " %][% END %] - [% " CONTACT: " _ contact.firstname.decodeEntity _ contact.lastname.decodeEntity _ " (" _ contact.role_name.decodeEntity _ ")\n" %] + [% " CONTACT: " _ contact.firstname.decodeEntity _ ' ' _ contact.lastname.decodeEntity _ " (" _ contact.role_names.decodeEntity _ ")\n" %] [%- IF contact.tel_regular %] [% " tel: " _ contact.tel_regular _ "\n" +%] [% END %] diff --git a/templates/publish_details.tt b/templates/publish_details.tt index 3bc2186..892dec2 100644 --- a/templates/publish_details.tt +++ b/templates/publish_details.tt @@ -77,7 +77,7 @@ Publication was sent to: [% IF individual.call247 %]24/7[% ELSE %]day[% END %] [% individual.lastname _ ', ' _ individual.firstname %] - [% individual.role_name %] + [% individual.role_names %] tel: [% IF individual.tel_regular; individual.tel_regular; ELSE; '-'; END %] mob: [% IF individual.tel_mobile; individual.tel_mobile; ELSE; '-'; END %]