Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / orm / tests / Doctrine / Tests / Models / ECommerce / ECommerceCategory.php
1 <?php
2
3 namespace Doctrine\Tests\Models\ECommerce;
4
5 use Doctrine\Common\Collections\ArrayCollection;
6
7 /**
8  * ECommerceCategory
9  * Represents a tag applied on particular products.
10  *
11  * @author Giorgio Sironi
12  * @Entity
13  * @Table(name="ecommerce_categories")
14  */
15 class ECommerceCategory
16 {
17     /**
18      * @Id @Column(type="integer")
19      * @GeneratedValue(strategy="AUTO")
20      */
21     private $id;
22
23     /**
24      * @Column(type="string", length=50)
25      */
26     private $name;
27
28     /**
29      * @ManyToMany(targetEntity="ECommerceProduct", mappedBy="categories")
30      */
31     private $products;
32
33     /**
34      * @OneToMany(targetEntity="ECommerceCategory", mappedBy="parent", cascade={"persist"})
35      */
36     private $children;
37
38     /**
39      * @ManyToOne(targetEntity="ECommerceCategory", inversedBy="children")
40      * @JoinColumn(name="parent_id", referencedColumnName="id")
41      */
42     private $parent;
43
44     public function __construct()
45     {
46         $this->products = new ArrayCollection();
47         $this->children = new ArrayCollection();
48     }
49
50     public function getId()
51     {
52         return $this->id;
53     }
54
55     public function getName()
56     {
57         return $this->name;
58     }
59
60     public function setName($name)
61     {
62         $this->name = $name;
63     }
64
65     public function addProduct(ECommerceProduct $product)
66     {
67         if (!$this->products->contains($product)) {
68             $this->products[] = $product;
69             $product->addCategory($this);
70         }
71     }
72
73     public function removeProduct(ECommerceProduct $product)
74     {
75         $removed = $this->products->removeElement($product);
76         if ($removed) {
77             $product->removeCategory($this);
78         }
79     }
80
81     public function getProducts()
82     {
83         return $this->products;
84     }
85
86     private function setParent(ECommerceCategory $parent)
87     {
88         $this->parent = $parent;
89     }
90
91     public function getChildren()
92     {
93         return $this->children;
94     }
95
96     public function getParent()
97     {
98         return $this->parent;
99     }
100
101     public function addChild(ECommerceCategory $child)
102     {
103         $this->children[] = $child;
104         $child->setParent($this);
105     }
106
107     /** does not set the owning side. */
108     public function brokenAddChild(ECommerceCategory $child)
109     {
110         $this->children[] = $child;
111     }
112
113
114     public function removeChild(ECommerceCategory $child)
115     {
116         $removed = $this->children->removeElement($child);
117         if ($removed) {
118             $child->removeParent();
119         }
120     }
121
122     private function removeParent()
123     {
124         $this->parent = null;
125     }
126 }