Hey guys,
Looking for a bit of help here with some basic Perl in the globals.
We're busy redoing our comment system's layout and requires us to use a placeholder image as an avatar for users who do not have a profile picture set.
However, the way the global is set up - when there is no picture in the profile, it returns an empty value - as opposed to a null value.
This means that we're unable to do an <%if uiPhoto%>.
So we're thinking that we need to change it so that the global returns a default value (Image URL) when it finds no profile picture for that particular user.
Here's the global:
my $username = shift;
my $size = shift;
use lib ('/home/site/site.com/cgi-bin/forum/admin');
my $DB = GT::SQL->new('/home/site/site.com/cgi-bin/forum/admin/defs');
my $sth = $DB->table('User')->do_query(qq|
SELECT * FROM forum_User
WHERE user_icon IS NOT NULL
AND profile_picture_index != 0
AND user_username = "$username";
|);
my $out;
my ( @UserInfo );
my $hits = 0;
while (my $res = $sth->fetchrow_hashref()) {
my $username = $res->{user_username};
my $pic = $res->{profile_picture_index};
if($pic == 0)
{
next;
}
$hits++;
my $rows = $DB->table('Profile_Pictures')->do_query(qq|
SELECT picture$pic|.qq|_$size FROM forum_Profile_Pictures
WHERE user_id = $res->{user_id};
|);
my $row = $rows->fetchrow_arrayref();
my $picLink = qq|/graphics/forum/users/profile_pictures/$row->[0]|;
push(@UserInfo, { 'uiUsername' => $username,
'uiPhoto' => $picLink,
},
);
}
return {UserInfoLoop => \@UserInfo,
UserInfoHits => $hits,
};
}Thanks!
Looking for a bit of help here with some basic Perl in the globals.
We're busy redoing our comment system's layout and requires us to use a placeholder image as an avatar for users who do not have a profile picture set.
However, the way the global is set up - when there is no picture in the profile, it returns an empty value - as opposed to a null value.
This means that we're unable to do an <%if uiPhoto%>.
So we're thinking that we need to change it so that the global returns a default value (Image URL) when it finds no profile picture for that particular user.
Here's the global:
Code:
sub { my $username = shift;
my $size = shift;
use lib ('/home/site/site.com/cgi-bin/forum/admin');
my $DB = GT::SQL->new('/home/site/site.com/cgi-bin/forum/admin/defs');
my $sth = $DB->table('User')->do_query(qq|
SELECT * FROM forum_User
WHERE user_icon IS NOT NULL
AND profile_picture_index != 0
AND user_username = "$username";
|);
my $out;
my ( @UserInfo );
my $hits = 0;
while (my $res = $sth->fetchrow_hashref()) {
my $username = $res->{user_username};
my $pic = $res->{profile_picture_index};
if($pic == 0)
{
next;
}
$hits++;
my $rows = $DB->table('Profile_Pictures')->do_query(qq|
SELECT picture$pic|.qq|_$size FROM forum_Profile_Pictures
WHERE user_id = $res->{user_id};
|);
my $row = $rows->fetchrow_arrayref();
my $picLink = qq|/graphics/forum/users/profile_pictures/$row->[0]|;
push(@UserInfo, { 'uiUsername' => $username,
'uiPhoto' => $picLink,
},
);
}
return {UserInfoLoop => \@UserInfo,
UserInfoHits => $hits,
};
}