From 5f8a1cad2fc9a3f3a59f165787978860f609db9e Mon Sep 17 00:00:00 2001 From: DBinaghi <39097246+DBinaghi@users.noreply.github.com> Date: Tue, 21 Apr 2020 09:59:18 +0200 Subject: [PATCH] Fixes problem with collections image It seems that, when a Collection contains no Item with an image (because that Item's image was not generated, and Item is resorting to fallback image when shown), then the Collection itself does not show any image, not even the fallback one. This fix solves the problem: if no Item with an image is found, than function tries to find any Item and, in absence of an image, the fallback one will be used for the Collection too. Sort field and direction are mantained, as a featured Item could exist even if it didn't have an image. --- application/models/Collection.php | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/application/models/Collection.php b/application/models/Collection.php index 2cf47bb884..bea5a4ef07 100644 --- a/application/models/Collection.php +++ b/application/models/Collection.php @@ -225,10 +225,19 @@ public function getFile() 'sort_field' => 'featured', 'sort_dir' => 'd' ), 1); - if ($itemArray) { - return ($itemArray[0]->getFile()); - } else { - return null; - } - } + if ($itemArray) { + return ($itemArray[0]->getFile()); + } else { + // In case no Item with an image was found + $itemArray = $itemTable->findBy(array( + 'collection' => $this->id, + 'sort_field' => 'featured', + 'sort_dir' => 'd' + ), 1); + if ($itemArray) { + return ($itemArray[0]->getFile()); + } else { + return null; + } + } }