Browse Source

[Technique] Images : gestion image par défaut

feature/souke
Guillaume Bourgeois 11 months ago
parent
commit
a503999dbc
3 changed files with 17 additions and 6 deletions
  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 View File

* termes. * termes.
*/ */


use common\helpers\Image;
use common\helpers\Price; use common\helpers\Price;
use common\logic\Producer\Producer\Module\ProducerModule; use common\logic\Producer\Producer\Module\ProducerModule;
use common\logic\User\User\Module\UserModule; use common\logic\User\User\Module\UserModule;
<span class="sr-only">Toggle navigation</span> <span class="sr-only">Toggle navigation</span>
</a> </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"> <span class="logo">
<img class="img-logo" <img class="img-logo"
src="<?= Yii::$app->urlManagerProducer->getHostInfo() . '/' . Yii::$app->urlManagerProducer->baseUrl; ?>/uploads/<?= $producer->logo; ?>" src="<?= Yii::$app->urlManagerProducer->getHostInfo() . '/' . Yii::$app->urlManagerProducer->baseUrl; ?>/uploads/<?= $producer->logo; ?>"

+ 12
- 3
common/helpers/Image.php View File

$thumbnailFilename = self::getThumbnailFilename($filenameOriginal, $thumbnail); $thumbnailFilename = self::getThumbnailFilename($filenameOriginal, $thumbnail);
$thumbnailPath = $basePath . $thumbnailFilename; $thumbnailPath = $basePath . $thumbnailFilename;
$originalPath = $basePath . $filenameOriginal; $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 public static function getBasePath(bool $absoluteUrl = false): string
return $filenameArray[0].'-'.$thumbnail.'.'.$filenameArray[1]; 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 View File

* termes. * termes.
*/ */


use common\helpers\Image;
use common\logic\Feature\Feature\Feature; use common\logic\Feature\Feature\Feature;
use common\logic\Feature\Feature\FeatureModule; use common\logic\Feature\Feature\FeatureModule;
use common\logic\Order\Order\Model\Order; use common\logic\Order\Order\Model\Order;
<div class="container"> <div class="container">
<div id="left" class="col-md-3"> <div id="left" class="col-md-3">
<div class="fixed"> <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; ?>> <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']) ?>"> <a href="<?= \Yii::$app->urlManager->createUrl(['site/index']) ?>">
<img class="img-logo" <img class="img-logo"

Loading…
Cancel
Save