<?php
namespace App\Entity\OffreAccueil;
use \JsonSerializable;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity
* @ORM\Table(name="efc.oa_preferences_publication")
*/
class PreferencesPublication implements JsonSerializable
{
use \App\Entity\Commun\IdTrait;
/**
* @Assert\NotNull()
* @ORM\OneToOne(targetEntity="App\Entity\AssistantMaternel\AssistantMaternel", inversedBy="preferences_publication")
* @ORM\JoinColumn(name="id_assmat", referencedColumnName="id", nullable=false)
*/
private $assmat;
/**
* @ORM\Column(type="boolean", nullable=true, options={"default":null})
*/
private $publi_age;
/**
* @ORM\Column(type="boolean", nullable=true, options={"default":null})
*/
private $publi_enfants_assmat;
/**
* @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 assmat
*
* @return Assmat
*/
public function getAssmat()
{
return $this->assmat;
}
/**
* Set assmat
*
* @param Assmat $assmat
*
* @return PreferencesPublication
*/
public function setAssmat(\App\Entity\AssistantMaternel\AssistantMaternel $assmat)
{
$this->assmat = $assmat;
return $this;
}
/**
* Get publi_age
*
* @return boolean
*/
public function getPubliAge()
{
return $this->publi_age;
}
/**
* Set publi_age
*
* @param boolean $publi_age
*
* @return PreferencesPublication
*/
public function setPubliAge(bool $publi_age)
{
$this->publi_age = $publi_age;
return $this;
}
/**
* Get publi_enfants_assmat
*
* @return boolean
*/
public function getPubliEnfantsAssmat()
{
return $this->publi_enfants_assmat;
}
/**
* Set publi_enfants_assmat
*
* @param boolean $publi_enfants_assmat
*
* @return PreferencesPublication
*/
public function setPubliEnfantsAssmat(bool $publi_enfants_assmat)
{
$this->publi_enfants_assmat = $publi_enfants_assmat;
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 PreferencesPublication
*/
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 PreferencesPublication
*/
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 PreferencesPublication
*/
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_age' => $this->publi_age,
'publi_email' => $this->publi_email,
'publi_enfants_assmat' => $this->publi_enfants_assmat,
'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 PreferencesPublication();
return $newInstance->initFromArray($data);
}
public static function createFromAssmat(\App\Entity\AssistantMaternel\AssistantMaternel $assmat): PreferencesPublication
{
$pref = new PreferencesPublication();
$pref->setDateCreation(new \DateTime());
$pref->setAssmat($assmat);
// Afficher les infos si assmat n'est pas opposé
$defaut = !$assmat->getOppose();
$pref->setPubliAge($defaut);
$pref->setPubliEnfantsAssmat($defaut);
// Pour les téléphones, afficher infos si assmat n'est pas opposé ET n'est pas sur liste rouge
$pref->setPubliTelFixe($assmat->getPublieTelFixeEtendu());
$pref->setPubliTelPortable($assmat->getPublieTelPortableEtendu());
$pref->setPubliEmail($assmat->getPublieMailEtendu());
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;
}
}