<?php
namespace App\Entity\OffreAccueil;
use App\Entity\MAM\MAM;
use Doctrine\ORM\Mapping as ORM;
use JsonSerializable;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity
* @ORM\Table(name="efc.oa_preferences_publication_mam")
*/
class PreferencesPublicationMAM implements JsonSerializable
{
use \App\Entity\Commun\IdTrait;
/**
* @Assert\NotNull()
* @ORM\OneToOne(targetEntity="App\Entity\MAM\MAM", inversedBy="preferences_publication")
* @ORM\JoinColumn(name="id_mam", referencedColumnName="id", nullable=false)
*/
private $mam;
/**
* @ORM\Column(type="boolean", nullable=true, options={"default":null})
*/
private $publi_tel_fixe;
/**
* @ORM\Column(type="boolean", nullable=true, options={"default":null})
*/
private $publi_tel_portable;
/**
* @ORM\Column(type="boolean", nullable=true, options={"default":null})
*/
private $publi_email;
use \App\Entity\Commun\DateCreationTrait;
use \App\Entity\Commun\DateModificationTrait;
/**
* Get mam
*
* @return MAM
*/
public function getMAM()
{
return $this->mam;
}
/**
* Set mam
*
* @param MAM $mam
*
* @return PreferencesPublicationMAM
*/
public function setMAM($mam)
{
$this->mam = $mam;
return $this;
}
/**
* Get publi_tel_fixe
*
* @return boolean
*/
public function getPubliTelFixe()
{
return $this->publi_tel_fixe;
}
/**
* Set publi_tel_fixe
*
* @param boolean $publi_tel_fixe
*
* @return PreferencesPublicationMAM
*/
public function setPubliTelFixe(bool $publi_tel_fixe)
{
$this->publi_tel_fixe = $publi_tel_fixe;
return $this;
}
/**
* Get publi_tel_portable
*
* @return boolean
*/
public function getPubliTelPortable()
{
return $this->publi_tel_portable;
}
/**
* Set publi_tel_portable
*
* @param boolean $publi_tel_portable
*
* @return PreferencesPublicationMAM
*/
public function setPubliTelPortable(bool $publi_tel_portable)
{
$this->publi_tel_portable = $publi_tel_portable;
return $this;
}
/**
* Get publi_email
*
* @return boolean
*/
public function getPubliEmail()
{
return $this->publi_email;
}
/**
* Set publi_email
*
* @param boolean $publi_email
*
* @return PreferencesPublicationMAM
*/
public function setPubliEmail(bool $publi_email)
{
$this->publi_email = $publi_email;
return $this;
}
/*
* Implémentation de JsonSerializable
* Ne liste que les champs modifiables par les utilisateurs
*/
public function jsonSerialize()
{
return [
'publi_email' => $this->publi_email,
'publi_tel_fixe' => $this->publi_tel_fixe,
'publi_tel_portable' => $this->publi_tel_portable,
];
}
/**
* Obtient une nouvelle instance de PreferencesPublication, initialisée à partir du tableau associatif fourni en paramètre
*
* @param array $data
* @return PreferencesPublication
*/
public static function createFromArray(array $data)
{
$newInstance = new PreferencesPublicationMAM();
return $newInstance->initFromArray($data);
}
public static function createFromMAM(MAM $mam): PreferencesPublicationMAM
{
$pref = new PreferencesPublicationMAM();
$pref->setMAM($mam);
// Afficher les infos si mam n'est pas opposé
$defaut = !$mam->getOppose();
$pref->setPubliEmail($defaut);
$pref->setPubliTelFixe($defaut);
$pref->setPubliTelPortable($defaut);
return $pref;
}
/**
* mappe les propriétés sur l'instance à partir d'un tableau associatif
*
* @param array $data
* @return void
*/
public function initFromArray(array $data)
{
foreach ($data as $prop => $value) {
$this->{$prop} = $value;
}
return $this;
}
}