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