2024-01-10 14:49:46 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Fo;
|
|
|
|
|
|
2024-04-19 17:03:25 +02:00
|
|
|
use App\Enums\Settings\SettingsType;
|
2024-07-10 17:10:33 +02:00
|
|
|
use App\Enums\StaticPageType;
|
2024-01-10 14:49:46 +01:00
|
|
|
use App\Http\Controllers\Controller;
|
2024-04-10 15:18:22 +02:00
|
|
|
use App\Http\Requests\Fo\SingleOptinRequest;
|
2024-04-12 12:15:18 +02:00
|
|
|
use App\Models\DemarcheSlide;
|
2024-04-04 13:00:12 +02:00
|
|
|
use App\Models\MainSlide;
|
2024-04-19 10:08:36 +02:00
|
|
|
use App\Models\Product;
|
2024-04-19 17:03:25 +02:00
|
|
|
use App\Models\GeneralSetting;
|
2024-08-30 16:09:01 +02:00
|
|
|
use App\Models\News;
|
2024-06-17 16:50:56 +02:00
|
|
|
use App\Models\Range;
|
2024-05-16 14:06:45 +02:00
|
|
|
use App\Models\Recipe;
|
2024-07-10 17:10:33 +02:00
|
|
|
use App\Models\StaticPage;
|
2024-05-27 17:29:42 +02:00
|
|
|
use App\Models\Video;
|
2024-04-19 17:03:25 +02:00
|
|
|
use Illuminate\Support\Facades\Cache;
|
2024-04-10 16:31:20 +02:00
|
|
|
use LDC\LDCCRM\Enums\ApiError;
|
|
|
|
|
use LDC\LDCCRM\Exceptions\ApiErrorException;
|
|
|
|
|
use LDC\LDCCRM\Exceptions\CrmException;
|
|
|
|
|
use LDC\LDCCRM\Models\SingleOptin;
|
2024-07-03 15:40:13 +02:00
|
|
|
use stdClass;
|
2024-01-10 14:49:46 +01:00
|
|
|
|
|
|
|
|
class HomeController extends Controller
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Display a listing of the resource.
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Contracts\View\View
|
|
|
|
|
*/
|
|
|
|
|
public function index(): \Illuminate\Contracts\View\View
|
|
|
|
|
{
|
2024-07-10 17:10:33 +02:00
|
|
|
$staticPageModel = StaticPage::query()->where('type', StaticPageType::home)->first();
|
2024-08-30 16:09:01 +02:00
|
|
|
$mainSlideModels = MainSlide::query()->where('published', true)->orderBy('order', 'ASC')->with('approach')->get();
|
2024-04-12 12:15:18 +02:00
|
|
|
$demarcheSlideModels = DemarcheSlide::query()->where('published', true)->orderBy('order', 'ASC')->get();
|
2024-06-17 16:50:56 +02:00
|
|
|
$rangeModels = Range::query()->where('published', true)->orderBy('slug', 'ASC')->get();
|
2024-04-19 10:08:36 +02:00
|
|
|
$productViews = Product::getProductsViewsByRange();
|
2024-04-19 17:03:25 +02:00
|
|
|
$hotNewsSettings = GeneralSetting::query()->where('type', SettingsType::hotNews)->first();
|
2024-08-30 16:09:01 +02:00
|
|
|
$newsModels = News::query()->where('published', true)->with('newsCategory')->get();
|
|
|
|
|
$recipeModels = Recipe::query()->where('published', true)->with([
|
2024-05-16 14:06:45 +02:00
|
|
|
'products',
|
2024-06-13 16:57:37 +02:00
|
|
|
'products.meat',
|
|
|
|
|
'products.submeat',
|
2024-05-16 14:06:45 +02:00
|
|
|
'consumptionMoment'
|
|
|
|
|
])->limit(9)->get();
|
2024-06-17 16:50:56 +02:00
|
|
|
$videoModels = Video::query()->where('published', true)->where('is_on_homepage', true)
|
|
|
|
|
->orderBy('order', 'ASC')->with('product')->limit(9)->get();
|
2024-04-11 14:17:06 +02:00
|
|
|
return view('fo.pages.home', compact(
|
2024-07-10 17:10:33 +02:00
|
|
|
'staticPageModel',
|
2024-04-11 14:17:06 +02:00
|
|
|
'mainSlideModels',
|
2024-06-17 16:50:56 +02:00
|
|
|
'rangeModels',
|
2024-04-12 12:15:18 +02:00
|
|
|
'demarcheSlideModels',
|
2024-04-11 14:17:06 +02:00
|
|
|
'productViews',
|
|
|
|
|
'newsModels',
|
2024-04-19 17:03:25 +02:00
|
|
|
'recipeModels',
|
2024-05-27 17:29:42 +02:00
|
|
|
'hotNewsSettings',
|
|
|
|
|
'videoModels'
|
2024-04-11 14:17:06 +02:00
|
|
|
));
|
2024-04-10 15:18:22 +02:00
|
|
|
}
|
|
|
|
|
|
2024-04-10 16:31:20 +02:00
|
|
|
/**
|
|
|
|
|
* Call the CRM to add a single optin
|
|
|
|
|
*
|
|
|
|
|
* @param \App\Http\Requests\Fo\SingleOptinRequest $request
|
|
|
|
|
* @return string|array|null|\Illuminate\Contracts\Translation\Translator
|
|
|
|
|
* @throws \LDC\LDCCRM\Exceptions\ValidationException ValidationException.
|
|
|
|
|
* @throws \Illuminate\Contracts\Container\BindingResolutionException BindingResolutionException.
|
|
|
|
|
*/
|
|
|
|
|
public function addOptIn(SingleOptinRequest $request)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
SingleOptin::setStatus($request->email, true);
|
|
|
|
|
return \response(trans("Votre inscription à la newsletter a été prise en compte"), 200);
|
|
|
|
|
} catch (ApiErrorException $e) {
|
|
|
|
|
// Il y a deja un customerInfo avec optin a true pour ce customer.
|
|
|
|
|
if ($e->getApiError()->equals(ApiError::singleOptinCustomerExists())) {
|
|
|
|
|
return trans('Vous êtes déjà inscrit avec cette adresse email');
|
|
|
|
|
}
|
2024-04-18 15:35:30 +02:00
|
|
|
\report($e);
|
2024-04-10 16:31:20 +02:00
|
|
|
return \response(trans('Une erreur est survenue, merci de réessayer ultérieurement'), 404);
|
|
|
|
|
} catch (CrmException $e) {
|
2024-04-18 15:35:30 +02:00
|
|
|
\report($e);
|
2024-04-10 16:31:20 +02:00
|
|
|
return \response(trans('Une erreur est survenue, merci de réessayer ultérieurement'), 404);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-04-19 17:03:25 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Display a listing of the resource.
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Http\JsonResponse
|
|
|
|
|
*/
|
|
|
|
|
public function updateHotNewsSatus(): \Illuminate\Http\JsonResponse
|
|
|
|
|
{
|
2024-04-26 09:29:39 +02:00
|
|
|
Cache::put('hotNewsIsDisplayed', true, now()->addHours(24));
|
2024-04-19 17:03:25 +02:00
|
|
|
return response()->json();
|
|
|
|
|
}
|
2024-01-10 14:49:46 +01:00
|
|
|
}
|