3 namespace Doctrine\Tests\Models\ECommerce;
5 use Doctrine\Common\Collections\ArrayCollection;
9 * Represents a type of product of a shopping application.
11 * @author Giorgio Sironi
13 * @Table(name="ecommerce_products",indexes={@Index(name="name_idx", columns={"name"})})
15 class ECommerceProduct
18 * @Column(type="integer")
25 * @Column(type="string", length=50, nullable=true)
30 * @OneToOne(targetEntity="ECommerceShipping", cascade={"persist"})
31 * @JoinColumn(name="shipping_id", referencedColumnName="id")
36 * @OneToMany(targetEntity="ECommerceFeature", mappedBy="product", cascade={"persist"})
41 * @ManyToMany(targetEntity="ECommerceCategory", cascade={"persist"}, inversedBy="products")
42 * @JoinTable(name="ecommerce_products_categories",
43 * joinColumns={@JoinColumn(name="product_id", referencedColumnName="id")},
44 * inverseJoinColumns={@JoinColumn(name="category_id", referencedColumnName="id")})
49 * This relation is saved with two records in the association table for
51 * @ManyToMany(targetEntity="ECommerceProduct", cascade={"persist"})
52 * @JoinTable(name="ecommerce_products_related",
53 * joinColumns={@JoinColumn(name="product_id", referencedColumnName="id")},
54 * inverseJoinColumns={@JoinColumn(name="related_id", referencedColumnName="id")})
58 public $isCloned = false;
59 public $wakeUp = false;
61 public function __construct()
63 $this->features = new ArrayCollection;
64 $this->categories = new ArrayCollection;
65 $this->related = new ArrayCollection;
68 public function getId()
73 public function getName()
78 public function setName($name)
83 public function getShipping()
85 return $this->shipping;
88 public function setShipping(ECommerceShipping $shipping)
90 $this->shipping = $shipping;
93 public function removeShipping()
95 $this->shipping = null;
98 public function getFeatures()
100 return $this->features;
103 public function addFeature(ECommerceFeature $feature)
105 $this->features[] = $feature;
106 $feature->setProduct($this);
109 /** does not set the owning side */
110 public function brokenAddFeature(ECommerceFeature $feature)
112 $this->features[] = $feature;
115 public function removeFeature(ECommerceFeature $feature)
117 $removed = $this->features->removeElement($feature);
119 $feature->removeProduct();
124 public function addCategory(ECommerceCategory $category)
126 if (!$this->categories->contains($category)) {
127 $this->categories[] = $category;
128 $category->addProduct($this);
132 public function removeCategory(ECommerceCategory $category)
134 $removed = $this->categories->removeElement($category);
136 $category->removeProduct($this);
140 public function getCategories()
142 return $this->categories;
145 public function getRelated()
147 return $this->related;
150 public function addRelated(ECommerceProduct $related)
152 if (!$this->related->contains($related)) {
153 $this->related[] = $related;
154 $related->addRelated($this);
158 public function removeRelated(ECommerceProduct $related)
160 $removed = $this->related->removeElement($related);
162 $related->removeRelated($this);
166 public function __clone()
168 $this->isCloned = true;
172 * Testing docblock contents here
174 public function __wakeup()
176 $this->wakeUp = true;