React appropriately when there are no random list search results

This commit is contained in:
im-mi 2016-09-23 12:31:02 -04:00
parent 3bebe77add
commit f763fc1356
2 changed files with 15 additions and 7 deletions

View file

@ -44,8 +44,11 @@ class RandomList extends Extension {
$random_images = array();
// generate random images
for ($i = 0; $i < $images_per_page; $i++)
array_push($random_images, Image::by_random($search_terms));
for ($i = 0; $i < $images_per_page; $i++) {
$random_image = Image::by_random($search_terms);
if (!$random_image) continue;
array_push($random_images, $random_image);
}
$this->theme->set_page($search_terms);
$this->theme->display_page($page, $random_images);

View file

@ -17,13 +17,18 @@ class RandomListTheme extends Themelet {
public function display_page(Page $page, $images) {
$page->title = "Random Images";
$html = "<b>Refresh the page to view more images</b>
<div class='shm-image-list'>";
$html = "<b>Refresh the page to view more images</b>";
if (count($images)) {
$html .= "<div class='shm-image-list'>";
foreach ($images as $image)
$html .= $this->build_thumb_html($image);
foreach ($images as $image)
$html .= $this->build_thumb_html($image);
$html .= "</div>";
} else {
$html .= "<br/><br/>No images were found to match the search criteria";
}
$html .= "</div>";
$page->add_block(new Block("Random Images", $html));
$nav = $this->build_navigation($this->search_terms);