ECommerceProduct.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <?php
  2. namespace Doctrine\Tests\Models\ECommerce;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. /**
  5. * ECommerceProduct
  6. * Represents a type of product of a shopping application.
  7. *
  8. * @author Giorgio Sironi
  9. * @Entity
  10. * @Table(name="ecommerce_products",indexes={@Index(name="name_idx", columns={"name"})})
  11. */
  12. class ECommerceProduct
  13. {
  14. /**
  15. * @Column(type="integer")
  16. * @Id
  17. * @GeneratedValue
  18. */
  19. private $id;
  20. /**
  21. * @Column(type="string", length=50, nullable=true)
  22. */
  23. private $name;
  24. /**
  25. * @OneToOne(targetEntity="ECommerceShipping", cascade={"persist"})
  26. * @JoinColumn(name="shipping_id", referencedColumnName="id")
  27. */
  28. private $shipping;
  29. /**
  30. * @OneToMany(targetEntity="ECommerceFeature", mappedBy="product", cascade={"persist"})
  31. */
  32. private $features;
  33. /**
  34. * @ManyToMany(targetEntity="ECommerceCategory", cascade={"persist"}, inversedBy="products")
  35. * @JoinTable(name="ecommerce_products_categories",
  36. * joinColumns={@JoinColumn(name="product_id", referencedColumnName="id")},
  37. * inverseJoinColumns={@JoinColumn(name="category_id", referencedColumnName="id")})
  38. */
  39. private $categories;
  40. /**
  41. * This relation is saved with two records in the association table for
  42. * simplicity.
  43. * @ManyToMany(targetEntity="ECommerceProduct", cascade={"persist"})
  44. * @JoinTable(name="ecommerce_products_related",
  45. * joinColumns={@JoinColumn(name="product_id", referencedColumnName="id")},
  46. * inverseJoinColumns={@JoinColumn(name="related_id", referencedColumnName="id")})
  47. */
  48. private $related;
  49. public $isCloned = false;
  50. public $wakeUp = false;
  51. public function __construct()
  52. {
  53. $this->features = new ArrayCollection;
  54. $this->categories = new ArrayCollection;
  55. $this->related = new ArrayCollection;
  56. }
  57. public function getId()
  58. {
  59. return $this->id;
  60. }
  61. public function getName()
  62. {
  63. return $this->name;
  64. }
  65. public function setName($name)
  66. {
  67. $this->name = $name;
  68. }
  69. public function getShipping()
  70. {
  71. return $this->shipping;
  72. }
  73. public function setShipping(ECommerceShipping $shipping)
  74. {
  75. $this->shipping = $shipping;
  76. }
  77. public function removeShipping()
  78. {
  79. $this->shipping = null;
  80. }
  81. public function getFeatures()
  82. {
  83. return $this->features;
  84. }
  85. public function addFeature(ECommerceFeature $feature)
  86. {
  87. $this->features[] = $feature;
  88. $feature->setProduct($this);
  89. }
  90. /** does not set the owning side */
  91. public function brokenAddFeature(ECommerceFeature $feature)
  92. {
  93. $this->features[] = $feature;
  94. }
  95. public function removeFeature(ECommerceFeature $feature)
  96. {
  97. $removed = $this->features->removeElement($feature);
  98. if ($removed) {
  99. $feature->removeProduct();
  100. }
  101. return $removed;
  102. }
  103. public function addCategory(ECommerceCategory $category)
  104. {
  105. if (!$this->categories->contains($category)) {
  106. $this->categories[] = $category;
  107. $category->addProduct($this);
  108. }
  109. }
  110. public function removeCategory(ECommerceCategory $category)
  111. {
  112. $removed = $this->categories->removeElement($category);
  113. if ($removed) {
  114. $category->removeProduct($this);
  115. }
  116. }
  117. public function getCategories()
  118. {
  119. return $this->categories;
  120. }
  121. public function getRelated()
  122. {
  123. return $this->related;
  124. }
  125. public function addRelated(ECommerceProduct $related)
  126. {
  127. if (!$this->related->contains($related)) {
  128. $this->related[] = $related;
  129. $related->addRelated($this);
  130. }
  131. }
  132. public function removeRelated(ECommerceProduct $related)
  133. {
  134. $removed = $this->related->removeElement($related);
  135. if ($removed) {
  136. $related->removeRelated($this);
  137. }
  138. }
  139. public function __clone()
  140. {
  141. $this->isCloned = true;
  142. }
  143. /**
  144. * Testing docblock contents here
  145. */
  146. public function __wakeup()
  147. {
  148. $this->wakeUp = true;
  149. }
  150. }