174 lines
4.8 KiB
PHP
174 lines
4.8 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\ContactFormCivility;
|
|
use App\Enums\ContactFormType;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Support\Str;
|
|
|
|
/**
|
|
* This class is used to store data in memory only, not in databases
|
|
*/
|
|
class MailContactData extends Model
|
|
{
|
|
/**
|
|
* 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',
|
|
'onepagesubject',
|
|
'message',
|
|
'joinFile',
|
|
'productName',
|
|
'productCode',
|
|
'buyPlace',
|
|
'lotNumberName',
|
|
'limitDateDay',
|
|
'limitDateMonth',
|
|
'limitDateYear',
|
|
'consumptionDateDay',
|
|
'consumptionDateMonth',
|
|
'consumptionDateYear'
|
|
];
|
|
|
|
/**
|
|
* The attributes that should be cast.
|
|
*
|
|
* @var array<string, string>
|
|
*/
|
|
protected $casts = [
|
|
'type' => ContactFormType::class,
|
|
'civility' => ContactFormCivility::class
|
|
];
|
|
|
|
|
|
/**
|
|
* The model's attributes.
|
|
*
|
|
* @var array
|
|
*/
|
|
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->value,
|
|
$this->lastname,
|
|
$this->firstname,
|
|
$this->address,
|
|
$this->postal,
|
|
$this->town,
|
|
$this->email,
|
|
$this->type->equals(ContactFormType::nl) ? $this->onepagesubject : $this->type->value,
|
|
$this->message,
|
|
'0',
|
|
'0',
|
|
'0',
|
|
'0'
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Export the model data to a Formatted Passerelle Data array
|
|
*
|
|
* * Removed
|
|
* 'EMETTEUR_OBJETDEMANDE' => "objet de la reclamation string",
|
|
* 'EMETTEUR_OPT_IN' => '',
|
|
* 'REPONSE_ETAT' => 0,
|
|
* 'TYPE_REPONSE' => 'mail',
|
|
*
|
|
* @return array
|
|
*/
|
|
public function exportToPasserelleDataArray(): array
|
|
{
|
|
// * CF PAsserrelle fields .csv
|
|
return [
|
|
// * Marque le Gaulois (Obligatoire)
|
|
'EMETTEUR_MARQUE' => 1,
|
|
// * Obligatoire
|
|
'EMETTEUR_DATE' => date("Y-m-d"),
|
|
// * Obligatoire
|
|
'EMETTEUR_HEURE' => date("h:i:s"),
|
|
'EMETTEUR_CIVILITE' => $this->civility->value,
|
|
// * Obligatoire Limité a 50
|
|
'EMETTEUR_NOM' => Str::limit($this->lastname, 50, ''),
|
|
// * Obligatoire
|
|
'EMETTEUR_PRENOM' => $this->firstname,
|
|
'EMETTEUR_ADRESSE1' => $this->address,
|
|
'EMETTEUR_ADRESSE2' => '',
|
|
'EMETTEUR_CP' => $this->postal,
|
|
// * Obligatoire
|
|
'EMETTEUR_VILLE' => $this->town,
|
|
'EMETTEUR_EMAIL' => $this->email,
|
|
'EMETTEUR_TELEPHONE' => $this->phone,
|
|
'EMETTEUR_PAYS' => 'France',
|
|
'EMETTEUR_NOM_PRODUIT' => $this->productName,
|
|
// * Obligatoire
|
|
'EMETTEUR_EAN13' => $this->productCode,
|
|
'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->type->equals(ContactFormType::nl) ?
|
|
sprintf('%s \n %s', $this->onepagesubject, $this->message) :
|
|
$this->message,
|
|
'EMETTEUR_PJ' => $this->joinFile,
|
|
'DATE_CONSO' => sprintf(
|
|
'%s/%s/%s',
|
|
$this->consumptionDateDay ?? '00',
|
|
$this->consumptionDateMonth ?? '00',
|
|
$this->consumptionDateYear ?? '0000'
|
|
),
|
|
'LIEU_ACHAT' => $this->buyPlace,
|
|
|
|
// * FUCK passerelle et leur DTD qui n'existe pas cf: resources/documents
|
|
// * Recla conso ?
|
|
'EMETTEUR_OBJETDEMANDE' => 3,
|
|
// * doit être vide ?
|
|
'EMETTEUR_OPT_IN' => '',
|
|
// * c'est quoi ça ?
|
|
'REPONSE_ETAT' => 0,
|
|
// * ok
|
|
'TYPE_REPONSE' => 'mail'
|
|
];
|
|
}
|
|
}
|