Loading src/UnicaenUtilisateur/Entity/HistoriqueAwareInterface.php 0 → 100644 +119 −0 Original line number Diff line number Diff line <?php namespace UnicaenUtilisateur\Entity; use DateTime; use UnicaenUtilisateur\Entity\Db\UserInterface; interface HistoriqueAwareInterface { /** * Set histoCreation * * @param DateTime $histoCreation * @return self */ public function setHistoCreation(?DateTime $histoCreation); /** * Get histoCreation * * @return DateTime */ public function getHistoCreation(); /** * Set histoDestruction * * @param DateTime $histoDestruction * @return self */ public function setHistoDestruction(?DateTime $histoDestruction); /** * Get histoDestruction * * @return DateTime */ public function getHistoDestruction(); /** * Set histoModification * * @param DateTime $histoModification * @return self */ public function setHistoModification(?DateTime $histoModification); /** * Get histoModification * * @return DateTime */ public function getHistoModification(); /** * Set histoModificateur * * @param UserInterface $histoModificateur * @return self */ public function setHistoModificateur(?UserInterface $histoModificateur = null); /** * Get histoModificateur * * @return UserInterface */ public function getHistoModificateur(); /** * Set histoDestructeur * * @param UserInterface $histoDestructeur * @return self */ public function setHistoDestructeur(?UserInterface $histoDestructeur = null); /** * Get histoDestructeur * * @return UserInterface */ public function getHistoDestructeur(); /** * Set histoCreateur * * @param UserInterface $histoCreateur * @return self */ public function setHistoCreateur(?UserInterface $histoCreateur = null); /** * Get histoCreateur * * @return UserInterface */ public function getHistoCreateur(); /** * @param DateTime|null $dateObs * * @return boolean */ public function estNonHistorise(?DateTime $dateObs = null); /** * @param UserInterface $histoDestructeur * @param DateTime|null $histoDestruction * @return $this */ public function historiser(?UserInterface $histoDestructeur, ?DateTime $histoDestruction = null); /** * @return $this */ public function dehistoriser(); } No newline at end of file src/UnicaenUtilisateur/Entity/HistoriqueAwareTrait.php 0 → 100644 +265 −0 Original line number Diff line number Diff line <?php namespace UnicaenUtilisateur\Entity; use DateTime; use UnicaenApp\Exception\RuntimeException; use UnicaenUtilisateur\Entity\Db\UserInterface; trait HistoriqueAwareTrait { /** * @var DateTime */ protected $histoCreation; /** * @var DateTime */ protected $histoModification; /** * @var DateTime */ protected $histoDestruction; /** * @var UserInterface */ protected $histoCreateur; /** * @var UserInterface */ protected $histoModificateur; /** * @var UserInterface */ protected $histoDestructeur; /** * Set histoCreation * * @param DateTime $histoCreation * * @return self */ public function setHistoCreation(?DateTime $histoCreation) { $this->histoCreation = $histoCreation; return $this; } /** * Get histoCreation * * @return DateTime */ public function getHistoCreation() { return $this->histoCreation; } /** * Set histoDestruction * * @param DateTime $histoDestruction * * @return self */ public function setHistoDestruction(?DateTime $histoDestruction) { $this->histoDestruction = $histoDestruction; return $this; } /** * Get histoDestruction * * @return DateTime */ public function getHistoDestruction() { return $this->histoDestruction; } /** * Set histoModification * * @param DateTime $histoModification * * @return self */ public function setHistoModification(?DateTime $histoModification) { $this->histoModification = $histoModification; return $this; } /** * Get histoModification * * @return DateTime */ public function getHistoModification() { return $this->histoModification; } /** * Set histoModificateur * * @param UserInterface $histoModificateur * * @return self */ public function setHistoModificateur(?UserInterface $histoModificateur = null) { $this->histoModificateur = $histoModificateur; return $this; } /** * Get histoModificateur * * @return UserInterface */ public function getHistoModificateur() { return $this->histoModificateur; } /** * Set histoDestructeur * * @param UserInterface $histoDestructeur * * @return self */ public function setHistoDestructeur(?UserInterface $histoDestructeur = null) { $this->histoDestructeur = $histoDestructeur; return $this; } /** * Get histoDestructeur * * @return UserInterface */ public function getHistoDestructeur() { return $this->histoDestructeur; } /** * Set histoCreateur * * @param UserInterface $histoCreateur * * @return self */ public function setHistoCreateur(?UserInterface $histoCreateur = null) { $this->histoCreateur = $histoCreateur; return $this; } /** * Get histoCreateur * * @return UserInterface */ public function getHistoCreateur() { return $this->histoCreateur; } /** * Marque cet enregistrement comme historisé. * * @see HistoriqueAwareInterface * * @param UserInterface|null $destructeur Auteur de la suppression ; si null, peut être renseigné * automatiquement (cf. HistoriqueListener) si la classe implémente * HistoriqueAwareInterface * @param DateTime|null $dateDestruction Date éventuelle de la suppression * @return $this */ public function historiser(?UserInterface $destructeur = null, ?DateTime $dateDestruction = null) { if ($destructeur) { $this->setHistoDestructeur($destructeur); } if (empty($dateDestruction)) { try { $dateDestruction = new DateTime(); } catch (\Exception $e) { throw new RuntimeException("Impossible d'instancier un DateTime!", null, $e); } } $this->setHistoDestruction($dateDestruction); return $this; } /** * Annule l'historisation de cet enregistrement. * * @see HistoriqueAwareInterface * @return $this */ public function dehistoriser() { $this->setHistoDestructeur(null); $this->setHistoDestruction(null); return $this; } /** * Retourne true si l'entité est historisée. * * @param DateTime|null $dateObs Date d'observation éventuelle * @return bool */ public function estHistorise(?DateTime $dateObs = null) { return ! $this->estNonHistorise($dateObs); } /** * Retourne true si l'entité n'est *pas* historisée. * * @param DateTime|null $dateObs Date d'observation éventuelle * @return bool */ public function estNonHistorise(?DateTime $dateObs = null) { if (empty($dateObs)) { try { $dateObs = new DateTime(); } catch (\Exception $e) { throw new RuntimeException("Impossible d'instancier un DateTime!", null, $e); } } $dObs = $dateObs->format('Y-m-d'); $dDeb = $this->getHistoCreation() ? $this->getHistoCreation()->format('Y-m-d') : null; $dFin = $this->getHistoDestruction() ? $this->getHistoDestruction()->format('Y-m-d') : null; if ($dDeb && !($dDeb <= $dObs)) return false; if ($dFin && !($dObs < $dFin)) return false; return true; } } No newline at end of file src/UnicaenUtilisateur/ORM/Event/Listeners/HistoriqueListener.php +1 −1 Original line number Diff line number Diff line Loading @@ -9,7 +9,7 @@ use Doctrine\ORM\Event\PreUpdateEventArgs; use Doctrine\ORM\Events; use Exception; use RuntimeException; use UnicaenApp\Entity\HistoriqueAwareInterface; use UnicaenUtilisateur\Entity\HistoriqueAwareInterface; use UnicaenUtilisateur\Entity\Db\AbstractUser; use UnicaenUtilisateur\Service\User\UserServiceAwareTrait; use Laminas\Authentication\AuthenticationService; Loading Loading
src/UnicaenUtilisateur/Entity/HistoriqueAwareInterface.php 0 → 100644 +119 −0 Original line number Diff line number Diff line <?php namespace UnicaenUtilisateur\Entity; use DateTime; use UnicaenUtilisateur\Entity\Db\UserInterface; interface HistoriqueAwareInterface { /** * Set histoCreation * * @param DateTime $histoCreation * @return self */ public function setHistoCreation(?DateTime $histoCreation); /** * Get histoCreation * * @return DateTime */ public function getHistoCreation(); /** * Set histoDestruction * * @param DateTime $histoDestruction * @return self */ public function setHistoDestruction(?DateTime $histoDestruction); /** * Get histoDestruction * * @return DateTime */ public function getHistoDestruction(); /** * Set histoModification * * @param DateTime $histoModification * @return self */ public function setHistoModification(?DateTime $histoModification); /** * Get histoModification * * @return DateTime */ public function getHistoModification(); /** * Set histoModificateur * * @param UserInterface $histoModificateur * @return self */ public function setHistoModificateur(?UserInterface $histoModificateur = null); /** * Get histoModificateur * * @return UserInterface */ public function getHistoModificateur(); /** * Set histoDestructeur * * @param UserInterface $histoDestructeur * @return self */ public function setHistoDestructeur(?UserInterface $histoDestructeur = null); /** * Get histoDestructeur * * @return UserInterface */ public function getHistoDestructeur(); /** * Set histoCreateur * * @param UserInterface $histoCreateur * @return self */ public function setHistoCreateur(?UserInterface $histoCreateur = null); /** * Get histoCreateur * * @return UserInterface */ public function getHistoCreateur(); /** * @param DateTime|null $dateObs * * @return boolean */ public function estNonHistorise(?DateTime $dateObs = null); /** * @param UserInterface $histoDestructeur * @param DateTime|null $histoDestruction * @return $this */ public function historiser(?UserInterface $histoDestructeur, ?DateTime $histoDestruction = null); /** * @return $this */ public function dehistoriser(); } No newline at end of file
src/UnicaenUtilisateur/Entity/HistoriqueAwareTrait.php 0 → 100644 +265 −0 Original line number Diff line number Diff line <?php namespace UnicaenUtilisateur\Entity; use DateTime; use UnicaenApp\Exception\RuntimeException; use UnicaenUtilisateur\Entity\Db\UserInterface; trait HistoriqueAwareTrait { /** * @var DateTime */ protected $histoCreation; /** * @var DateTime */ protected $histoModification; /** * @var DateTime */ protected $histoDestruction; /** * @var UserInterface */ protected $histoCreateur; /** * @var UserInterface */ protected $histoModificateur; /** * @var UserInterface */ protected $histoDestructeur; /** * Set histoCreation * * @param DateTime $histoCreation * * @return self */ public function setHistoCreation(?DateTime $histoCreation) { $this->histoCreation = $histoCreation; return $this; } /** * Get histoCreation * * @return DateTime */ public function getHistoCreation() { return $this->histoCreation; } /** * Set histoDestruction * * @param DateTime $histoDestruction * * @return self */ public function setHistoDestruction(?DateTime $histoDestruction) { $this->histoDestruction = $histoDestruction; return $this; } /** * Get histoDestruction * * @return DateTime */ public function getHistoDestruction() { return $this->histoDestruction; } /** * Set histoModification * * @param DateTime $histoModification * * @return self */ public function setHistoModification(?DateTime $histoModification) { $this->histoModification = $histoModification; return $this; } /** * Get histoModification * * @return DateTime */ public function getHistoModification() { return $this->histoModification; } /** * Set histoModificateur * * @param UserInterface $histoModificateur * * @return self */ public function setHistoModificateur(?UserInterface $histoModificateur = null) { $this->histoModificateur = $histoModificateur; return $this; } /** * Get histoModificateur * * @return UserInterface */ public function getHistoModificateur() { return $this->histoModificateur; } /** * Set histoDestructeur * * @param UserInterface $histoDestructeur * * @return self */ public function setHistoDestructeur(?UserInterface $histoDestructeur = null) { $this->histoDestructeur = $histoDestructeur; return $this; } /** * Get histoDestructeur * * @return UserInterface */ public function getHistoDestructeur() { return $this->histoDestructeur; } /** * Set histoCreateur * * @param UserInterface $histoCreateur * * @return self */ public function setHistoCreateur(?UserInterface $histoCreateur = null) { $this->histoCreateur = $histoCreateur; return $this; } /** * Get histoCreateur * * @return UserInterface */ public function getHistoCreateur() { return $this->histoCreateur; } /** * Marque cet enregistrement comme historisé. * * @see HistoriqueAwareInterface * * @param UserInterface|null $destructeur Auteur de la suppression ; si null, peut être renseigné * automatiquement (cf. HistoriqueListener) si la classe implémente * HistoriqueAwareInterface * @param DateTime|null $dateDestruction Date éventuelle de la suppression * @return $this */ public function historiser(?UserInterface $destructeur = null, ?DateTime $dateDestruction = null) { if ($destructeur) { $this->setHistoDestructeur($destructeur); } if (empty($dateDestruction)) { try { $dateDestruction = new DateTime(); } catch (\Exception $e) { throw new RuntimeException("Impossible d'instancier un DateTime!", null, $e); } } $this->setHistoDestruction($dateDestruction); return $this; } /** * Annule l'historisation de cet enregistrement. * * @see HistoriqueAwareInterface * @return $this */ public function dehistoriser() { $this->setHistoDestructeur(null); $this->setHistoDestruction(null); return $this; } /** * Retourne true si l'entité est historisée. * * @param DateTime|null $dateObs Date d'observation éventuelle * @return bool */ public function estHistorise(?DateTime $dateObs = null) { return ! $this->estNonHistorise($dateObs); } /** * Retourne true si l'entité n'est *pas* historisée. * * @param DateTime|null $dateObs Date d'observation éventuelle * @return bool */ public function estNonHistorise(?DateTime $dateObs = null) { if (empty($dateObs)) { try { $dateObs = new DateTime(); } catch (\Exception $e) { throw new RuntimeException("Impossible d'instancier un DateTime!", null, $e); } } $dObs = $dateObs->format('Y-m-d'); $dDeb = $this->getHistoCreation() ? $this->getHistoCreation()->format('Y-m-d') : null; $dFin = $this->getHistoDestruction() ? $this->getHistoDestruction()->format('Y-m-d') : null; if ($dDeb && !($dDeb <= $dObs)) return false; if ($dFin && !($dObs < $dFin)) return false; return true; } } No newline at end of file
src/UnicaenUtilisateur/ORM/Event/Listeners/HistoriqueListener.php +1 −1 Original line number Diff line number Diff line Loading @@ -9,7 +9,7 @@ use Doctrine\ORM\Event\PreUpdateEventArgs; use Doctrine\ORM\Events; use Exception; use RuntimeException; use UnicaenApp\Entity\HistoriqueAwareInterface; use UnicaenUtilisateur\Entity\HistoriqueAwareInterface; use UnicaenUtilisateur\Entity\Db\AbstractUser; use UnicaenUtilisateur\Service\User\UserServiceAwareTrait; use Laminas\Authentication\AuthenticationService; Loading