bundles/ADAS/LogowanieBundle/Security/User/DaneUsera.php line 51

Open in your IDE?
  1. <?php
  2. /*
  3.  * To change this license header, choose License Headers in Project Properties.
  4.  * To change this template file, choose Tools | Templates
  5.  * and open the template in the editor.
  6.  */
  7. namespace ADAS\LogowanieBundle\Security\User;
  8. use ADAS\LogowanieBundle\Entity\SysWydzialy;
  9. use Symfony\Component\HttpFoundation\RequestStack;
  10. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  11. /**
  12.  * serwis zarządzający danymi usera 
  13.  * 
  14.  * @author abielecki
  15.  */
  16. class DaneUsera
  17. {
  18.     private $DataLogowania="ADASDataLogowania";
  19.     private $WybranaJednostka="ADASWybranaJednostka";
  20.     private $WybranyWydzial="ADASWybranyWydzial";
  21.     private $RokLogowania="ADASRokLogowania";
  22.     private $IdUsera="ADASUserData";
  23.     private $Wersja="ADASWersja";
  24.     public function __construct(
  25.         private RequestStack $requestStack
  26.     ) {}
  27.     public function getCzybylWydzial()
  28.     {
  29.         if($this->getSession()->has($this->WybranyWydzial))
  30.             return true;
  31.         else
  32.             return false;
  33.     }
  34.     public function setDatalogowania($Data)
  35.     {
  36.         $this->getSession()->set($this->DataLogowania, $Data);
  37.         $timestamp = strtotime($Data);
  38.         $rok=  date("Y",$timestamp);
  39.         $this->setRoklogowania($rok);
  40.     }
  41.     
  42.     public function getDatalogowania()
  43.     {
  44.         return $this->getSession()->get($this->DataLogowania);
  45.     }
  46.     public function setRoklogowania($Data)
  47.     {
  48.         $this->getSession()->set($this->RokLogowania, $Data);
  49.     }
  50.     
  51.     public function getRoklogowania()
  52.     {
  53.         return $this->getSession()->get($this->RokLogowania);
  54.     }
  55.     
  56.     public function setWybranaJednostka($Data)
  57.     {
  58.         $this->getSession()->set($this->WybranaJednostka,$Data);
  59.     }
  60.     public function getWybranaJednostka()
  61.     {
  62.         return $this->getSession()->get($this->WybranaJednostka);
  63.     }    
  64.     
  65.     public function setWybranyWydzial($Data)
  66.     {
  67.         $this->getSession()->set($this->WybranyWydzial,$Data);
  68.     }
  69.     /**
  70.      * 
  71.      * @return SysWydzialy;
  72.      */
  73.     public function getWybranyWydzial()
  74.     {
  75.         return $this->getSession()->get($this->WybranyWydzial);
  76.     }    
  77.         
  78.     /*
  79.      * Funkcja kasujaca dane Usera z Sesji
  80.      */
  81.     public function KasujDane()
  82.     {
  83.         $this->getSession()->set($this->WybranyWydzial,null);
  84.         $this->getSession()->set($this->DataLogowania, null);
  85.         $this->getSession()->set($this->WybranaJednostka,null);
  86.         $this->getSession()->set($this->RokLogowania,null);
  87.         $this->getSession()->set($this->IdUsera,null);
  88.         $this->getSession()->set($this->Wersja,null);
  89.     }
  90.     
  91.     public function getWybranyWydzialNazwa()
  92.     {   $mRet =$this->getSession()->get($this->WybranyWydzial);
  93.         if($mRet===null)
  94.             return '';
  95.         else
  96.             return $mRet->getNazwa();
  97.     }    
  98.     
  99.     public function getWybranaJednostkaNazwa() 
  100.     {
  101.         $mRet=$this->getSession()->get($this->WybranaJednostka);
  102.         if($mRet===null)
  103.             return '';
  104.         else
  105.             return $mRet->getNazwa();
  106.         
  107.     }
  108.     
  109.     public function getIdWybranejJednostki() 
  110.     {
  111.         $mRet=$this->getSession()->get($this->WybranaJednostka);
  112.         if($mRet===null)
  113.             return -1;
  114.         else
  115.             return $mRet->getIdjednostki();
  116.         
  117.     }
  118.     
  119.     public function setIdusera($idusera)
  120.     {
  121.          $this->getSession()->set($this->IdUsera,$idusera);
  122.          
  123.     }
  124.     
  125.     public function getIdusera()
  126.     {
  127.         $mRet=$this->getSession()->get($this->IdUsera);
  128.         if($mRet===null)
  129.             return 0;
  130.         else
  131.             return $mRet->getId();
  132.     }
  133.     
  134.     public function getIdWybranegoWydzialu()
  135.     {
  136.         $mRet=$this->getSession()->get($this->WybranyWydzial);
  137.         if($mRet===null)
  138.             return -1;
  139.         else
  140.            return $mRet->getNrid();
  141.     }
  142.     
  143.     public function getUserData() 
  144.     {
  145.         $mRet=$this->getSession()->get($this->IdUsera);
  146.         if($mRet===null)
  147.             return null;
  148.         else
  149.             return $mRet;
  150.     }
  151.     private function getSession(): SessionInterface
  152.     {
  153.         return $this->requestStack->getSession();
  154.     }
  155. }