src/JuridicusBundle/Entity/Gutschein.php line 18

Open in your IDE?
  1. <?php
  2. namespace JF\JuridicusBundle\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Doctrine\Common\Collections\Criteria;
  5. use Symfony\Component\Validator\Constraints as Assert;
  6. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  7. /**
  8. * Gutschein
  9. *
  10. * @ORM\Entity
  11. * @UniqueEntity("code")
  12. */
  13. class Gutschein
  14. {
  15. const CLASSNAME = __CLASS__;
  16. const STATUS_UNUSED = NULL;
  17. const STATUS_USED = 'USED';
  18. const STATUS_BLOCKED = 'BLOCKED';
  19. /**
  20. * @var integer
  21. */
  22. private $id;
  23. /**
  24. * @var string
  25. */
  26. private $code;
  27. /**
  28. *
  29. * @var boolean
  30. */
  31. private $multiple = false;
  32. /**
  33. * @var \DateTime
  34. */
  35. private $created_at;
  36. /**
  37. * @var float
  38. */
  39. private $betrag;
  40. /**
  41. * @var \DateTime
  42. */
  43. private $expires_at;
  44. /**
  45. * @var integer
  46. */
  47. private $valid_abo_typ;
  48. /**
  49. * @var string
  50. */
  51. private $valid_zeitschrift;
  52. /**
  53. * @var boolean
  54. */
  55. private $valid_online;
  56. /**
  57. * @var \Doctrine\Common\Collections\Collection
  58. */
  59. private $buchungen;
  60. /**
  61. * @var \Doctrine\Common\Collections\Collection
  62. */
  63. private $abos;
  64. /**
  65. *
  66. * @var string
  67. */
  68. private static $code_chars = 'ABCDEFGHJKMNPQRSTUXYZ23456789';
  69. /**
  70. * Get id
  71. *
  72. * @return integer
  73. */
  74. public function getId()
  75. {
  76. return $this->id;
  77. }
  78. /**
  79. * @Assert\IsTrue(groups={"gutschein"}, message = "Ungültiger Gutscheincode.")
  80. * changedFrom Assert\True
  81. */
  82. public function isValid()
  83. {
  84. return $this->id !== null;
  85. }
  86. /**
  87. * isUsed
  88. *
  89. * @return boolean
  90. *
  91. * @Assert\IsFalse(groups={"gutschein"}, message = "Der Gutscheincode wurde bereits verwendet.")
  92. * changedFrom Assert\False
  93. */
  94. public function isUsed()
  95. {
  96. if ($this->multiple) {
  97. return false;
  98. }
  99. return $this->hasBuchung() || $this->hasAbo();
  100. }
  101. /**
  102. * isExpired
  103. *
  104. * @return boolean
  105. *
  106. * @Assert\IsFalse(groups={"gutschein"}, message = "Der Gutscheincode ist nicht mehr gültig.")
  107. * changedFrom Assert\False
  108. */
  109. public function isExpired()
  110. {
  111. return $this->expires_at && $this->expires_at < new \DateTime('now');
  112. }
  113. /**
  114. * isBlocked
  115. *
  116. * @return boolean
  117. *
  118. * @Assert\IsFalse(groups={"gutschein"}, message = "Der Gutscheincode ist ungültig.")
  119. * changedFrom Assert\False
  120. */
  121. public function isBlocked()
  122. {
  123. if ($this->status == self::STATUS_BLOCKED ) {
  124. return true;
  125. }
  126. return false;
  127. }
  128. /**
  129. * Set code
  130. *
  131. * @param string $code
  132. * @return Gutschein
  133. */
  134. public function setCode($code)
  135. {
  136. $this->code = $code;
  137. return $this;
  138. }
  139. /**
  140. * Get code
  141. *
  142. * @return string
  143. */
  144. public function getCode()
  145. {
  146. return $this->code;
  147. }
  148. /**
  149. * Erzeugt einen zufälligen Code der Form 'xxxx-xxxx'
  150. *
  151. * @param string $postfix
  152. * @return \JF\JuridicusBundle\Entity\Gutschein
  153. */
  154. public function createCode( $postfix = false )
  155. {
  156. $max = strlen(self::$code_chars)-1;
  157. $this->code='';
  158. for ($i=0; $i<4; $i++) {
  159. $this->code .= substr(self::$code_chars,rand(0,$max),1);
  160. }
  161. $this->code .= '-';
  162. for ($i=0; $i<4; $i++) {
  163. $this->code .= substr(self::$code_chars,rand(0,$max),1);
  164. }
  165. if ( $postfix ) {
  166. $this->code .= '-'.$postfix;
  167. }
  168. return $this;
  169. }
  170. /**
  171. * Set created_at
  172. *
  173. * @param \DateTime $createdAt
  174. * @return Gutschein
  175. */
  176. public function setCreatedAt(\DateTime $createdAt = null)
  177. {
  178. $this->created_at = $createdAt;
  179. return $this;
  180. }
  181. /**
  182. * Get created_at
  183. *
  184. * @return \DateTime
  185. */
  186. public function getCreatedAt()
  187. {
  188. return $this->created_at;
  189. }
  190. /**
  191. * @ORM\PrePersist
  192. */
  193. public function setCreatedAtValue()
  194. {
  195. $this->created_at = new \DateTime();
  196. }
  197. /**
  198. * Set betrag
  199. *
  200. * @param float $betrag
  201. * @return Gutschein
  202. */
  203. public function setBetrag($betrag)
  204. {
  205. $this->betrag = $betrag;
  206. return $this;
  207. }
  208. /**
  209. * Get betrag
  210. *
  211. * @return float
  212. */
  213. public function getBetrag()
  214. {
  215. return $this->betrag;
  216. }
  217. /**
  218. *
  219. * @return string
  220. */
  221. public function __toString()
  222. {
  223. return ($this->code) ? $this->code : '';
  224. }
  225. /**
  226. * Constructor
  227. */
  228. public function __construct()
  229. {
  230. $this->buchungen = new \Doctrine\Common\Collections\ArrayCollection();
  231. $this->abos = new \Doctrine\Common\Collections\ArrayCollection();
  232. }
  233. /**
  234. * Set expires_at
  235. *
  236. * @param \DateTime $expiresAt
  237. * @return Gutschein
  238. */
  239. public function setExpiresAt(\DateTime $expiresAt = null)
  240. {
  241. $this->expires_at = $expiresAt;
  242. return $this;
  243. }
  244. /**
  245. * Get expires_at
  246. *
  247. * @return \DateTime
  248. */
  249. public function getExpiresAt()
  250. {
  251. return $this->expires_at;
  252. }
  253. /**
  254. * Set valid_zeitschrift
  255. *
  256. * @param string $validZeitschrift
  257. * @return Gutschein
  258. */
  259. public function setValidZeitschrift($validZeitschrift)
  260. {
  261. $this->valid_zeitschrift = $validZeitschrift;
  262. return $this;
  263. }
  264. /**
  265. * Get valid_zeitschrift
  266. *
  267. * @return string
  268. */
  269. public function getValidZeitschrift()
  270. {
  271. return $this->valid_zeitschrift;
  272. }
  273. /**
  274. * Set valid_online
  275. *
  276. * @param boolean $validOnline
  277. * @return Gutschein
  278. */
  279. public function setValidOnline($validOnline)
  280. {
  281. $this->valid_online = $validOnline;
  282. return $this;
  283. }
  284. /**
  285. * Get valid_online
  286. *
  287. * @return boolean
  288. */
  289. public function getValidOnline()
  290. {
  291. return $this->valid_online;
  292. }
  293. /**
  294. * Add buchungen
  295. *
  296. * @param \JF\JuridicusBundle\Entity\KundePruefung $buchung
  297. * @return Gutschein
  298. */
  299. public function addBuchungen(KundePruefung $buchung)
  300. {
  301. $this->buchungen[] = $buchung;
  302. $buchung->setGutschein($this);
  303. return $this;
  304. }
  305. /**
  306. * Remove buchungen
  307. *
  308. * @param \JF\JuridicusBundle\Entity\KundePruefung $buchung
  309. */
  310. public function removeBuchungen(KundePruefung $buchung)
  311. {
  312. $this->buchungen->removeElement($buchung);
  313. }
  314. /**
  315. * Get buchungen
  316. *
  317. * @return \Doctrine\Common\Collections\Collection
  318. */
  319. public function getBuchungen()
  320. {
  321. return $this->buchungen;
  322. }
  323. /**
  324. *
  325. * @return boolean
  326. */
  327. public function hasBuchung()
  328. {
  329. return ! $this->buchungen->isEmpty();
  330. }
  331. /**
  332. * Add abos
  333. *
  334. * @param \JF\JuridicusBundle\Entity\Abo $abo
  335. * @return Gutschein
  336. */
  337. public function addAbo(Abo $abo)
  338. {
  339. $this->abos[] = $abo;
  340. $abo->setGutschein($this);
  341. return $this;
  342. }
  343. /**
  344. * Remove abos
  345. *
  346. * @param \JF\JuridicusBundle\Entity\Abo $abo
  347. */
  348. public function removeAbo(Abo $abo)
  349. {
  350. $this->abos->removeElement($abo);
  351. }
  352. /**
  353. * Get abos
  354. *
  355. * @return \Doctrine\Common\Collections\Collection
  356. */
  357. public function getAbos()
  358. {
  359. return $this->abos;
  360. }
  361. /**
  362. *
  363. * @return boolean
  364. */
  365. public function hasAbo()
  366. {
  367. return ! $this->abos->isEmpty();
  368. }
  369. /**
  370. * Set valid_abo_typ
  371. *
  372. * @param integer $validAboTyp
  373. * @return Gutschein
  374. */
  375. public function setValidAboTyp($validAboTyp)
  376. {
  377. $this->valid_abo_typ = $validAboTyp;
  378. return $this;
  379. }
  380. /**
  381. * Get valid_abo_typ
  382. *
  383. * @return integer
  384. */
  385. public function getValidAboTyp()
  386. {
  387. return $this->valid_abo_typ;
  388. }
  389. /**
  390. * Set multiple
  391. *
  392. * @param boolean $multiple
  393. * @return Gutschein
  394. */
  395. public function setMultiple($multiple = true)
  396. {
  397. $this->multiple = $multiple;
  398. return $this;
  399. }
  400. /**
  401. * is multiple
  402. *
  403. * @return boolean
  404. */
  405. public function isMultiple()
  406. {
  407. return $this->multiple;
  408. }
  409. /**
  410. * @var string
  411. */
  412. private $bulk_slug;
  413. /**
  414. * @var string
  415. */
  416. private $status;
  417. /**
  418. * Get multiple
  419. *
  420. * @return boolean
  421. */
  422. public function getMultiple()
  423. {
  424. return $this->multiple;
  425. }
  426. /**
  427. * Set status
  428. *
  429. * @param string $status
  430. * @return Gutschein
  431. */
  432. public function setStatus($status)
  433. {
  434. $this->status = $status;
  435. $this->status_updated_at = new \DateTime();
  436. return $this;
  437. }
  438. /**
  439. * Get status
  440. *
  441. * @return string
  442. */
  443. public function getStatus()
  444. {
  445. return $this->status;
  446. }
  447. /**
  448. * @var \DateTime
  449. */
  450. private $status_updated_at;
  451. /**
  452. * Set status_updated_at
  453. *
  454. * @param \DateTime $statusUpdatedAt
  455. * @return Gutschein
  456. */
  457. public function setStatusUpdatedAt($statusUpdatedAt)
  458. {
  459. $this->status_updated_at = $statusUpdatedAt;
  460. return $this;
  461. }
  462. /**
  463. * Get status_updated_at
  464. *
  465. * @return \DateTime
  466. */
  467. public function getStatusUpdatedAt()
  468. {
  469. return $this->status_updated_at;
  470. }
  471. /**
  472. * @var \JF\JuridicusBundle\Entity\GutscheinMetadata
  473. */
  474. private $gutschein_metadata;
  475. /**
  476. * Set gutschein_metadata
  477. *
  478. * @param \JF\JuridicusBundle\Entity\GutscheinMetadata $gutscheinMetadata
  479. * @return Gutschein
  480. */
  481. public function setGutscheinMetadata(\JF\JuridicusBundle\Entity\GutscheinMetadata $gutscheinMetadata = null)
  482. {
  483. $this->gutschein_metadata = $gutscheinMetadata;
  484. return $this;
  485. }
  486. /**
  487. * Get gutschein_metadata
  488. *
  489. * @return \JF\JuridicusBundle\Entity\GutscheinMetadata
  490. */
  491. public function getGutscheinMetadata()
  492. {
  493. return $this->gutschein_metadata;
  494. }
  495. }