Hi all
my other puzzle, I'm updating the standard /util/get_contributor.mc template that David wrote - to add links to the Contributor bio story - if it exists. I wrote a subroutine that adds this link for a single contributor instance however I can't figure out how to insert this subroutine, in an elegant way, into the complex map/join for a multiple contributor array.
Here's the last part of the code:
<%init>;
# Get the list of contributors.
my @contribs = defined $type
? grep { $_->get_grp->get_name eq $type} $asset->get_contributors
: $asset->get_contributors;
unless (@contribs) {
# If there are no contributors, just output the default and return.
$m->print($default);
return 1;
}
#DAWN ADDED, works : search for the first published Profile story where this contributor is the related contributor
sub get_profile {
my ($profile) = $story->list({
element_key_name => 'profile',
contrib_id => $_[0]->get_id,
Limit => 1,
unexpired => 1,
publish_status => '1',
});
$profile->get_uri if defined $profile;
}
if ($#contribs == 0) {
# There's just one contributor. Format and return.
#DAWN ADDED, works for single contrib:
my $uri = get_profile($contribs[0]);
if($uri){
$m->print('<a href="'.$uri.'">'.$contribs[0]->get_name($format).'</a>');
}else{
$m->print($contribs[0]->get_name($format));
}
return 1;
}
if ($sort) {
# We need to resort them.
my $get = $sort eq 'full_name' ? sub { $_[0]->get_name($format) } :
Bric::Util::Grp::Parts::Member::Contrib->my_meths->{$sort}{get_meth};
@contribs = sort { lc $get->($a) cmp lc $get->($b) } @contribs;
}
# Grab the last name in the list.
my $last = pop @contribs;
# Output the list.
# DAWN QUESTION: How do I add the get_profile subroutine into this map business below - and create a conditional test - in an elegant way? Maybe I should be pushing values onto a new array?
$m->print(join($sep, map { '<a href="'.$uri.'">'.$_->get_name($format).'</a>' } @contribs),
$final, '<a href="'.$uri.'">'.$last->get_name($format).'</a>');
return 1;
</%init>
my other puzzle, I'm updating the standard /util/get_contributor.mc template that David wrote - to add links to the Contributor bio story - if it exists. I wrote a subroutine that adds this link for a single contributor instance however I can't figure out how to insert this subroutine, in an elegant way, into the complex map/join for a multiple contributor array.
Here's the last part of the code:
<%init>;
# Get the list of contributors.
my @contribs = defined $type
? grep { $_->get_grp->get_name eq $type} $asset->get_contributors
: $asset->get_contributors;
unless (@contribs) {
# If there are no contributors, just output the default and return.
$m->print($default);
return 1;
}
#DAWN ADDED, works : search for the first published Profile story where this contributor is the related contributor
sub get_profile {
my ($profile) = $story->list({
element_key_name => 'profile',
contrib_id => $_[0]->get_id,
Limit => 1,
unexpired => 1,
publish_status => '1',
});
$profile->get_uri if defined $profile;
}
if ($#contribs == 0) {
# There's just one contributor. Format and return.
#DAWN ADDED, works for single contrib:
my $uri = get_profile($contribs[0]);
if($uri){
$m->print('<a href="'.$uri.'">'.$contribs[0]->get_name($format).'</a>');
}else{
$m->print($contribs[0]->get_name($format));
}
return 1;
}
if ($sort) {
# We need to resort them.
my $get = $sort eq 'full_name' ? sub { $_[0]->get_name($format) } :
Bric::Util::Grp::Parts::Member::Contrib->my_meths->{$sort}{get_meth};
@contribs = sort { lc $get->($a) cmp lc $get->($b) } @contribs;
}
# Grab the last name in the list.
my $last = pop @contribs;
# Output the list.
# DAWN QUESTION: How do I add the get_profile subroutine into this map business below - and create a conditional test - in an elegant way? Maybe I should be pushing values onto a new array?
$m->print(join($sep, map { '<a href="'.$uri.'">'.$_->get_name($format).'</a>' } @contribs),
$final, '<a href="'.$uri.'">'.$last->get_name($format).'</a>');
return 1;
</%init>