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