/src/lib/Doctrine/Entities/Person.php

https://gitlab.com/gothcon/cthulhu · PHP · 788 lines · 309 code · 111 blank · 368 comment · 20 complexity · 3ec7d31e3dac1d3c69196937aebfe833 MD5 · raw file

  1. <?php
  2. namespace Entities;
  3. use UserAccessor;
  4. use UserLevel;
  5. /**
  6. * Person
  7. */
  8. class Person
  9. {
  10. /**
  11. * @var string
  12. */
  13. private $firstName;
  14. /**
  15. * @var string
  16. */
  17. private $lastName;
  18. /**
  19. * @var string
  20. */
  21. private $emailAddress;
  22. /**
  23. * @var boolean
  24. */
  25. private $emailIsPublic;
  26. /**
  27. * @var \DateTime
  28. */
  29. private $createdAt;
  30. /**
  31. * @var string
  32. */
  33. private $createdBy;
  34. /**
  35. * @var \DateTime
  36. */
  37. private $modifiedAt;
  38. /**
  39. * @var string
  40. */
  41. private $modifiedBy;
  42. /**
  43. * @var boolean
  44. */
  45. private $isDeleted;
  46. /**
  47. * @var string
  48. */
  49. private $phoneNumber;
  50. /**
  51. * @var string
  52. */
  53. private $identification;
  54. /**
  55. * @var string
  56. */
  57. private $streetAddress;
  58. /**
  59. * @var string
  60. */
  61. private $zip;
  62. /**
  63. * @var string
  64. */
  65. private $city;
  66. /**
  67. * @var string
  68. */
  69. private $country;
  70. /**
  71. * @var string
  72. */
  73. private $foreignAddress;
  74. /**
  75. * @var string
  76. */
  77. private $note;
  78. /**
  79. * @var string
  80. */
  81. private $internalNote;
  82. /**
  83. * @var integer
  84. */
  85. private $isOutdated;
  86. /**
  87. * @var integer
  88. */
  89. private $xp;
  90. /**
  91. * @var integer
  92. */
  93. private $id;
  94. /**
  95. * @var \Entities\User
  96. */
  97. private $user;
  98. /**
  99. * @var \Doctrine\Common\Collections\Collection
  100. */
  101. private $signups;
  102. /**
  103. * Constructor
  104. */
  105. public function __construct()
  106. {
  107. $this->signups = new \Doctrine\Common\Collections\ArrayCollection();
  108. }
  109. /**
  110. * Set firstName
  111. *
  112. * @param string $firstName
  113. * @return Person
  114. */
  115. public function setFirstName($firstName)
  116. {
  117. $this->firstName = $firstName;
  118. return $this;
  119. }
  120. /**
  121. * Get firstName
  122. *
  123. * @return string
  124. */
  125. public function getFirstName()
  126. {
  127. return $this->firstName;
  128. }
  129. /**
  130. * Set lastName
  131. *
  132. * @param string $lastName
  133. * @return Person
  134. */
  135. public function setLastName($lastName)
  136. {
  137. $this->lastName = $lastName;
  138. return $this;
  139. }
  140. /**
  141. * Get lastName
  142. *
  143. * @return string
  144. */
  145. public function getLastName()
  146. {
  147. return $this->lastName;
  148. }
  149. /**
  150. * Set emailAddress
  151. *
  152. * @param string $emailAddress
  153. * @return Person
  154. */
  155. public function setEmailAddress($emailAddress)
  156. {
  157. $this->emailAddress = $emailAddress;
  158. return $this;
  159. }
  160. /**
  161. * Get emailAddress
  162. *
  163. * @return string
  164. */
  165. public function getEmailAddress()
  166. {
  167. return $this->emailAddress;
  168. }
  169. /**
  170. * Set emailIsPublic
  171. *
  172. * @param boolean $emailIsPublic
  173. * @return Person
  174. */
  175. public function setEmailIsPublic($emailIsPublic)
  176. {
  177. $this->emailIsPublic = $emailIsPublic;
  178. return $this;
  179. }
  180. /**
  181. * Get emailIsPublic
  182. *
  183. * @return boolean
  184. */
  185. public function getEmailIsPublic()
  186. {
  187. return $this->emailIsPublic;
  188. }
  189. /**
  190. * Set createdAt
  191. *
  192. * @param \DateTime $createdAt
  193. * @return Person
  194. */
  195. public function setCreatedAt($createdAt)
  196. {
  197. $this->createdAt = $createdAt;
  198. return $this;
  199. }
  200. /**
  201. * Get createdAt
  202. *
  203. * @return \DateTime
  204. */
  205. public function getCreatedAt()
  206. {
  207. return $this->createdAt;
  208. }
  209. /**
  210. * Set createdBy
  211. *
  212. * @param string $createdBy
  213. * @return Person
  214. */
  215. public function setCreatedBy($createdBy)
  216. {
  217. $this->createdBy = $createdBy;
  218. return $this;
  219. }
  220. /**
  221. * Get createdBy
  222. *
  223. * @return string
  224. */
  225. public function getCreatedBy()
  226. {
  227. return $this->createdBy;
  228. }
  229. /**
  230. * Set modifiedAt
  231. *
  232. * @param \DateTime $modifiedAt
  233. * @return Person
  234. */
  235. public function setModifiedAt($modifiedAt)
  236. {
  237. $this->modifiedAt = $modifiedAt;
  238. return $this;
  239. }
  240. /**
  241. * Get modifiedAt
  242. *
  243. * @return \DateTime
  244. */
  245. public function getModifiedAt()
  246. {
  247. return $this->modifiedAt;
  248. }
  249. /**
  250. * Set modifiedBy
  251. *
  252. * @param string $modifiedBy
  253. * @return Person
  254. */
  255. public function setModifiedBy($modifiedBy)
  256. {
  257. $this->modifiedBy = $modifiedBy;
  258. return $this;
  259. }
  260. /**
  261. * Get modifiedBy
  262. *
  263. * @return string
  264. */
  265. public function getModifiedBy()
  266. {
  267. return $this->modifiedBy;
  268. }
  269. /**
  270. * Set isDeleted
  271. *
  272. * @param boolean $isDeleted
  273. * @return Person
  274. */
  275. public function setIsDeleted($isDeleted)
  276. {
  277. $this->isDeleted = $isDeleted;
  278. return $this;
  279. }
  280. /**
  281. * Get isDeleted
  282. *
  283. * @return boolean
  284. */
  285. public function getIsDeleted()
  286. {
  287. return $this->isDeleted;
  288. }
  289. /**
  290. * Set phoneNumber
  291. *
  292. * @param string $phoneNumber
  293. * @return Person
  294. */
  295. public function setPhoneNumber($phoneNumber)
  296. {
  297. $this->phoneNumber = $phoneNumber;
  298. return $this;
  299. }
  300. /**
  301. * Get phoneNumber
  302. *
  303. * @return string
  304. */
  305. public function getPhoneNumber()
  306. {
  307. return $this->phoneNumber;
  308. }
  309. /**
  310. * Set identification
  311. *
  312. * @param string $identification
  313. * @return Person
  314. */
  315. public function setIdentification($identification)
  316. {
  317. $identification = str_replace(array(" ","-"),"",$identification);
  318. if(strlen($identification)){
  319. if(!preg_match("/^[0-9]{6}[0-9]{4}$/",$identification)){
  320. throw new \Exception("Incorrect format");
  321. }
  322. }
  323. $this->identification = $identification;
  324. return $this;
  325. }
  326. /**
  327. * Get identification
  328. *
  329. * @return string
  330. */
  331. public function getIdentification()
  332. {
  333. return $this->identification;
  334. }
  335. /**
  336. * Set streetAddress
  337. *
  338. * @param string $streetAddress
  339. * @return Person
  340. */
  341. public function setStreetAddress($streetAddress)
  342. {
  343. $this->streetAddress = $streetAddress;
  344. return $this;
  345. }
  346. /**
  347. * Get streetAddress
  348. *
  349. * @return string
  350. */
  351. public function getStreetAddress()
  352. {
  353. return $this->streetAddress;
  354. }
  355. /**
  356. * Set zip
  357. *
  358. * @param string $zip
  359. * @return Person
  360. */
  361. public function setZip($zip)
  362. {
  363. $this->zip = $zip;
  364. return $this;
  365. }
  366. /**
  367. * Get zip
  368. *
  369. * @return string
  370. */
  371. public function getZip()
  372. {
  373. return $this->zip;
  374. }
  375. /**
  376. * Set city
  377. *
  378. * @param string $city
  379. * @return Person
  380. */
  381. public function setCity($city)
  382. {
  383. $this->city = $city;
  384. return $this;
  385. }
  386. /**
  387. * Get city
  388. *
  389. * @return string
  390. */
  391. public function getCity()
  392. {
  393. return $this->city;
  394. }
  395. /**
  396. * Set country
  397. *
  398. * @param string $country
  399. * @return Person
  400. */
  401. public function setCountry($country)
  402. {
  403. $this->country = $country;
  404. return $this;
  405. }
  406. /**
  407. * Get country
  408. *
  409. * @return string
  410. */
  411. public function getCountry()
  412. {
  413. return $this->country;
  414. }
  415. /**
  416. * Set foreignAddress
  417. *
  418. * @param string $foreignAddress
  419. * @return Person
  420. */
  421. public function setForeignAddress($foreignAddress)
  422. {
  423. $this->foreignAddress = $foreignAddress;
  424. return $this;
  425. }
  426. /**
  427. * Get foreignAddress
  428. *
  429. * @return string
  430. */
  431. public function getForeignAddress()
  432. {
  433. return $this->foreignAddress;
  434. }
  435. /**
  436. * Set note
  437. *
  438. * @param string $note
  439. * @return Person
  440. */
  441. public function setNote($note)
  442. {
  443. $this->note = $note;
  444. return $this;
  445. }
  446. /**
  447. * Get note
  448. *
  449. * @return string
  450. */
  451. public function getNote()
  452. {
  453. return $this->note;
  454. }
  455. /**
  456. * Set internalNote
  457. *
  458. * @param string $internalNote
  459. * @return Person
  460. */
  461. public function setInternalNote($internalNote)
  462. {
  463. if(UserAccessor::currentUserHasAccess(UserLevel::STAFF))
  464. $this->internalNote = $internalNote;
  465. else
  466. throw new Exception("Cannot set internal note, user has no access");
  467. return $this;
  468. }
  469. /**
  470. * Get internalNote
  471. *
  472. * @return string
  473. */
  474. public function getInternalNote()
  475. {
  476. if(UserAccessor::currentUserHasAccess(UserLevel::STAFF))
  477. return $this->internalNote;
  478. else
  479. return "Ingen åtkomst";
  480. }
  481. /**
  482. * Set isOutdated
  483. *
  484. * @param integer $isOutdated
  485. * @return Person
  486. */
  487. public function setIsOutdated($isOutdated)
  488. {
  489. $this->isOutdated = $isOutdated;
  490. return $this;
  491. }
  492. /**
  493. * Get isOutdated
  494. *
  495. * @return integer
  496. */
  497. public function getIsOutdated()
  498. {
  499. return $this->isOutdated;
  500. }
  501. /**
  502. * Set xp
  503. *
  504. * @param integer $xp
  505. * @return Person
  506. */
  507. public function setXp($xp)
  508. {
  509. $this->xp = $xp;
  510. return $this;
  511. }
  512. /**
  513. * Get xp
  514. *
  515. * @return integer
  516. */
  517. public function getXp()
  518. {
  519. return $this->xp;
  520. }
  521. /**
  522. * Get id
  523. *
  524. * @return integer
  525. */
  526. public function getId()
  527. {
  528. return $this->id;
  529. }
  530. /**
  531. * Set user
  532. *
  533. * @param \Entities\User $user
  534. * @return Person
  535. */
  536. public function setUser(\Entities\User $user = null)
  537. {
  538. $this->user = $user;
  539. if($user != null)
  540. $user->setPerson($this);
  541. return $this;
  542. }
  543. /**
  544. * Get user
  545. *
  546. * @return \Entities\User
  547. */
  548. public function getUser()
  549. {
  550. return $this->user;
  551. }
  552. /**
  553. * Add signups
  554. *
  555. * @param \Entities\Signup $signups
  556. * @return Person
  557. */
  558. public function addSignup(\Entities\Signup $signups)
  559. {
  560. $this->signups[] = $signups;
  561. return $this;
  562. }
  563. /**
  564. * Remove signups
  565. *
  566. * @param \Entities\Signup $signups
  567. */
  568. public function removeSignup(\Entities\Signup $signups)
  569. {
  570. $this->signups->removeElement($signups);
  571. }
  572. /**
  573. * Get signups
  574. *
  575. * @return \Doctrine\Common\Collections\Collection
  576. */
  577. public function getSignups()
  578. {
  579. return $this->signups;
  580. }
  581. /**
  582. * @var \Doctrine\Common\Collections\Collection
  583. */
  584. private $groupMemberships;
  585. /**
  586. * Add groupMemberships
  587. *
  588. * @param \Entities\Signup $groupMemberships
  589. * @return Person
  590. */
  591. public function addGroupMembership(\Entities\Signup $groupMemberships)
  592. {
  593. $this->groupMemberships[] = $groupMemberships;
  594. return $this;
  595. }
  596. /**
  597. * Remove groupMemberships
  598. *
  599. * @param \Entities\Signup $groupMemberships
  600. */
  601. public function removeGroupMembership(\Entities\Signup $groupMemberships)
  602. {
  603. $this->groupMemberships->removeElement($groupMemberships);
  604. }
  605. /**
  606. * Get groupMemberships
  607. *
  608. * @return \Doctrine\Common\Collections\Collection
  609. */
  610. public function getGroupMemberships()
  611. {
  612. return $this->groupMemberships;
  613. }
  614. /**
  615. * @ORM\PrePersist
  616. */
  617. public function onPrePersist()
  618. {
  619. // Add your code here
  620. }
  621. /**
  622. * @ORM\PreUpdate
  623. */
  624. public function onPreUpdate(\Doctrine\ORM\Event\PreUpdateEventArgs $eventArgs)
  625. {
  626. $person = $eventArgs->getEntity();
  627. if($eventArgs->hasChangedField("identification")){
  628. $personIdentification = $person->getIdentification();
  629. if($personIdentification != ""){
  630. $person = \Repository\PersonRepository::personByIdentification($personIdentification);
  631. if($person != null){
  632. $person = $person[0];
  633. throw new \Exception("Personnummret är registrerat på ". $person->getId() .". " . $person->getFirstName(). " " .$person->getLastName());
  634. }
  635. }
  636. }
  637. if($eventArgs->hasChangedField("emailAddress") && strlen($person->getEmailAddress())){
  638. $tempPerson = \Repository\PersonRepository::personByEmailAddress($person->getEmailAddress());
  639. if($tempPerson != null && $person->getId() != $tempPerson->getId()){
  640. throw new \Exception("Epostadressen är redan registrerat på ". $tempPerson->getId() .". " . $tempPerson->getFirstName(). " " .$tempPerson->getLastName());
  641. }
  642. }
  643. if($eventArgs->hasChangedField("level") || $eventArgs->hasChangedField("username")){
  644. if(! \UserAccessor::currentUserHasAccess(\UserLevel::STAFF)){
  645. throw new Exception("User is not authorized to update level or username");
  646. }
  647. }
  648. }
  649. /**
  650. * @var \Entities\SleepingSlotBooking
  651. */
  652. private $sleepingSlotBooking;
  653. /**
  654. * Set sleepingSlotBooking
  655. *
  656. * @param \Entities\SleepingSlotBooking $sleepingSlotBooking
  657. * @return Person
  658. */
  659. public function setSleepingSlotBooking($sleepingSlotBooking = null)
  660. {
  661. $this->sleepingSlotBooking = $sleepingSlotBooking;
  662. return $this;
  663. }
  664. /**
  665. * Get sleepingSlotBooking
  666. *
  667. * @return \Entities\SleepingSlotBooking
  668. */
  669. public function getSleepingSlotBooking()
  670. {
  671. return $this->sleepingSlotBooking;
  672. }
  673. public function __toString(){
  674. // die(print_r($this));
  675. return json_encode($this);
  676. }
  677. }