107 lines
3.3 KiB
PHP
107 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Enums\OCBType;
|
|
use App\Models\OCBBreeder;
|
|
use App\Models\OCBContent;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class OCBController extends Controller
|
|
{
|
|
/**
|
|
* Show obc breeders testimonials
|
|
*
|
|
* @return \Illuminate\Contracts\View\View|\Illuminate\Contracts\View\Factory
|
|
*/
|
|
public function testimonials()
|
|
{
|
|
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);
|
|
|
|
return view('front.ocb.testimonials', compact('breeders'));
|
|
}
|
|
|
|
/**
|
|
* View specific ocb breeder
|
|
*
|
|
* @param OCBBreeder $breeder
|
|
* @return \Illuminate\Contracts\View\View|\Illuminate\Contracts\View\Factory
|
|
*/
|
|
public function breeder(OCBBreeder $breeder)
|
|
{
|
|
if (!$breeder->status) {
|
|
abort(404);
|
|
}
|
|
// Contient les images de l'exploitation de l'éleveur.
|
|
$pictures = [];
|
|
if ($breeder->site !== null && $breeder->site->presentation_type === 2) {
|
|
if ($breeder->site->picture1 !== null) {
|
|
$pictures[] = $breeder->site->picture1;
|
|
}
|
|
if ($breeder->site->picture2 !== null) {
|
|
$pictures[] = $breeder->site->picture2;
|
|
}
|
|
if ($breeder->site->picture3 !== null) {
|
|
$pictures[] = $breeder->site->picture3;
|
|
}
|
|
}
|
|
|
|
return view('front.ocb.breeder', compact('breeder', 'pictures'));
|
|
}
|
|
|
|
/**
|
|
* Show ocb poultry content
|
|
*
|
|
* @return \Illuminate\Contracts\View\View|\Illuminate\Contracts\View\Factory
|
|
*/
|
|
public function poultry()
|
|
{
|
|
$ocbContents = OCBContent::where('type', OCBType::poultry())
|
|
->where('status', true)
|
|
->orderBy('order')
|
|
->get();
|
|
$breeder = OCBBreeder::ocbValidated()->where('status', true)
|
|
->inRandomOrder()->first();
|
|
return view('front.ocb.poultry', compact('breeder', 'ocbContents'));
|
|
}
|
|
|
|
/**
|
|
* Show ocb rabbit content
|
|
*
|
|
* @return \Illuminate\Contracts\View\View|\Illuminate\Contracts\View\Factory
|
|
*/
|
|
public function rabbit()
|
|
{
|
|
$ocbContents = OCBContent::where('type', OCBType::rabbit())
|
|
->where('status', true)
|
|
->orderBy('order')
|
|
->get();
|
|
return view('front.ocb.rabbit', compact('ocbContents'));
|
|
}
|
|
|
|
/**
|
|
* Show ocb egg content
|
|
*
|
|
* @return \Illuminate\Contracts\View\View|\Illuminate\Contracts\View\Factory
|
|
*/
|
|
public function egg()
|
|
{
|
|
$ocbContents = OCBContent::where('type', OCBType::egg())
|
|
->orderBy('order')
|
|
->where('status', true)->get();
|
|
return view('front.ocb.egg', compact('ocbContents'));
|
|
}
|
|
}
|