ECommerceCustomer.php 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace Doctrine\Tests\Models\ECommerce;
  3. /**
  4. * ECommerceCustomer
  5. * Represents a registered user of a shopping application.
  6. *
  7. * @author Giorgio Sironi
  8. * @Entity
  9. * @Table(name="ecommerce_customers")
  10. */
  11. class ECommerceCustomer
  12. {
  13. /**
  14. * @Column(type="integer")
  15. * @Id
  16. * @GeneratedValue(strategy="AUTO")
  17. */
  18. private $id;
  19. /**
  20. * @Column(type="string", length=50)
  21. */
  22. private $name;
  23. /**
  24. * @OneToOne(targetEntity="ECommerceCart", mappedBy="customer", cascade={"persist"})
  25. */
  26. private $cart;
  27. /**
  28. * Example of a one-one self referential association. A mentor can follow
  29. * only one customer at the time, while a customer can choose only one
  30. * mentor. Not properly appropriate but it works.
  31. *
  32. * @OneToOne(targetEntity="ECommerceCustomer", cascade={"persist"}, fetch="EAGER")
  33. * @JoinColumn(name="mentor_id", referencedColumnName="id")
  34. */
  35. private $mentor;
  36. public function getId() {
  37. return $this->id;
  38. }
  39. public function getName() {
  40. return $this->name;
  41. }
  42. public function setName($name) {
  43. $this->name = $name;
  44. }
  45. public function setCart(ECommerceCart $cart)
  46. {
  47. if ($this->cart !== $cart) {
  48. $this->cart = $cart;
  49. $cart->setCustomer($this);
  50. }
  51. }
  52. /* Does not properly maintain the bidirectional association! */
  53. public function brokenSetCart(ECommerceCart $cart) {
  54. $this->cart = $cart;
  55. }
  56. public function getCart() {
  57. return $this->cart;
  58. }
  59. public function removeCart()
  60. {
  61. if ($this->cart !== null) {
  62. $cart = $this->cart;
  63. $this->cart = null;
  64. $cart->removeCustomer();
  65. }
  66. }
  67. public function setMentor(ECommerceCustomer $mentor)
  68. {
  69. $this->mentor = $mentor;
  70. }
  71. public function removeMentor()
  72. {
  73. $this->mentor = null;
  74. }
  75. public function getMentor()
  76. {
  77. return $this->mentor;
  78. }
  79. }