ldc-legaulois/app/Models/MailContactData.php

183 lines
6.5 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.
*
* @property \App\Enums\ContactFormCivility $civility Picto path.
* @property string $lastname Picto title attribute.
* @property string $firstname Picto alt attribute.
* @property string $address Legend of picto.
* @property string $email The origin of the text.
* @property string $postal Change order request.
* @property string $town Picto publish status.
* @property integer $phone Picto publish status.
* @property \App\Enums\ContactFormType $type Picto publish status.
* @property string $message Picto publish status.
* @property string $joinFile Picto publish status.
* @property string $productName Picto publish status.
* @property string $productCode Picto publish status.
* @property string $buyPlace Picto publish status.
* @property string $lotNumberName Picto publish status.
* @property string $limitDateDay Picto publish status.
* @property string $limitDateMonth Picto publish status.
* @property string $limitDateYear Picto publish status.
* @property string $consumptionDateDay Picto publish status.
* @property string $consumptionDateMonth Picto publish status.
* @property string $consumptionDateYear Picto publish status.
* @property-read \Illuminate\Support\Carbon $created_at Created date.
* @property-read \Illuminate\Support\Carbon $updated_at Updated date.
*/
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<int, string>
*/
protected $fillable = [
'civility',
'lastname',
'firstname',
'address',
'email',
'postal',
'town',
'phone',
'type',
'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->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 [
// Le Gaulois brand.
'EMETTEUR_MARQUE' => 1,
'EMETTEUR_DATE' => date("Y-m-d"),
'EMETTEUR_HEURE' => date("h:i:s"),
'EMETTEUR_CIVILITE' => $this->civility->value,
// Limited at 50 characters.
'EMETTEUR_NOM' => Str::limit($this->lastname, 50, ''),
'EMETTEUR_PRENOM' => $this->firstname,
'EMETTEUR_ADRESSE1' => $this->address,
'EMETTEUR_ADRESSE2' => '',
'EMETTEUR_CP' => $this->postal,
'EMETTEUR_VILLE' => $this->town,
'EMETTEUR_EMAIL' => $this->email,
'EMETTEUR_TELEPHONE' => $this->phone,
'EMETTEUR_PAYS' => 'France',
'EMETTEUR_NOM_PRODUIT' => $this->productName,
'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->message,
'EMETTEUR_PJ' => $this->joinFile,
'DATE_CONSO' => sprintf(
'%s/%s/%s',
$this->consumptionDateDay ?? '00',
$this->consumptionDateMonth ?? '00',
$this->consumptionDateYear ?? '0000'
),
'LIEU_ACHAT' => $this->buyPlace,
'EMETTEUR_OBJETDEMANDE' => 3,
'EMETTEUR_OPT_IN' => '',
'REPONSE_ETAT' => 0,
'TYPE_REPONSE' => 'mail'
];
}
}