if ($sph_results->{total_found}) {
my @docid = map $_->{doc}, @{ $sph_results->{matches} };
my %get_all_params = (
cache => $c->cache,
bypass_cache => $c->req->param('bypass_cache') || 0,
schema => $c->model('DB'),
user_exists => $c->user_exists() || 0,
is_movie => $c->stash->{is_movie} || 0,
config => $c->config,
images_dir => $c->path_to(qw[ root static images ]),
);
if($get_all_params{user_exists}) {
$get_all_params{user_id} = $c->user->get('id');
}
my $documents = $c->model('DB::Document')->get_all_data_related_to_document_array(\@docid, \%get_all_params, $c);
# fill $documents with image proportions here
if($documents->[0]{document_type_name} eq 'photos' || $c->stash->{filter} eq 'photos') {
my $max_width = 750;
my $photos_per_row = 3;
my $document_chunks = [];
while( my @list = splice( @$documents, 0, $photos_per_row ) ) {
push @$document_chunks, \@list;
}
foreach my $documents (@$document_chunks) {
my $largest_height = 0;
foreach my $document (@$documents) {
if($document->{photos}[0]{large_photo}{height} > $largest_height) {
my $height = $document->{photos}[0]{large_photo}{height};
$largest_height = $height;
}
}
my $total_width = 0;
foreach my $document (@$documents) {
my $height = $document->{photos}[0]{large_photo}{height};
my $width = $document->{photos}[0]{large_photo}{width};
if($height) {
my $scale_factor = $largest_height / $height;
$document->{photos}[0]{large_photo}{scaled_height} = $height * $scale_factor;
$document->{photos}[0]{large_photo}{scaled_width} = $width * $scale_factor;
$total_width += $document->{photos}[0]{large_photo}{scaled_width};
}
}
foreach my $document (@$documents) {
my $height = $document->{photos}[0]{large_photo}{scaled_height};
my $width = $document->{photos}[0]{large_photo}{scaled_width};
if($width) {
my $percent = $width / $total_width;
$document->{photos}[0]{large_photo}{scaled_width} = int($max_width * $percent);
my $scale_factor = $document->{photos}[0]{large_photo}{scaled_width} / $width;
$document->{photos}[0]{large_photo}{scaled_height} = int($height * $scale_factor);
}
}
push @{ $c->stash->{document_blocks} }, $documents;
}
}