<?php
namespace App\Entity;
use App\Repository\InfoSalarieRepository;
use Doctrine\ORM\Mapping as ORM;
use ParagonIE\Halite\Alerts\CannotPerformOperation;
use ParagonIE\Halite\Alerts\InvalidDigestLength;
use ParagonIE\Halite\Alerts\InvalidMessage;
use ParagonIE\Halite\Alerts\InvalidSignature;
use ParagonIE\Halite\Alerts\InvalidType;
use ParagonIE\Halite\KeyFactory;
use ParagonIE\HiddenString\HiddenString;
use ParagonIE\Halite\Symmetric\Crypto as Symmetric;
/**
* @ORM\Entity(repositoryClass=InfoSalarieRepository::class)
*/
class InfoSalarie
{
private $encryptionKey;
private $isDecrypted = false;
private $_error = [];
private $properties = array(
'tarif_jour',
'date_naissance',
'lieu_naissance',
'situation_familiale',
'nationalite',
'num_secu_sociale',
'num_conges_spectacle',
'num_carte_presse',
'num_carte_sejour',
'date_visite_medicale',
'statut_cadre',
'nb_enfant',
'iban',
);
function __construct($webPath)
{
if(''!==$webPath) $this->encryptionKey = KeyFactory::loadEncryptionKey($webPath.'/var/cache/encryption.key');
}
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="text", nullable=true)
*/
private ?string $tarif_jour;
private ?string $uncrypted_tarif_jour;
/**
* @ORM\Column(type="text", nullable=true)
*/
private ?string $type_salarie;
/**
* @ORM\Column(type="text", nullable=true)
*/
private ?string $date_naissance;
private ?string $uncrypted_date_naissance;
/**
* @ORM\Column(type="text", nullable=true)
*/
private ?string $lieu_naissance;
private ?string $uncrypted_lieu_naissance;
/**
* @ORM\Column(type="text", nullable=true)
*/
private ?string $situation_familiale;
private ?string $uncrypted_situation_familiale;
/**
* @ORM\Column(type="text", nullable=true)
*/
private ?string $nationalite;
private ?string $uncrypted_nationalite;
/**
* @ORM\Column(type="text", nullable=true)
*/
private ?string $num_secu_sociale;
private ?string $uncrypted_num_secu_sociale;
/**
* @ORM\Column(type="text", nullable=true)
*/
private ?string $num_conges_spectacle;
private ?string $uncrypted_num_conges_spectacle;
/**
* @ORM\Column(type="text", nullable=true)
*/
private ?string $num_carte_sejour;
private ?string $uncrypted_num_carte_sejour;
/**
* @ORM\Column(type="text", nullable=true)
*/
private ?string $num_carte_presse;
private ?string $uncrypted_num_carte_presse;
/**
* @ORM\Column(type="text", nullable=true)
*/
private ?string $date_visite_medicale;
private ?string $uncrypted_date_visite_medicale;
/**
* @ORM\Column(type="text", nullable=true)
*/
private ?string $statut_cadre;
private ?string $uncrypted_statut_cadre;
/**
* @ORM\Column(type="text", nullable=true)
*/
private ?string $nb_enfant;
private ?string $uncrypted_nb_enfant;
/**
* @ORM\Column(type="text", nullable=true)
*/
private ?string $iban;
private ?string $uncrypted_iban;
/**
* @ORM\Column(type="text", nullable=true)
*/
private ?string $fonction;
/**
* @ORM\Column(type="datetime", options={"default": "CURRENT_TIMESTAMP"})
*/
private $date_modif;
/**
* @ORM\Column(type="integer", options={"default": "0"})
*/
private $user_modif;
/**
* @ORM\OneToOne(targetEntity=Tiers::class, mappedBy="info_salarie", cascade={"persist", "remove"})
*/
private $tiers;
/**
* @ORM\Column(type="datetime", options={"default": "CURRENT_TIMESTAMP"})
*/
private $date_crea;
/**
* @ORM\Column(type="integer", options={"default": "0"})
*/
private $user_crea;
public function getId(): ?int
{
return $this->id;
}
public function getTarifJour(): ?string
{
return $this->tarif_jour;
}
public function setTarifJour(?string $tarif_jour): self
{
if(''===trim($tarif_jour)) return $this;
$this->uncrypted_tarif_jour = $tarif_jour;
$this->tarif_jour = null;
return $this;
}
public function getTypeSalarie(): ?string
{
return $this->type_salarie;
}
public function setTypeSalarie(?string $type_salarie): self
{
$this->type_salarie = $type_salarie;
return $this;
}
public function getDateNaissance(): ?string
{
return $this->date_naissance;
}
public function setDateNaissance(?string $date_naissance): self
{
if(''===trim($date_naissance)) return $this;
$this->uncrypted_date_naissance = $date_naissance;
$this->date_naissance = null;
return $this;
}
public function getLieuNaissance(): ?string
{
return $this->lieu_naissance;
}
public function setLieuNaissance(?string $lieu_naissance): self
{
if(''===trim($lieu_naissance)) return $this;
$this->uncrypted_lieu_naissance = $lieu_naissance;
$this->lieu_naissance = null;
return $this;
}
public function getSituationFamiliale(): ?string
{
return $this->situation_familiale;
}
public function setSituationFamiliale(?string $situation_familiale): self
{
if(''===trim($situation_familiale)) return $this;
$this->uncrypted_situation_familiale = $situation_familiale;
$this->situation_familiale = null;
return $this;
}
public function getNationalite(): ?string
{
return $this->nationalite;
}
public function setNationalite(?string $nationalite): self
{
if(''===trim($nationalite)) return $this;
$this->uncrypted_nationalite = $nationalite;
$this->nationalite = null;
return $this;
}
public function getNumSecuSociale(): ?string
{
return $this->num_secu_sociale;
}
public function setNumSecuSociale(?string $num_secu_sociale): self
{
if(''===trim($num_secu_sociale)) return $this;
$this->uncrypted_num_secu_sociale = $num_secu_sociale;
$this->num_secu_sociale = null;
return $this;
}
public function getNumCongesSpectacle(): ?string
{
return $this->num_conges_spectacle;
}
public function setNumCongesSpectacle(?string $num_conges_spectacle): self
{
if(''===trim($num_conges_spectacle)) return $this;
$this->uncrypted_num_conges_spectacle = $num_conges_spectacle;
$this->num_conges_spectacle = null;
return $this;
}
public function getNumCarteSejour(): ?string
{
return $this->num_carte_sejour;
}
public function setNumCarteSejour(?string $num_carte_sejour): self
{
if(''===trim($num_carte_sejour)) return $this;
$this->uncrypted_num_carte_sejour = $num_carte_sejour;
$this->num_carte_sejour = null;
return $this;
}
public function getNumCartePresse(): ?string
{
return $this->num_carte_presse;
}
public function setNumCartePresse(?string $num_carte_presse): self
{
if(''===trim($num_carte_presse)) return $this;
$this->uncrypted_num_carte_presse = $num_carte_presse;
$this->num_carte_presse = null;
return $this;
}
public function getDateVisiteMedicale(): ?string
{
return $this->date_visite_medicale;
}
public function setDateVisiteMedicale(?string $date_visite_medicale): self
{
if(''===trim($date_visite_medicale)) return $this;
$this->uncrypted_date_visite_medicale = $date_visite_medicale;
$this->date_visite_medicale = null;
return $this;
}
public function getStatutCadre(): ?string
{
return $this->statut_cadre;
}
public function setStatutCadre(?string $statut_cadre): self
{
if(''===trim($statut_cadre)) return $this;
$this->uncrypted_statut_cadre = $statut_cadre;
$this->statut_cadre = null;
return $this;
}
public function getNbEnfant(): ?string
{
return $this->nb_enfant;
}
public function setNbEnfant(?string $nb_enfant): self
{
if(''===trim($nb_enfant)) return $this;
$this->uncrypted_nb_enfant = $nb_enfant;
$this->nb_enfant = null;
return $this;
}
public function getIban(): ?string
{
return $this->iban;
}
public function setIban(?string $iban): self
{
if(''===trim($iban)) return $this;
$this->uncrypted_iban = $iban;
$this->iban = null;
return $this;
}
public function getFonction(): ?string
{
return $this->fonction;
}
public function setFonction(?string $fonction): self
{
$this->fonction = $fonction;
return $this;
}
public function getDateModif(): ?\DateTimeInterface
{
return $this->date_modif;
}
public function setDateModif(\DateTimeInterface $date_modif): self
{
$this->date_modif = $date_modif;
return $this;
}
public function getUserModif(): ?int
{
return $this->user_modif;
}
public function setUserModif(int $user_modif): self
{
$this->user_modif = $user_modif;
return $this;
}
public function getDateCrea(): ?\DateTimeInterface
{
return $this->date_crea;
}
public function setDateCrea(\DateTimeInterface $date_crea): self
{
$this->date_crea = $date_crea;
return $this;
}
public function getUserCrea(): ?int
{
return $this->user_crea;
}
public function setUserCrea(int $user_crea): self
{
$this->user_crea = $user_crea;
return $this;
}
public function getTiers(): ?Tiers
{
return $this->tiers;
}
public function setTiers(?Tiers $tiers): self
{
// unset the owning side of the relation if necessary
if ($tiers === null && $this->tiers !== null) {
$this->tiers->setInfoSalarie(null);
}
// set the owning side of the relation if necessary
if ($tiers !== null && $tiers->getInfoSalarie() !== $this) {
$tiers->setInfoSalarie($this);
}
$this->tiers = $tiers;
return $this;
}
public function initEncryptionKey($webPath): self
{
$this->encryptionKey = KeyFactory::loadEncryptionKey($webPath.'/var/cache/encryption.key');
return $this;
}
public function persistContent(): self
{
foreach ($this->properties as $property){
if (null !== $this->$property && '' !== $this->$property) {
$this->$property = Symmetric::encrypt(new HiddenString($this->$property), $this->encryptionKey);
}
}
return $this;
}
public function secureContent(): self
{
foreach ($this->properties as $property){
$uncryptedProperty = 'uncrypted_' . $property;
if(isset($this->{$uncryptedProperty})) {
if (null === $this->$property && null !== $this->$uncryptedProperty && '' !== $this->$uncryptedProperty) {
$this->$property = Symmetric::encrypt(new HiddenString($this->$uncryptedProperty), $this->encryptionKey);
}
}
}
return $this;
}
public function decryptContent(): self
{
if($this->isDecrypted) return $this;
foreach ($this->properties as $property){
if (null !== $this->$property && '' !== $this->$property) {
$decrypted = Symmetric::decrypt($this->$property, $this->encryptionKey);
if(''!==$decrypted->getString()) $this->$property = $decrypted->getString();
}
}
$this->encryptionKey = null;
$this->isDecrypted = true;
$this->checkData();
return $this;
}
public function initInfosVierge()
{
foreach ($this->properties as $property){
$this->$property = '';
}
$this->type_salarie = '';
$this->fonction = '';
}
public function checkData()
{
if($this->isDecrypted) {
$salarie = $this->getTiers();
if (empty($salarie->getPrenomTiers())) $this->_error[] = 'Prénom salarié vide';
if (empty($salarie->getNomTiers())) $this->_error[] = 'Nom salarié vide';
if (15 !== strlen($this->getNumSecuSociale())) $this->_error[] = 'Numéro de sécurité sociale invalide : 15 chiffres attendus';
if (10 !== strlen($this->getDateNaissance())) $this->_error[] = 'Date de naissance invalide';
if (empty($this->getLieuNaissance())) $this->_error[] = 'Lieu de naissance vide';
if (preg_match('/[()]/', $this->getLieuNaissance())) $this->_error[] = 'Les parenthèses sont interdites : ' . $this->getLieuNaissance();
}
}
public function getError()
{
return $this->_error;
}
}