Skip to content

Commit

Permalink
Gallery: Fix "Argument must be of type string, null given" (#703)
Browse files Browse the repository at this point in the history
Further improved the views for handling an missing image.
  • Loading branch information
blackcoder87 authored Jul 9, 2023
1 parent e316796 commit f101582
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 22 deletions.
10 changes: 5 additions & 5 deletions application/modules/gallery/mappers/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public function getImageById(int $id): ?ImageModel
$imageModel = new ImageModel();
$imageModel->setId($imageRow['imgid']);
$imageModel->setImageId($imageRow['image_id']);
$imageModel->setImageUrl($imageRow['url']);
$imageModel->setImageThumb($imageRow['url_thumb']);
$imageModel->setImageUrl((string)$imageRow['url']);
$imageModel->setImageThumb((string)$imageRow['url_thumb']);
$imageModel->setImageTitle($imageRow['image_title']);
$imageModel->setImageDesc($imageRow['image_description']);
$imageModel->setGalleryId($imageRow['gallery_id']);
Expand Down Expand Up @@ -69,7 +69,7 @@ public function getLastImageByGalleryId(int $id): ?ImageModel

$imageModel = new ImageModel();
$imageModel->setImageId($imageRow['image_id']);
$imageModel->setImageThumb($imageRow['url_thumb']);
$imageModel->setImageThumb((string)$imageRow['url_thumb']);
$imageModel->setImageTitle($imageRow['image_title']);
$imageModel->setImageDesc($imageRow['image_description']);
$imageModel->setVisits($imageRow['visits']);
Expand Down Expand Up @@ -141,8 +141,8 @@ public function getImageByGalleryId(int $id, Pagination $pagination = NULL): arr

foreach ($imageArray as $entries) {
$entryModel = new ImageModel();
$entryModel->setImageUrl($entries['url']);
$entryModel->setImageThumb($entries['url_thumb']);
$entryModel->setImageUrl((string)$entries['url']);
$entryModel->setImageThumb((string)$entries['url_thumb']);
$entryModel->setId($entries['imgid']);
$entryModel->setImageTitle($entries['image_title']);
$entryModel->setImageDesc($entries['image_description']);
Expand Down
35 changes: 20 additions & 15 deletions application/modules/gallery/views/index/show.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,30 @@

<div id="gallery">
<?php foreach ($this->get('image') as $image): ?>

<?php $commentsCount = $commentMapper->getCountComments ('gallery/index/showimage/id/'.$image->getId()); ?>

<div class="col-xs-6 col-md-4 col-lg-3 col-sm-4">
<div class="panel panel-default">

<a class="venobox" data-gall="gallery01" href="<?=$this->getUrl().'/' .$image->getImageUrl() ?>"title="<?=$image->getImageTitle() ?> ">

<div class="panel-image thumbnail">
<img src="<?=$this->getUrl().'/'.$image->getImageThumb() ?>" class="panel-image-preview" alt="<?=$image->getImageTitle()?>" />
</div>

<?php if (file_exists($image->getImageThumb())): ?>
<a class="venobox" data-gall="gallery01" href="<?= $this->getUrl() . '/' . $image->getImageUrl() ?>" title="<?= $image->getImageTitle() ?> ">
<div class="panel-image thumbnail">
<img src="<?= $this->getUrl() . '/' . $image->getImageThumb() ?>" class="panel-image-preview" alt="<?= $this->escape($image->getImageTitle()) ?>" />
</div>
</a>
<?php else: ?>
<a class="venobox" data-gall="gallery01" href="<?= $this->getUrl() . '/' . $image->getImageUrl() ?>" title="<?= $image->getImageTitle() ?> ">
<div class="panel-image thumbnail">
<img src="<?=$this->getBaseUrl('application/modules/media/static/img/nomedia.png') ?>" class="panel-image-preview" alt="<?=$this->getTrans('noMediaAlt') ?>" />
</div>
</a>
<?php endif; ?>

<a href="<?=$this->getUrl(['action' => 'showimage', 'id' => $image->getId()]) ?>" title="<?=$this->getTrans('description')?>">


<div class="panel-footer text-center">
<i class="fa-regular fa-comment"></i> <?=$commentsCount ?>
<i class="fa-solid fa-eye"> <?=$image->getVisits() ?></i>
</div>
<div class="panel-footer text-center">
<i class="fa-regular fa-comment"></i> <?=$commentsCount ?>
<i class="fa-solid fa-eye"></i> <?=$image->getVisits() ?>
</div>
</a>
</div>
</div>
<?php endforeach; ?>
Expand All @@ -77,4 +82,4 @@
navTouch: true,
spinner: 'pulse',
})
</script>
</script>
10 changes: 8 additions & 2 deletions application/modules/gallery/views/index/showimage.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@
<div id="gallery">
<div class="row">
<div class="col-md-6">
<a class="venobox" href="<?=$this->getUrl().'/'.$image->getImageUrl() ?>">
<img src="<?=$this->getUrl().'/'.$image->getImageUrl() ?>" alt="<?=$this->escape($image->getImageTitle()) ?>"/>
<?php if ($image->getImageUrl()): ?>
<a class="venobox" href="<?= $this->getUrl() . '/' . $image->getImageUrl() ?>">
<img src="<?= $this->getUrl() . '/' . $image->getImageUrl() ?>" alt="<?= $this->escape($image->getImageTitle()) ?>" />
</a>
<?php else: ?>
<a class="venobox" href="<?= $this->getUrl() . '/' . $image->getImageUrl() ?>">
<img src="<?=$this->getBaseUrl('application/modules/media/static/img/nomedia.png') ?>" alt="<?=$this->getTrans('noMediaAlt') ?>" />
</a>
<?php endif; ?>
</div>
</div>
</div>
Expand Down

0 comments on commit f101582

Please sign in to comment.