ldc-legaulois/app/Models/MailContactData.php
2021-02-15 17:48:49 +01:00

140 lines
3.9 KiB
PHP

<?php
namespace App\Models;
use App\Enums\ContactFormCivility;
use App\Enums\ContactFormType;
use App\Traits\CastsEnums;
use Illuminate\Database\Eloquent\Model;
/**
* This class is used to store data in memory only, not in databases
*/
class MailContactData extends Model
{
use CastsEnums;
protected $enumCasts = [
'type' => ContactFormType::class,
'civility' => ContactFormCivility::class
];
/**
* The database connection that should be used by the model.
*
* @var string
*/
protected $connection = null;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'civility',
'lastname',
'firstname',
'address',
'email',
'postal',
'town',
'phone',
'type',
'message',
'joinFile',
'productName',
'productCode',
'buyPlace',
'lotNumberName',
'limitDateDay',
'limitDateMonth',
'limitDateYear',
'consumptionDateDay',
'consumptionDateMonth',
'consumptionDateYear'
];
protected $attributes = [
'productName' => '',
'productCode' => '',
'buyPlace' => '',
'lotNumberName' => 0,
'limitDateDay' => '00',
'limitDateMonth' => '00',
'limitDateYear' => '0000',
'consumptionDateDay' => '00',
'consumptionDateMonth' => '00',
'consumptionDateYear' => '0000',
];
/**
* Export the model data to a Formatted Arcadia Data array
*
* @return array
*/
public function exportToArcadiaDataArray(): array
{
return [
date("Ymd"),
date("Gis"),
$this->civility->label,
$this->lastname,
$this->firstname,
$this->address,
$this->postal,
$this->town,
$this->email,
$this->type->label,
$this->message,
'0', '0', '0', '0'
];
}
/**
* Export the model data to a Formatted Arcadia Data array
*
* @return array
*/
public function exportToPasserelleDataArray(): array
{
// CF PAsserrelle fields .csv
return [
'EMETTEUR_MARQUE' => 1, // Marque le Gaulois (Obligatoire)
'EMETTEUR_DATE' => date("Ymd"), // (Obligatoire)
'EMETTEUR_HEURE' => date("Gis"), // (Obligatoire)
'EMETTEUR_CIVILITE' => $this->civility,
'EMETTEUR_NOM' => $this->lastname, // (Obligatoire)
'EMETTEUR_PRENOM' => $this->firstname, // (Obligatoire)
'EMETTEUR_ADRESSE1' => $this->address,
'EMETTEUR_ADRESSE2' => '',
'EMETTEUR_CP' => $this->postal,
'EMETTEUR_VILLE' => $this->town, // (Obligatoire)
'EMETTEUR_EMAIL' => $this->email,
'EMETTEUR_TELEPHONE' => $this->phone,
'EMETTEUR_PAYS' => 'France',
'EMETTEUR_NOM_PRODUIT' => $this->productName,
'EMETTEUR_EAN13' => $this->productCode, // (Obligatoire)
'EMETTEUR_DATE_LIMITE_CONSO' => sprintf(
'%s/%s/%s',
$this->limitDateDay ?? '00',
$this->limitDateMonth ?? '00',
$this->limitDateYear ?? '0000'
),
'EMETTEUR_NUM_LOT' => $this->lotNumberName,
'EMETTEUR_MESSAGE' => $this->message,
'EMETTEUR_PJ' => $this->joinFile,
// 'EMETTEUR_OBJETDEMANDE' => "objet de la reclamation string",
// 'EMETTEUR_OPT_IN' => '',
// 'REPONSE_ETAT' => 0,
// 'TYPE_REPONSE' => 'mail',
'DATE_CONSO' => sprintf(
'%s/%s/%s',
$this->consumptionDateDay ?? '00',
$this->consumptionDateMonth ?? '00',
$this->consumptionDateYear ?? '0000'
),
'LIEU_ACHAT' => $this->buyPlace
];
}
}