ldc-mesbr-app/app/Traits/LogTrait.php

98 lines
2.6 KiB
PHP
Raw Permalink Normal View History

2025-08-14 17:05:09 +02:00
<?php
namespace App\Traits;
use App\Models\Log;
2025-08-14 17:05:09 +02:00
trait LogTrait
{
/**
* Write error log when the campaign doesn't exist or isn't a basket.
*
* @param string $refcamp
* @return void
*/
public function writeLogErrorIncorrectCampaign(string $refcamp)
{
$log = new Log();
$log->log_action = $this->logAction->value;
$log->log_source = $this->logSource;
$log->log_params = json_encode(['refcamp' => $refcamp]);
$log->log_statut = 'NOK';
$log->log_message = "La campagne n'existe pas ou n'est pas un panier";
$log->save();
}
/**
* Write error log when there's a wrong or missing parameter in the request.
*
* @param string|null $refcamp
* @param string|null $refadherent
* @param string|null $refsite
* @param string|null $panier
2025-08-14 17:05:09 +02:00
* @return void
*/
public function writeLogErrorWrongRequestParameters(
$refcamp,
$refadherent,
$refsite,
$panier
2025-08-14 17:05:09 +02:00
) {
$log = new Log();
$log->log_action = $this->logAction->value;
$log->log_source = $this->logSource;
$log->log_params = json_encode([
'refcamp' => $refcamp ?? 'NO DATA',
'refadherent' => $refadherent ?? 'NO DATA',
'refsite' => $refsite ?? 'NO DATA',
'panier' => $panier ?? 'NO DATA'
2025-08-14 17:05:09 +02:00
]);
$log->log_statut = 'NOK';
$log->log_message = "Des paramètres de la requête sont mal renseignés ou non présents";
$log->save();
}
/**
* Write success log when the basket is created or updated.
*
* @param string $refcamp
* @param string $refadherent
* @param string $refsite
* @param string $panier
* @param array $panierCoupons
* @return void
*/
public function writeLogSuccessBasketCreated(
string $refcamp,
string $refadherent,
string $refsite,
string $panier,
array $panierCoupons
) {
$log = new Log();
$log->log_action = $this->logAction->value;
$log->log_source = $this->logSource;
$log->log_params = json_encode([
'refcamp' => $refcamp,
'refadherent' => $refadherent,
'refsite' => $refsite,
'panier' => $panier
]);
$log->log_refsite = $refsite;
$log->log_statut = 'OK';
$log->log_message = json_encode(
['Message' => 'Le panier a bien été créé/mis à jour', 'Coupons' => $panierCoupons],
JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES
);
$log->save();
}
}