Skip to content

Commit

Permalink
issue #371 Show roles in H/H calling list
Browse files Browse the repository at this point in the history
  • Loading branch information
markov2 committed Mar 16, 2021
1 parent be64cb8 commit abd85fc
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 44 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 4 additions & 4 deletions pm/Taranis/CallingList.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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<firstname>, C<lastname>, C<role_name>, C<tel_regular> and
# * individuals, is also an ARRAY of HASES which has the C<firstname>, C<lastname>, C<role_names>, C<tel_regular> and
# C<tel_mobile> per individual.
# * comments, concerning the call
# * group_id and constituent_group_id, internal id of constituent group
Expand Down Expand Up @@ -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,
Expand All @@ -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} =
Expand Down
83 changes: 45 additions & 38 deletions pm/Taranis/Publish.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();

Expand Down Expand Up @@ -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 )
Expand Down
2 changes: 1 addition & 1 deletion templates/publish_call_list_savefile.tt
Original file line number Diff line number Diff line change
Expand Up @@ -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 %]
Expand Down
2 changes: 1 addition & 1 deletion templates/publish_details.tt
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Publication was sent to:
<tr class="publishing-details-call-contacts">
<td>[% IF individual.call247 %]24/7[% ELSE %]day[% END %]</td>
<td>[% individual.lastname _ ', ' _ individual.firstname %]</td>
<td>[% individual.role_name %]</td>
<td>[% individual.role_names %]</td>
<td>tel: [% IF individual.tel_regular; individual.tel_regular; ELSE; '-'; END %]</td>
<td>mob: [% IF individual.tel_mobile; individual.tel_mobile; ELSE; '-'; END %]</td>
</tr>
Expand Down

0 comments on commit abd85fc

Please sign in to comment.