src/Entity/OffreAccueil/PreferencesPublicationMAM.php line 142

Open in your IDE?
  1. <?php
  2. namespace App\Entity\OffreAccueil;
  3. use App\Entity\MAM\MAM;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use JsonSerializable;
  6. use Symfony\Component\Validator\Constraints as Assert;
  7. /**
  8.  * @ORM\Entity
  9.  * @ORM\Table(name="efc.oa_preferences_publication_mam")
  10.  */
  11. class PreferencesPublicationMAM implements JsonSerializable
  12. {
  13.     use \App\Entity\Commun\IdTrait;
  14.     /**
  15.      * @Assert\NotNull()
  16.      * @ORM\OneToOne(targetEntity="App\Entity\MAM\MAM", inversedBy="preferences_publication")
  17.      * @ORM\JoinColumn(name="id_mam", referencedColumnName="id", nullable=false)
  18.      */
  19.     private $mam;
  20.     /**
  21.      * @ORM\Column(type="boolean", nullable=true, options={"default":null})
  22.      */
  23.     private $publi_tel_fixe;
  24.     /**
  25.      * @ORM\Column(type="boolean", nullable=true, options={"default":null})
  26.      */
  27.     private $publi_tel_portable;
  28.     /**
  29.      * @ORM\Column(type="boolean", nullable=true, options={"default":null})
  30.      */
  31.     private $publi_email;
  32.     use \App\Entity\Commun\DateCreationTrait;
  33.     use \App\Entity\Commun\DateModificationTrait;
  34.     /**
  35.      * Get mam
  36.      *
  37.      * @return MAM
  38.      */
  39.     public function getMAM()
  40.     {
  41.         return $this->mam;
  42.     }
  43.     /**
  44.      * Set mam
  45.      *
  46.      * @param MAM $mam
  47.      * 
  48.      * @return PreferencesPublicationMAM
  49.      */
  50.     public function setMAM($mam)
  51.     {
  52.         $this->mam $mam;
  53.         return $this;
  54.     }
  55.     /**
  56.      * Get publi_tel_fixe
  57.      *
  58.      * @return boolean
  59.      */
  60.     public function getPubliTelFixe()
  61.     {
  62.         return $this->publi_tel_fixe;
  63.     }
  64.     /**
  65.      * Set publi_tel_fixe
  66.      *
  67.      * @param boolean $publi_tel_fixe
  68.      * 
  69.      * @return PreferencesPublicationMAM
  70.      */
  71.     public function setPubliTelFixe(bool $publi_tel_fixe)
  72.     {
  73.         $this->publi_tel_fixe $publi_tel_fixe;
  74.         return $this;
  75.     }
  76.     /**
  77.      * Get publi_tel_portable
  78.      *
  79.      * @return boolean
  80.      */
  81.     public function getPubliTelPortable()
  82.     {
  83.         return $this->publi_tel_portable;
  84.     }
  85.     /**
  86.      * Set publi_tel_portable
  87.      *
  88.      * @param boolean $publi_tel_portable
  89.      * 
  90.      * @return PreferencesPublicationMAM
  91.      */
  92.     public function setPubliTelPortable(bool $publi_tel_portable)
  93.     {
  94.         $this->publi_tel_portable $publi_tel_portable;
  95.         return $this;
  96.     }
  97.     /**
  98.      * Get publi_email
  99.      *
  100.      * @return boolean
  101.      */
  102.     public function getPubliEmail()
  103.     {
  104.         return $this->publi_email;
  105.     }
  106.     /**
  107.      * Set publi_email
  108.      *
  109.      * @param boolean $publi_email
  110.      * 
  111.      * @return PreferencesPublicationMAM
  112.      */
  113.     public function setPubliEmail(bool $publi_email)
  114.     {
  115.         $this->publi_email $publi_email;
  116.         return $this;
  117.     }
  118.     /*
  119.      * Implémentation de JsonSerializable
  120.      * Ne liste que les champs modifiables par les utilisateurs
  121.      */
  122.     public function jsonSerialize()
  123.     {
  124.         return [
  125.             'publi_email' => $this->publi_email,
  126.             'publi_tel_fixe' => $this->publi_tel_fixe,
  127.             'publi_tel_portable' => $this->publi_tel_portable,
  128.         ];
  129.     }
  130.     /**
  131.      * Obtient une nouvelle instance de PreferencesPublication, initialisée à partir du tableau associatif fourni en paramètre
  132.      *
  133.      * @param array $data
  134.      * @return PreferencesPublication
  135.      */
  136.     public static function createFromArray(array $data)
  137.     {
  138.         $newInstance = new PreferencesPublicationMAM();
  139.         return $newInstance->initFromArray($data);
  140.     }
  141.     public static function createFromMAM(MAM $mam): PreferencesPublicationMAM
  142.     {
  143.         $pref = new PreferencesPublicationMAM();
  144.         $pref->setMAM($mam);
  145.         // Afficher les infos si mam n'est pas opposé
  146.         $defaut = !$mam->getOppose();
  147.         $pref->setPubliEmail($defaut);
  148.         $pref->setPubliTelFixe($defaut);
  149.         $pref->setPubliTelPortable($defaut);
  150.         return $pref;
  151.     }
  152.     /**
  153.      * mappe les propriétés sur l'instance à partir d'un tableau associatif
  154.      *
  155.      * @param array $data
  156.      * @return void
  157.      */
  158.     public function initFromArray(array $data)
  159.     {
  160.         foreach ($data as $prop => $value) {
  161.             $this->{$prop} = $value;
  162.         }
  163.         return $this;
  164.     }
  165. }