diff --git a/app/Http/Controllers/MediaController.php b/app/Http/Controllers/MediaController.php index c4265f4..9b51d3a 100644 --- a/app/Http/Controllers/MediaController.php +++ b/app/Http/Controllers/MediaController.php @@ -8,6 +8,7 @@ use Illuminate\Support\Facades\Auth; use Illuminate\Http\Request; use Illuminate\Support\Facades\Storage; use App\Models\Sujet; +use App\Models\Setting; use App\Models\Format; use App\Models\Media; use App\Models\Typemedia; @@ -23,6 +24,7 @@ use App\Models\Recherche; use App\Models\Historique; use App\Models\Panier; use App\Http\Traits\MediaTools; +use App\Models\FormatRestriction; class MediaController extends Controller { @@ -996,23 +998,76 @@ class MediaController extends Controller $largeur = $media->largeur; $hauteur = $media->hauteur; - //si on est sur un sujet arcadia (donc pas le sujet Groupe) + //on récupère les restrictions par défaut + $defaultwidth = Setting::where('key', 'default_size_restriction_width')->first(); + if(empty($defaultwidth->value)) { + $checkwidth = null; + } else { + $checkwidth = $defaultwidth->value; + } + + $defaultheight = Setting::where('key', 'default_size_restriction_height')->first(); + if(empty($defaultheight->value)) { + $checkheight = null; + } else { + $checkheight = $defaultheight->value; + } + + $defaultmime = Setting::where('key', 'default_mime_restriction')->first(); + if(empty($defaultmime->value)) { + $checkmime = array(); + } else { + $checkmime = explode(',', $defaultmime->value); + } + + //si on est sur un sujet arcadia (donc pas le sujet Groupe par exemple) if ($media->sujet->sujet_arcadia) { //le check est requis - $doCheck = true; - //cas d'exclusion BAT - if ($type_vue == 19) { - $doCheck = false; + $format_restriction = FormatRestriction::query(); + $format_restriction = $format_restriction->selectRaw( + '*,(CASE WHEN ISNULL(sujet_id) THEN 0 ELSE 3 END) + (CASE WHEN ISNULL(typevues_id) THEN 0 ELSE 2 END) + (CASE WHEN ISNULL(typemedias_id) THEN 0 ELSE 1 END) AS wght') + ->where( + function ($q) use ($code_sujet) { + $q->where('sujet_id', $code_sujet) + ->orWhereNull('sujet_id'); + }) + ->where( + function ($q) use ($type_vue) { + $q->where('typevues_id', $type_vue) + ->orWhereNull('typevues_id'); + }) + ->where( + function ($q) use ($type_media) { + $q->where('typemedias_id', $type_media) + ->orWhereNull('typemedias_id'); + }) + ->orderBy('wght', 'DESC'); + + $format_restriction = $format_restriction->first(); + + if(!$format_restriction) { + //aucune nouvelle restriction trouvée + } else { + $checkwidth = $format_restriction->in_width; + $checkheight = $format_restriction->in_height; + if(empty($format_restriction->in_mimes)) { + $checkmime = array(); + } else { + $checkmime = explode(',', $format_restriction->in_mimes); + } + } - if ($type_media == 6) { - $doCheck = false; - } - } - if ($doCheck) { - if ($extension == 'png') { - if ($largeur == 1800) { - if ($hauteur == 1800) { - //ok + + //vérification du mime + if(in_array($extension, $checkmime) || empty($checkmime)) { + //pass + //verification de la largeur + if($largeur == $checkwidth || is_null($checkwidth)) { + //pass + //vérification hauteur + if($hauteur == $checkheight || is_null($checkheight)) { + //pass + //tout est OK } else { //fail hauteur return json_encode(array('status' => false, 'error' => "Les dimensions requises sont 1800px par 1800px, veuillez charger un autre média")); @@ -1023,7 +1078,7 @@ class MediaController extends Controller } } else { //fail type de fichier - return json_encode(array('status' => false, 'error' => "Le type de fichier doit être PNG, veuillez charger un autre média")); + return json_encode(array('status' => false, 'error' => "Le type de fichier doit être ". implode(', ', $checkmime) .", veuillez charger un autre média")); } }