src/JuridicusBundle/Entity/Pruefung.php line 14

Open in your IDE?
  1. <?php
  2. namespace JF\JuridicusBundle\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Symfony\Component\Validator\Constraints as Assert;
  5. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. /**
  8.  * Pruefung
  9.  * @UniqueEntity(fields={"pruefungsamt","datum","bezeichnung"}, message="Die Kombination aus Datum und Bezeichnung wird bereits verwendet.")
  10.  */
  11. class Pruefung extends InitModeEntity
  12. {
  13.     const CLASSNAME __CLASS__;
  14.     const TYP_EXAMEN_1 "1";
  15.     const TYP_EXAMEN_2 "2";
  16.     const TYP_WAHLFACH_1 3;
  17.     const TYP_WAHLFACH_2 4;
  18.     private static $typ_options = array(
  19.         self::TYP_EXAMEN_1 => '1. Staatsexamen',
  20.         self::TYP_EXAMEN_2 => '2. Staatsexamen',
  21.         self::TYP_WAHLFACH_1 => '1. Examen (Wahlfachprüfung)',
  22.         self::TYP_WAHLFACH_2 => '2. Examen (Wahlfachprüfung)'
  23.     );
  24.     public static function getTypKeys()
  25.     {
  26.        return array_keys(self::$typ_options);
  27.     }
  28.     public static function getTypOptions()
  29.     {
  30.         
  31.         return self::$typ_options//changedFrom array_keys(self::$typ_options) 17.01.2020
  32.     }
  33.     /**
  34.      * getTypString
  35.      *
  36.      * @param integer $typ
  37.      * @return string
  38.      */
  39.     public static function getTypString($typ)
  40.     {
  41.         if (isset(self::$typ_options[$typ])) {
  42.             return self::$typ_options[$typ];
  43.         } else {
  44.             throw new \OutOfBoundsException(sprintf('%s, Ungültiger Index %d'__METHOD__$typ));
  45.         }
  46.     }
  47.     /**
  48.      * @var integer
  49.      */
  50.     private $id;
  51.     /**
  52.      * @var \DateTime
  53.      * @Assert\NotNull()
  54.      * @Assert\Type(\DateTimeInterface::class)
  55.      */
  56.     private $datum;
  57.     /**
  58.      * @var string
  59.      * @Assert\NotBlank
  60.      * @Assert\Length(max="24")
  61.      */
  62.     private $bezeichnung;
  63.     /**
  64.      * @var string
  65.      */
  66.     private $thema_kurzvortrag;
  67.     /**
  68.      * @var integer
  69.      * @Assert\Choice(callback="getTypKeys")
  70.      */
  71.     private $typ;
  72.     /**
  73.      * @var boolean
  74.      * @Assert\NotNull
  75.      */
  76.     private $auto_updateable;
  77.     /**
  78.      * @var \DateTime
  79.      * @Assert\Type(\DateTimeInterface::class)
  80.      */
  81.     private $created_at;
  82.     /**
  83.      * @var \DateTime
  84.       ' @Assert\DateTime
  85.      */
  86.     private $updated_at;
  87.     /**
  88.      * @var \JF\JuridicusBundle\Entity\User
  89.      */
  90.     private $creator;
  91.     /**
  92.      * @var \JF\JuridicusBundle\Entity\Pruefungsamt
  93.      */
  94.     private $pruefungsamt;
  95.     /**
  96.      * @var \Doctrine\Common\Collections\Collection
  97.      */
  98.     private $prueflinge;
  99.     /**
  100.      * @var \Doctrine\Common\Collections\Collection
  101.      */
  102.     private $pruefer_pruefungen;
  103.     /**
  104.      * @var \Doctrine\Common\Collections\Collection
  105.      */
  106.     private $kunde_pruefungen;
  107.     /**
  108.      * @var \Doctrine\Common\Collections\Collection
  109.      */
  110.     private $protokoll_infothek_pruefungen;
  111.     /**
  112.      *
  113.      * @var boolean
  114.      */
  115.     private $protokoll_all;
  116.     /**
  117.      *
  118.      * @var boolean
  119.      */
  120.     private $protokoll_none;
  121.     /**
  122.      * Constructor
  123.      */
  124.     public function __construct()
  125.     {
  126.         $this->prueflinge = new ArrayCollection();
  127.         $this->pruefer_pruefungen = new ArrayCollection();
  128.         $this->protokoll_infothek_pruefungen = new ArrayCollection();
  129.         $this->kunde_pruefungen = new ArrayCollection();
  130.     }
  131.     /**
  132.      * Get id
  133.      *
  134.      * @return integer
  135.      */
  136.     public function getId()
  137.     {
  138.         return $this->id;
  139.     }
  140.     /**
  141.      * Set typ
  142.      *
  143.      * @param integer $typ
  144.      * @return Pruefung
  145.      */
  146.     public function setTyp($typ)
  147.     {
  148.         $this->typ $typ;
  149.         return $this;
  150.     }
  151.     /**
  152.      * Get typ
  153.      *
  154.      * @return integer
  155.      */
  156.     public function getTyp()
  157.     {
  158.         return $this->typ;
  159.     }
  160.     /**
  161.      * Set datum
  162.      *
  163.      * @param \DateTime $datum
  164.      * @return Pruefung
  165.      */
  166.     public function setDatum(\DateTime $datum)
  167.     {
  168.         if ($datum != $this->datum) {
  169.             $this->datum $datum;
  170.         }
  171.         return $this;
  172.     }
  173.     /**
  174.      * Get datum
  175.      *
  176.      * @return \DateTime
  177.      */
  178.     public function getDatum()
  179.     {
  180.         return $this->datum;
  181.     }
  182.     /**
  183.      * Get days elapsed since datum
  184.      *
  185.      * @return integer
  186.      */
  187.     public function getDaysElapsed()
  188.     {
  189.         $now = new \DateTime();
  190.         return $now->diff($this->datum)->days;
  191.     }
  192.     /**
  193.      * Set bezeichnung
  194.      *
  195.      * @param string $bezeichnung
  196.      * @return Pruefung
  197.      */
  198.     public function setBezeichnung($bezeichnung)
  199.     {
  200.         $this->bezeichnung $bezeichnung;
  201.         return $this;
  202.     }
  203.     /**
  204.      * Get bezeichnung
  205.      *
  206.      * @return string
  207.      */
  208.     public function getBezeichnung()
  209.     {
  210.         return $this->bezeichnung;
  211.     }
  212.     /**
  213.      * Set thema_kurzvortrag
  214.      *
  215.      * @param string $themaKurzvortrag
  216.      * @return Pruefung
  217.      */
  218.     public function setThemaKurzvortrag($themaKurzvortrag)
  219.     {
  220.         $this->thema_kurzvortrag $themaKurzvortrag;
  221.         return $this;
  222.     }
  223.     /**
  224.      * Get thema_kurzvortrag
  225.      *
  226.      * @return string
  227.      */
  228.     public function getThemaKurzvortrag()
  229.     {
  230.         return $this->thema_kurzvortrag;
  231.     }
  232.     /**
  233.      * Set auto_updateable
  234.      *
  235.      * @param boolean $autoUpdateable
  236.      * @return Pruefung
  237.      */
  238.     public function setAutoUpdateable($autoUpdateable true)
  239.     {
  240.         $this->auto_updateable = (bool) $autoUpdateable;
  241.         return $this;
  242.     }
  243.     /**
  244.      * Get auto_updateable
  245.      *
  246.      * @return boolean
  247.      */
  248.     public function getAutoUpdateable()
  249.     {
  250.         return $this->auto_updateable;
  251.     }
  252.     /**
  253.      * Set created_at
  254.      *
  255.      * @param \DateTime $createdAt
  256.      * @return Pruefung
  257.      */
  258.     public function setCreatedAt(\DateTime $createdAt null)
  259.     {
  260.         $this->created_at $createdAt;
  261.         return $this;
  262.     }
  263.     /**
  264.      * Get created_at
  265.      *
  266.      * @return \DateTime
  267.      */
  268.     public function getCreatedAt()
  269.     {
  270.         return $this->created_at;
  271.     }
  272.     /**
  273.      * Set updated_at
  274.      *
  275.      * @param \DateTime $updatedAt
  276.      * @return Pruefung
  277.      */
  278.     public function setUpdatedAt(\DateTime $updatedAt=null)
  279.     {
  280.         $this->updated_at $updatedAt;
  281.         return $this;
  282.     }
  283.     /**
  284.      * Get updated_at
  285.      *
  286.      * @return \DateTime
  287.      */
  288.     public function getUpdatedAt()
  289.     {
  290.         return $this->updated_at;
  291.     }
  292.     /**
  293.      * Add prueflinge
  294.      *
  295.      * @param \JF\JuridicusBundle\Entity\Pruefling $prueflinge
  296.      * @return Pruefung
  297.      */
  298.     public function addPrueflinge(Pruefling $prueflinge)
  299.     {
  300.         $this->prueflinge[] = $prueflinge;
  301.         $prueflinge->setPruefung($this);
  302.         return $this;
  303.     }
  304.     /**
  305.      * Remove prueflinge [INVERSE SIDE]
  306.      *
  307.      * @param \JF\JuridicusBundle\Entity\Pruefling $prueflinge
  308.      */
  309.     public function removePrueflinge(Pruefling $prueflinge)
  310.     {
  311.         $this->prueflinge->removeElement($prueflinge);
  312.     }
  313.     /**
  314.      * Get prueflinge
  315.      *
  316.      * @return \Doctrine\Common\Collections\Collection
  317.      */
  318.     public function getPrueflinge()
  319.     {
  320.         return $this->prueflinge;
  321.     }
  322.     /**
  323.      * Set creator [OWNING SIDE]
  324.      *
  325.      * @param \JF\JuridicusBundle\Entity\User $creator
  326.      * @return Pruefung
  327.      */
  328.     public function setCreator(User $creator null)
  329.     {
  330.         $this->creator $creator;
  331.         return $this;
  332.     }
  333.     /**
  334.      * Get creator
  335.      *
  336.      * @return \JF\JuridicusBundle\Entity\User
  337.      */
  338.     public function getCreator()
  339.     {
  340.         return $this->creator;
  341.     }
  342.     /**
  343.      * Set pruefungsamt [OWNING SIDE]
  344.      *
  345.      * @param \JF\JuridicusBundle\Entity\Pruefungsamt $pruefungsamt
  346.      * @return Pruefung
  347.      */
  348.     public function setPruefungsamt(Pruefungsamt $pruefungsamt null)
  349.     {
  350.         $this->pruefungsamt $pruefungsamt;
  351.         return $this;
  352.     }
  353.     /**
  354.      * Get pruefungsamt
  355.      *
  356.      * @return \JF\JuridicusBundle\Entity\Pruefungsamt
  357.      */
  358.     public function getPruefungsamt()
  359.     {
  360.         return $this->pruefungsamt;
  361.     }
  362.     /**
  363.      * Add pruefer_pruefungen [INVERSE SIDE]
  364.      *
  365.      * @param \JF\JuridicusBundle\Entity\PrueferPruefung $prueferPruefungen
  366.      * @return Pruefung
  367.      */
  368.     public function addPrueferPruefungen(PrueferPruefung $prueferPruefungen)
  369.     {
  370.         $this->pruefer_pruefungen[] = $prueferPruefungen;
  371.         $prueferPruefungen->setPruefung($this);
  372.         return $this;
  373.     }
  374.     /**
  375.      * Remove pruefer_pruefungen [INVERSE SIDE]
  376.      *
  377.      * @param \JF\JuridicusBundle\Entity\PrueferPruefung $prueferPruefungen
  378.      */
  379.     public function removePrueferPruefungen(PrueferPruefung $prueferPruefungen)
  380.     {
  381.         $this->pruefer_pruefungen->removeElement($prueferPruefungen);
  382.     }
  383.     /**
  384.      * Get pruefer_pruefungen
  385.      *
  386.      * @return \Doctrine\Common\Collections\Collection
  387.      */
  388.     public function getPrueferPruefungen()
  389.     {
  390.         return $this->pruefer_pruefungen;
  391.     }
  392.     /**
  393.      * Add kunde_pruefungen [INVERSE SIDE]
  394.      *
  395.      * @param \JF\JuridicusBundle\Entity\KundePruefung $kundePruefungen
  396.      * @return Pruefung
  397.      */
  398.     public function addKundePruefungen(KundePruefung $kundePruefungen)
  399.     {
  400.         $this->kunde_pruefungen[] = $kundePruefungen;
  401.         $kundePruefungen->setPruefung($this);
  402.         return $this;
  403.     }
  404.     /**
  405.      * Remove kunde_pruefungen [INVERSE SIDE]
  406.      *
  407.      * @param \JF\JuridicusBundle\Entity\KundePruefung $kundePruefungen
  408.      */
  409.     public function removeKundePruefungen(KundePruefung $kundePruefungen)
  410.     {
  411.         $this->kunde_pruefungen->removeElement($kundePruefungen);
  412.         $kundePruefungen->setPruefung(null);
  413.     }
  414.     /**
  415.      * Get kunde_pruefungen
  416.      *
  417.      * @return \Doctrine\Common\Collections\Collection
  418.      */
  419.     public function getKundePruefungen()
  420.     {
  421.         return $this->kunde_pruefungen;
  422.     }
  423.     /**
  424.      * Add protokoll_infothek_pruefungen [INVERSE SIDE]
  425.      *
  426.      * @param \JF\JuridicusBundle\Entity\ProtokollInfothekPruefung $protokollInfothekPruefungen
  427.      * @return Pruefung
  428.      */
  429.     public function addProtokollInfothekPruefungen(ProtokollInfothekPruefung $protokollInfothekPruefungen)
  430.     {
  431.         $this->protokoll_infothek_pruefungen[] = $protokollInfothekPruefungen;
  432.         return $this;
  433.     }
  434.     /**
  435.      * Remove protokoll_infothek_pruefungen [INVERSE SIDE]
  436.      *
  437.      * @param \JF\JuridicusBundle\Entity\ProtokollInfothekPruefung $protokollInfothekPruefungen
  438.      */
  439.     public function removeProtokollInfothekPruefungen(ProtokollInfothekPruefung $protokollInfothekPruefungen)
  440.     {
  441.         $this->protokoll_infothek_pruefungen->removeElement($protokollInfothekPruefungen);
  442.     }
  443.     /**
  444.      * Get protokoll_infothek_pruefungen
  445.      *
  446.      * @return \Doctrine\Common\Collections\Collection
  447.      */
  448.     public function getProtokollInfothekPruefungen()
  449.     {
  450.         return $this->protokoll_infothek_pruefungen;
  451.     }
  452.     /**
  453.      * @ORM\PrePersist
  454.      */
  455.     public function setCreatedAtValue()
  456.     {
  457.         if (! isset($this->created_at)) {
  458.             $this->setCreatedAt(new \DateTime());
  459.         }
  460.     }
  461.     /**
  462.      * @ORM\PreUpdate
  463.      */
  464.     public function setUpdatedAtValue()
  465.     {
  466.         if (! isset($this->updated_at)) {
  467.             $this->setUpdatedAt(new \DateTime());
  468.         }
  469.     }
  470.     /**
  471.      * @param Pruefungsamt
  472.      * @param integer $typ
  473.      * @return Pruefung
  474.      */
  475.     public static function createForPruefungsamt(Pruefungsamt $pruefungsamt$typ)
  476.     {
  477.         $entity = new Pruefung();
  478.         $entity
  479.                 ->setPruefungsamt($pruefungsamt)
  480.                 ->setTyp($typ)
  481.                 ->setAutoUpdateable(false)
  482.         ;
  483.         if ($typ 3) {
  484.             for ($i 1$i <= $pruefungsamt->getAnzahlPruefer(); $i++) {
  485.                 $pruefer_pruefung = new PrueferPruefung();
  486.                 $pruefer_pruefung
  487.                         ->setVorsitz($i == 1)
  488.                         ->setSortierung($i)
  489.                         ->setPruefung($entity)
  490.                 ;
  491.                 $entity->addPrueferPruefungen($pruefer_pruefung);
  492.             }
  493.         } else {
  494.             $pruefer_pruefung = new PrueferPruefung();
  495.             $pruefer_pruefung
  496.                     ->setVorsitz(false)
  497.                     ->setSortierung(1)
  498.                     ->setPruefung($entity)
  499.             ;
  500.             $entity->addPrueferPruefungen($pruefer_pruefung);
  501.         }
  502.         return $entity;
  503.     }
  504.     /**
  505.      *
  506.      * @return boolean
  507.      */
  508.     public function hatKeineProtokolle()
  509.     {
  510.         if ($this->protokoll_none === null) {
  511.             $this->checkProtokolle();
  512.         }
  513.         return $this->protokoll_none;
  514.     }
  515.     /**
  516.      *
  517.      * @return boolean
  518.      */
  519.     public function hatAlleProtokolle()
  520.     {
  521.         if ($this->protokoll_all === null) {
  522.             $this->checkProtokolle();
  523.         }
  524.         return $this->protokoll_all;
  525.     }
  526.     /**
  527.      *
  528.      * @param \JF\JuridicusBundle\Entity\Kunde $kunde
  529.      * @return boolean
  530.      */
  531.     public function isGebucht(Kunde $kunde)
  532.     {
  533.         foreach ($this->getKundePruefungen() as $buchung) {
  534.             /* @var $buchung \JF\JuridicusBundle\Entity\KundePruefung */
  535.             if ($buchung->getKunde()->getId() == $kunde->getId()) {
  536.                 return true;
  537.             }
  538.         }
  539.         return false;
  540.     }
  541.     /**
  542.      *
  543.      * @param \JF\JuridicusBundle\Entity\Kunde $kunde
  544.      * @return \JF\JuridicusBundle\Entity\KundePruefung|null
  545.      */
  546.     public function findBuchung(Kunde $kunde)
  547.     {
  548.         foreach ($this->getKundePruefungen() as $buchung) {
  549.             /* @var $buchung \JF\JuridicusBundle\Entity\KundePruefung */
  550.             if ($buchung->getKunde()->getId() == $kunde->getId()) {
  551.                 return $buchung;
  552.             }
  553.         }
  554.         return null;
  555.     }
  556.     /**
  557.      *
  558.      */
  559.     private function checkProtokolle()
  560.     {
  561.         $this->protokoll_all true;
  562.         $this->protokoll_none true;
  563.         foreach ($this->getPrueferPruefungen() as $i => $pruefer_pruefung) {
  564.             $count $pruefer_pruefung->getPruefer()->getProtokollCount();
  565.             if ($count['gesamt'] > 0) {
  566.                 $this->protokoll_none false;
  567.             } else {
  568.                 $this->protokoll_all false;
  569.             }
  570.         }
  571.     }
  572.     /**
  573.      * String Representation
  574.      *
  575.      * @return string
  576.      */
  577.     public function __toString()
  578.     {
  579.         if (isset($this->id)) {
  580.             return sprintf('%s: %s (%s)'$this->datum->format('d.m.Y'), $this->bezeichnung,
  581.                     $this->pruefungsamt->getBezeichnung());
  582.         }
  583.         return 'Neue Prüfung';
  584.     }
  585. }