2021-01-05 14:51:15 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
2021-04-02 17:18:43 +02:00
|
|
|
use App\Enums\OCBType;
|
2021-04-08 20:06:14 +02:00
|
|
|
use App\Models\OCBBreeder;
|
2021-04-26 15:44:00 +02:00
|
|
|
use App\Models\OCBContent;
|
2021-04-09 17:26:26 +02:00
|
|
|
use Illuminate\Support\Facades\DB;
|
2021-01-05 14:51:15 +01:00
|
|
|
|
|
|
|
|
class OCBController extends Controller
|
|
|
|
|
{
|
2021-03-09 10:47:23 +01:00
|
|
|
public function testimonials()
|
|
|
|
|
{
|
2021-04-09 17:26:26 +02:00
|
|
|
if (
|
|
|
|
|
!session()->has('ocbtestimony.rand') ||
|
|
|
|
|
(intval(session()->get('ocbtestimony.time', time())) - intval(time())) > (60 * 60 * 60) // 1 hour
|
|
|
|
|
) {
|
|
|
|
|
session()->put('ocbtestimony.time', time());
|
|
|
|
|
session()->put('ocbtestimony.rand', DB::table(resolve(OCBBreeder::class)->getTable())
|
|
|
|
|
->select('id')->inRandomOrder()->get()->pluck('id')->toArray());
|
|
|
|
|
session()->save();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$breeders = OCBBreeder::ocbValidated()->where('status', true)
|
|
|
|
|
->select('slug', 'picture', 'first_name', 'last_name', 'testimony')
|
|
|
|
|
->orderByRaw(\sprintf('FIELD(id, %s)', implode(", ", session()->get('ocbtestimony.rand'))))
|
|
|
|
|
->paginate(8);
|
2021-01-29 12:17:47 +01:00
|
|
|
|
|
|
|
|
return view('front.ocb.testimonials', compact('breeders'));
|
2021-01-05 14:51:15 +01:00
|
|
|
}
|
|
|
|
|
|
2021-04-08 20:06:14 +02:00
|
|
|
public function breeder(OCBBreeder $breeder)
|
2021-03-09 10:00:35 +01:00
|
|
|
{
|
2021-04-26 15:44:00 +02:00
|
|
|
if (!$breeder->status) {
|
2021-04-15 11:50:07 +02:00
|
|
|
abort(404);
|
|
|
|
|
}
|
2021-01-08 14:00:22 +01:00
|
|
|
// Contient les images de l'exploitation de l'éleveur
|
|
|
|
|
$pictures = [];
|
2021-02-16 17:32:51 +01:00
|
|
|
if ($breeder->site !== null && $breeder->site->presentation_type === 2) {
|
2021-03-20 14:38:15 +01:00
|
|
|
if ($breeder->site->picture1 !== null) {
|
2021-01-08 14:00:22 +01:00
|
|
|
$pictures[] = $breeder->site->picture1;
|
2021-03-20 14:38:15 +01:00
|
|
|
}
|
|
|
|
|
if ($breeder->site->picture2 !== null) {
|
2021-01-08 14:00:22 +01:00
|
|
|
$pictures[] = $breeder->site->picture2;
|
2021-03-20 14:38:15 +01:00
|
|
|
}
|
|
|
|
|
if ($breeder->site->picture3 !== null) {
|
2021-01-08 14:00:22 +01:00
|
|
|
$pictures[] = $breeder->site->picture3;
|
2021-03-20 14:38:15 +01:00
|
|
|
}
|
2021-01-08 14:00:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return view('front.ocb.breeder', compact('breeder', 'pictures'));
|
2021-01-05 14:51:15 +01:00
|
|
|
}
|
2021-01-12 14:36:45 +01:00
|
|
|
|
2021-03-09 10:47:23 +01:00
|
|
|
public function poultry()
|
|
|
|
|
{
|
2021-04-28 13:57:12 +02:00
|
|
|
$ocbContents = OCBContent::where('type', OCBType::poultry())
|
|
|
|
|
->where('status', true)
|
|
|
|
|
->orderBy('order')
|
|
|
|
|
->get();
|
2021-04-09 17:26:26 +02:00
|
|
|
$breeder = OCBBreeder::ocbValidated()->where('status', true)
|
|
|
|
|
->inRandomOrder()->first();
|
2021-05-02 14:34:39 +02:00
|
|
|
return view('front.ocb.poultry', compact('breeder', 'ocbContents'));
|
2021-04-26 15:44:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function egg()
|
|
|
|
|
{
|
2021-04-28 13:57:12 +02:00
|
|
|
$ocbContents = OCBContent::where('type', OCBType::egg())
|
|
|
|
|
->orderBy('order')
|
|
|
|
|
->where('status', true)->get();
|
2021-04-26 15:44:00 +02:00
|
|
|
return view('front.ocb.egg', compact('ocbContents'));
|
2021-01-12 14:36:45 +01:00
|
|
|
}
|
2021-01-05 14:51:15 +01:00
|
|
|
}
|