Bladeren bron

[Technique] Images : gestion image par défaut

feature/souke
Guillaume Bourgeois 11 maanden geleden
bovenliggende
commit
a503999dbc
3 gewijzigde bestanden met toevoegingen van 17 en 6 verwijderingen
  1. +3
    -2
      backend/views/layouts/header.php
  2. +12
    -3
      common/helpers/Image.php
  3. +2
    -1
      producer/views/layouts/main.php

+ 3
- 2
backend/views/layouts/header.php Bestand weergeven

@@ -36,6 +36,7 @@
* termes.
*/

use common\helpers\Image;
use common\helpers\Price;
use common\logic\Producer\Producer\Module\ProducerModule;
use common\logic\User\User\Module\UserModule;
@@ -62,8 +63,8 @@ $userCurrent = GlobalParam::getCurrentUser();
<span class="sr-only">Toggle navigation</span>
</a>

<span class="producer-panel<?php if(!$producer->logo): ?> without-logo<?php endif; ?>">
<?php if($producer->logo): ?>
<span class="producer-panel<?php if(!$producer->logo || !Image::isPhotoExist($producer->logo)): ?> without-logo<?php endif; ?>">
<?php if($producer->logo && Image::isPhotoExist($producer->logo)): ?>
<span class="logo">
<img class="img-logo"
src="<?= Yii::$app->urlManagerProducer->getHostInfo() . '/' . Yii::$app->urlManagerProducer->baseUrl; ?>/uploads/<?= $producer->logo; ?>"

+ 12
- 3
common/helpers/Image.php Bestand weergeven

@@ -31,8 +31,17 @@ class Image
$thumbnailFilename = self::getThumbnailFilename($filenameOriginal, $thumbnail);
$thumbnailPath = $basePath . $thumbnailFilename;
$originalPath = $basePath . $filenameOriginal;
$defaultImagePath = $basePath . 'default.jpg';

return self::isThumbnailExist($thumbnailFilename) ? $thumbnailPath : $originalPath;
if(self::isPhotoExist($thumbnailFilename)) {
return $thumbnailPath;
}

if(self::isPhotoExist($filenameOriginal)) {
return $originalPath;
}

return $defaultImagePath;
}

public static function getBasePath(bool $absoluteUrl = false): string
@@ -51,8 +60,8 @@ class Image
return $filenameArray[0].'-'.$thumbnail.'.'.$filenameArray[1];
}

public static function isThumbnailExist(string $thumbnailFilename): bool
public static function isPhotoExist(string $filename): bool
{
return file_exists(\Yii::getAlias('@producer').'/web/'.self::DIR_UPLOADS.'/'.$thumbnailFilename);
return file_exists(\Yii::getAlias('@producer').'/web/'.self::DIR_UPLOADS.'/'.$filename);
}
}

+ 2
- 1
producer/views/layouts/main.php Bestand weergeven

@@ -36,6 +36,7 @@
* termes.
*/

use common\helpers\Image;
use common\logic\Feature\Feature\Feature;
use common\logic\Feature\Feature\FeatureModule;
use common\logic\Order\Order\Model\Order;
@@ -88,7 +89,7 @@ if (!Yii::$app->user->isGuest) {
<div class="container">
<div id="left" class="col-md-3">
<div class="fixed">
<?php if (strlen($producer->logo)): ?>
<?php if (strlen($producer->logo) && Image::isPhotoExist($producer->logo)): ?>
<div id="logo"<?php if (!is_null($producer->background_color_logo) && strlen($producer->background_color_logo)): ?> style="background-color:<?= Html::encode($producer->background_color_logo); ?>"<?php endif; ?>>
<a href="<?= \Yii::$app->urlManager->createUrl(['site/index']) ?>">
<img class="img-logo"

Laden…
Annuleren
Opslaan