<?php
namespace JF\JuridicusBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Doctrine\Common\Collections\ArrayCollection;
/**
* Pruefung
* @UniqueEntity(fields={"pruefungsamt","datum","bezeichnung"}, message="Die Kombination aus Datum und Bezeichnung wird bereits verwendet.")
*/
class Pruefung extends InitModeEntity
{
const CLASSNAME = __CLASS__;
const TYP_EXAMEN_1 = "1";
const TYP_EXAMEN_2 = "2";
const TYP_WAHLFACH_1 = 3;
const TYP_WAHLFACH_2 = 4;
private static $typ_options = array(
self::TYP_EXAMEN_1 => '1. Staatsexamen',
self::TYP_EXAMEN_2 => '2. Staatsexamen',
self::TYP_WAHLFACH_1 => '1. Examen (Wahlfachprüfung)',
self::TYP_WAHLFACH_2 => '2. Examen (Wahlfachprüfung)'
);
public static function getTypKeys()
{
return array_keys(self::$typ_options);
}
public static function getTypOptions()
{
return self::$typ_options; //changedFrom array_keys(self::$typ_options) 17.01.2020
}
/**
* getTypString
*
* @param integer $typ
* @return string
*/
public static function getTypString($typ)
{
if (isset(self::$typ_options[$typ])) {
return self::$typ_options[$typ];
} else {
throw new \OutOfBoundsException(sprintf('%s, Ungültiger Index %d', __METHOD__, $typ));
}
}
/**
* @var integer
*/
private $id;
/**
* @var \DateTime
* @Assert\NotNull()
* @Assert\Type(\DateTimeInterface::class)
*/
private $datum;
/**
* @var string
* @Assert\NotBlank
* @Assert\Length(max="24")
*/
private $bezeichnung;
/**
* @var string
*/
private $thema_kurzvortrag;
/**
* @var integer
* @Assert\Choice(callback="getTypKeys")
*/
private $typ;
/**
* @var boolean
* @Assert\NotNull
*/
private $auto_updateable;
/**
* @var \DateTime
* @Assert\Type(\DateTimeInterface::class)
*/
private $created_at;
/**
* @var \DateTime
' @Assert\DateTime
*/
private $updated_at;
/**
* @var \JF\JuridicusBundle\Entity\User
*/
private $creator;
/**
* @var \JF\JuridicusBundle\Entity\Pruefungsamt
*/
private $pruefungsamt;
/**
* @var \Doctrine\Common\Collections\Collection
*/
private $prueflinge;
/**
* @var \Doctrine\Common\Collections\Collection
*/
private $pruefer_pruefungen;
/**
* @var \Doctrine\Common\Collections\Collection
*/
private $kunde_pruefungen;
/**
* @var \Doctrine\Common\Collections\Collection
*/
private $protokoll_infothek_pruefungen;
/**
*
* @var boolean
*/
private $protokoll_all;
/**
*
* @var boolean
*/
private $protokoll_none;
/**
* Constructor
*/
public function __construct()
{
$this->prueflinge = new ArrayCollection();
$this->pruefer_pruefungen = new ArrayCollection();
$this->protokoll_infothek_pruefungen = new ArrayCollection();
$this->kunde_pruefungen = new ArrayCollection();
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set typ
*
* @param integer $typ
* @return Pruefung
*/
public function setTyp($typ)
{
$this->typ = $typ;
return $this;
}
/**
* Get typ
*
* @return integer
*/
public function getTyp()
{
return $this->typ;
}
/**
* Set datum
*
* @param \DateTime $datum
* @return Pruefung
*/
public function setDatum(\DateTime $datum)
{
if ($datum != $this->datum) {
$this->datum = $datum;
}
return $this;
}
/**
* Get datum
*
* @return \DateTime
*/
public function getDatum()
{
return $this->datum;
}
/**
* Get days elapsed since datum
*
* @return integer
*/
public function getDaysElapsed()
{
$now = new \DateTime();
return $now->diff($this->datum)->days;
}
/**
* Set bezeichnung
*
* @param string $bezeichnung
* @return Pruefung
*/
public function setBezeichnung($bezeichnung)
{
$this->bezeichnung = $bezeichnung;
return $this;
}
/**
* Get bezeichnung
*
* @return string
*/
public function getBezeichnung()
{
return $this->bezeichnung;
}
/**
* Set thema_kurzvortrag
*
* @param string $themaKurzvortrag
* @return Pruefung
*/
public function setThemaKurzvortrag($themaKurzvortrag)
{
$this->thema_kurzvortrag = $themaKurzvortrag;
return $this;
}
/**
* Get thema_kurzvortrag
*
* @return string
*/
public function getThemaKurzvortrag()
{
return $this->thema_kurzvortrag;
}
/**
* Set auto_updateable
*
* @param boolean $autoUpdateable
* @return Pruefung
*/
public function setAutoUpdateable($autoUpdateable = true)
{
$this->auto_updateable = (bool) $autoUpdateable;
return $this;
}
/**
* Get auto_updateable
*
* @return boolean
*/
public function getAutoUpdateable()
{
return $this->auto_updateable;
}
/**
* Set created_at
*
* @param \DateTime $createdAt
* @return Pruefung
*/
public function setCreatedAt(\DateTime $createdAt = null)
{
$this->created_at = $createdAt;
return $this;
}
/**
* Get created_at
*
* @return \DateTime
*/
public function getCreatedAt()
{
return $this->created_at;
}
/**
* Set updated_at
*
* @param \DateTime $updatedAt
* @return Pruefung
*/
public function setUpdatedAt(\DateTime $updatedAt=null)
{
$this->updated_at = $updatedAt;
return $this;
}
/**
* Get updated_at
*
* @return \DateTime
*/
public function getUpdatedAt()
{
return $this->updated_at;
}
/**
* Add prueflinge
*
* @param \JF\JuridicusBundle\Entity\Pruefling $prueflinge
* @return Pruefung
*/
public function addPrueflinge(Pruefling $prueflinge)
{
$this->prueflinge[] = $prueflinge;
$prueflinge->setPruefung($this);
return $this;
}
/**
* Remove prueflinge [INVERSE SIDE]
*
* @param \JF\JuridicusBundle\Entity\Pruefling $prueflinge
*/
public function removePrueflinge(Pruefling $prueflinge)
{
$this->prueflinge->removeElement($prueflinge);
}
/**
* Get prueflinge
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getPrueflinge()
{
return $this->prueflinge;
}
/**
* Set creator [OWNING SIDE]
*
* @param \JF\JuridicusBundle\Entity\User $creator
* @return Pruefung
*/
public function setCreator(User $creator = null)
{
$this->creator = $creator;
return $this;
}
/**
* Get creator
*
* @return \JF\JuridicusBundle\Entity\User
*/
public function getCreator()
{
return $this->creator;
}
/**
* Set pruefungsamt [OWNING SIDE]
*
* @param \JF\JuridicusBundle\Entity\Pruefungsamt $pruefungsamt
* @return Pruefung
*/
public function setPruefungsamt(Pruefungsamt $pruefungsamt = null)
{
$this->pruefungsamt = $pruefungsamt;
return $this;
}
/**
* Get pruefungsamt
*
* @return \JF\JuridicusBundle\Entity\Pruefungsamt
*/
public function getPruefungsamt()
{
return $this->pruefungsamt;
}
/**
* Add pruefer_pruefungen [INVERSE SIDE]
*
* @param \JF\JuridicusBundle\Entity\PrueferPruefung $prueferPruefungen
* @return Pruefung
*/
public function addPrueferPruefungen(PrueferPruefung $prueferPruefungen)
{
$this->pruefer_pruefungen[] = $prueferPruefungen;
$prueferPruefungen->setPruefung($this);
return $this;
}
/**
* Remove pruefer_pruefungen [INVERSE SIDE]
*
* @param \JF\JuridicusBundle\Entity\PrueferPruefung $prueferPruefungen
*/
public function removePrueferPruefungen(PrueferPruefung $prueferPruefungen)
{
$this->pruefer_pruefungen->removeElement($prueferPruefungen);
}
/**
* Get pruefer_pruefungen
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getPrueferPruefungen()
{
return $this->pruefer_pruefungen;
}
/**
* Add kunde_pruefungen [INVERSE SIDE]
*
* @param \JF\JuridicusBundle\Entity\KundePruefung $kundePruefungen
* @return Pruefung
*/
public function addKundePruefungen(KundePruefung $kundePruefungen)
{
$this->kunde_pruefungen[] = $kundePruefungen;
$kundePruefungen->setPruefung($this);
return $this;
}
/**
* Remove kunde_pruefungen [INVERSE SIDE]
*
* @param \JF\JuridicusBundle\Entity\KundePruefung $kundePruefungen
*/
public function removeKundePruefungen(KundePruefung $kundePruefungen)
{
$this->kunde_pruefungen->removeElement($kundePruefungen);
$kundePruefungen->setPruefung(null);
}
/**
* Get kunde_pruefungen
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getKundePruefungen()
{
return $this->kunde_pruefungen;
}
/**
* Add protokoll_infothek_pruefungen [INVERSE SIDE]
*
* @param \JF\JuridicusBundle\Entity\ProtokollInfothekPruefung $protokollInfothekPruefungen
* @return Pruefung
*/
public function addProtokollInfothekPruefungen(ProtokollInfothekPruefung $protokollInfothekPruefungen)
{
$this->protokoll_infothek_pruefungen[] = $protokollInfothekPruefungen;
return $this;
}
/**
* Remove protokoll_infothek_pruefungen [INVERSE SIDE]
*
* @param \JF\JuridicusBundle\Entity\ProtokollInfothekPruefung $protokollInfothekPruefungen
*/
public function removeProtokollInfothekPruefungen(ProtokollInfothekPruefung $protokollInfothekPruefungen)
{
$this->protokoll_infothek_pruefungen->removeElement($protokollInfothekPruefungen);
}
/**
* Get protokoll_infothek_pruefungen
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getProtokollInfothekPruefungen()
{
return $this->protokoll_infothek_pruefungen;
}
/**
* @ORM\PrePersist
*/
public function setCreatedAtValue()
{
if (! isset($this->created_at)) {
$this->setCreatedAt(new \DateTime());
}
}
/**
* @ORM\PreUpdate
*/
public function setUpdatedAtValue()
{
if (! isset($this->updated_at)) {
$this->setUpdatedAt(new \DateTime());
}
}
/**
* @param Pruefungsamt
* @param integer $typ
* @return Pruefung
*/
public static function createForPruefungsamt(Pruefungsamt $pruefungsamt, $typ)
{
$entity = new Pruefung();
$entity
->setPruefungsamt($pruefungsamt)
->setTyp($typ)
->setAutoUpdateable(false)
;
if ($typ < 3) {
for ($i = 1; $i <= $pruefungsamt->getAnzahlPruefer(); $i++) {
$pruefer_pruefung = new PrueferPruefung();
$pruefer_pruefung
->setVorsitz($i == 1)
->setSortierung($i)
->setPruefung($entity)
;
$entity->addPrueferPruefungen($pruefer_pruefung);
}
} else {
$pruefer_pruefung = new PrueferPruefung();
$pruefer_pruefung
->setVorsitz(false)
->setSortierung(1)
->setPruefung($entity)
;
$entity->addPrueferPruefungen($pruefer_pruefung);
}
return $entity;
}
/**
*
* @return boolean
*/
public function hatKeineProtokolle()
{
if ($this->protokoll_none === null) {
$this->checkProtokolle();
}
return $this->protokoll_none;
}
/**
*
* @return boolean
*/
public function hatAlleProtokolle()
{
if ($this->protokoll_all === null) {
$this->checkProtokolle();
}
return $this->protokoll_all;
}
/**
*
* @param \JF\JuridicusBundle\Entity\Kunde $kunde
* @return boolean
*/
public function isGebucht(Kunde $kunde)
{
foreach ($this->getKundePruefungen() as $buchung) {
/* @var $buchung \JF\JuridicusBundle\Entity\KundePruefung */
if ($buchung->getKunde()->getId() == $kunde->getId()) {
return true;
}
}
return false;
}
/**
*
* @param \JF\JuridicusBundle\Entity\Kunde $kunde
* @return \JF\JuridicusBundle\Entity\KundePruefung|null
*/
public function findBuchung(Kunde $kunde)
{
foreach ($this->getKundePruefungen() as $buchung) {
/* @var $buchung \JF\JuridicusBundle\Entity\KundePruefung */
if ($buchung->getKunde()->getId() == $kunde->getId()) {
return $buchung;
}
}
return null;
}
/**
*
*/
private function checkProtokolle()
{
$this->protokoll_all = true;
$this->protokoll_none = true;
foreach ($this->getPrueferPruefungen() as $i => $pruefer_pruefung) {
$count = $pruefer_pruefung->getPruefer()->getProtokollCount();
if ($count['gesamt'] > 0) {
$this->protokoll_none = false;
} else {
$this->protokoll_all = false;
}
}
}
/**
* String Representation
*
* @return string
*/
public function __toString()
{
if (isset($this->id)) {
return sprintf('%s: %s (%s)', $this->datum->format('d.m.Y'), $this->bezeichnung,
$this->pruefungsamt->getBezeichnung());
}
return 'Neue Prüfung';
}
}