Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / orm / tests / Doctrine / Tests / Models / ECommerce / ECommerceCart.php
1 <?php
2
3 namespace Doctrine\Tests\Models\ECommerce;
4
5 use Doctrine\Common\Collections\ArrayCollection;
6
7 /**
8  * ECommerceCart
9  * Represents a typical cart of a shopping application.
10  *
11  * @author Giorgio Sironi
12  * @Entity
13  * @Table(name="ecommerce_carts")
14  */
15 class ECommerceCart
16 {
17     /**
18      * @Column(type="integer")
19      * @Id
20      * @GeneratedValue
21      */
22     private $id;
23
24     /**
25      * @Column(length=50, nullable=true)
26      */
27     private $payment;
28
29     /**
30      * @OneToOne(targetEntity="ECommerceCustomer", inversedBy="cart")
31      * @JoinColumn(name="customer_id", referencedColumnName="id")
32      */
33     private $customer;
34
35     /**
36      * @ManyToMany(targetEntity="ECommerceProduct", cascade={"persist"})
37      * @JoinTable(name="ecommerce_carts_products",
38             joinColumns={@JoinColumn(name="cart_id", referencedColumnName="id")},
39             inverseJoinColumns={@JoinColumn(name="product_id", referencedColumnName="id")})
40      */
41     private $products;
42
43     public function __construct()
44     {
45         $this->products = new ArrayCollection;
46     }
47
48     public function getId() {
49         return $this->id;
50     }
51
52     public function getPayment() {
53         return $this->payment;
54     }
55
56     public function setPayment($payment) {
57         $this->payment = $payment;
58     }
59
60     public function setCustomer(ECommerceCustomer $customer) {
61         if ($this->customer !== $customer) {
62             $this->customer = $customer;
63             $customer->setCart($this);
64         }
65     }
66
67     public function removeCustomer() {
68         if ($this->customer !== null) {
69             $customer = $this->customer;
70             $this->customer = null;
71             $customer->removeCart();
72         }
73     }
74
75     public function getCustomer() {
76         return $this->customer;
77     }
78
79     public function getProducts()
80     {
81         return $this->products;
82     }
83
84     public function addProduct(ECommerceProduct $product) {
85         $this->products[] = $product;
86     }
87
88     public function removeProduct(ECommerceProduct $product) {
89         return $this->products->removeElement($product);
90     }
91 }