Guest User

Untitled

a guest
Jan 19th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.39 KB | None | 0 0
  1. <?php
  2. use Doctrine\Common\Collections\ArrayCollection;
  3.  
  4. /**
  5. * @Entity @Table(name="User")
  6. */
  7. class User
  8. {
  9. /**
  10. * @Id @Column(type="integer") @GeneratedValue
  11. * @var integer
  12. */
  13. private $id;
  14. /**
  15. * @Column()
  16. * @var string
  17. */
  18. private $username;
  19. /**
  20. * @Column()
  21. * @var string
  22. */
  23. private $password;
  24. /**
  25. * @Column()
  26. * @var string
  27. */
  28. private $email;
  29.  
  30. /**
  31. * @Column()
  32. * @var string
  33. */
  34. private $verificationcode;
  35. /**
  36. * @Column(length="2")
  37. * @var integer
  38. */
  39. private $status; // logged in? Banned?
  40. /**
  41. * @Column()
  42. * @var string
  43. */
  44. private $ip;
  45.  
  46. /**
  47. * NOT-OWNING SIDE
  48. * @OneToMany(targetEntity="Transaction", mappedBy="user", cascade={"persist"})
  49. * @var array List of transactions
  50. */
  51. private $transactions;
  52.  
  53. /****************************************************************************/
  54.  
  55. public function __construct() {
  56. $this->transactions = new \Doctrine\Common\Collections\ArrayCollection;
  57. }
  58.  
  59. public function getId() { return $this->id; }
  60.  
  61. public function getUsername() { return $this->username; }
  62. public function setUsername($username) { $this->username = $username; }
  63.  
  64. public function getPassword() { return $this->password; }
  65. public function setPassword($password) { $this->password = $password; }
  66.  
  67. public function getEmail() { return $this->email; }
  68. public function setEmail($email) { $this->email = $email; }
  69.  
  70. public function getVerificationcode() { return $this->verificationcode; }
  71. public function setVerificationcode($verificationcode) { $this->verificationcode = $verificationcode; }
  72.  
  73. public function getStatus() { return $this->status; }
  74. public function setStatus($status) { $this->status = $status; }
  75.  
  76. public function getIp() { return $this->ip; }
  77. public function setIp($ip) { $this->ip = $ip; }
  78.  
  79. public function addTransaction(Transaction $transaction) {
  80. $transaction->setUser($this->getId());
  81. $this->transactions[] = $transaction;
  82. }
  83. public function getTransactions() { return $this->transactions; }
  84. public function getTransaction($index) { return $this->transactions[$index]; }
  85.  
  86. }
  87.  
  88.  
  89. /**
  90. * @Entity @Table(name="Transaction")
  91. */
  92. class Transaction
  93. {
  94. /**
  95. * @ID @Column(type = "integer") @GeneratedValue
  96. *
  97. * @var integer
  98. */
  99. private $id;
  100.  
  101. /**
  102. * OWNING SIDE because it's the Many part
  103. * @ManyToOne(targetEntity="User", inversedBy="transactions")
  104. *
  105. * @var integer
  106. */
  107. private $user;
  108.  
  109. /**
  110. * @Column
  111. *
  112. * @var string
  113. */
  114. private $message;
  115.  
  116. /***************************************************************/
  117.  
  118. public function getMessage() { return $this->message; }
  119. public function setMessage($message) { $this->message = $message; }
  120.  
  121. public function setUser($user) { $this->user = $user; }
  122.  
  123. }
  124.  
  125.  
  126. // calling code:
  127. $oUser = $em->find('User', 1);
  128.  
  129. $oTransaction = new Transaction();
  130. $oTransaction->setMessage('Test ' . date("H:i:s"));
  131.  
  132. $oUser->addTransaction($oTransaction);
  133.  
  134. $em->persist($oUser);
  135. $em->flush();
Add Comment
Please, Sign In to add comment