ECommerceProduct.php 2.32 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
<?php

namespace Doctrine\Tests\Models\ECommerce;

/**
 * ECommerceProduct
 * Represents a type of product of a shopping application.
 *
 * @author Giorgio Sironi
 * @Entity
 * @Table(name="ecommerce_products")
 */
class ECommerceProduct
{
    /**
     * @Column(type="integer")
     * @Id
     * @GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @Column(type="string", length=50)
     */
    private $name;

27 28 29 30 31 32 33 34 35 36 37
    /**
     * @OneToOne(targetEntity="ECommerceShipping", cascade={"save"})
     * @JoinColumn(name="shipping_id", referencedColumnName="id")
     */
    private $shipping;

    /**
     * @OneToMany(targetEntity="ECommerceFeature", mappedBy="product", cascade={"save"})
     */
    private $features;

38 39 40 41 42 43 44 45
    /**
     * @ManyToMany(targetEntity="ECommerceCategory", cascade={"save"})
     * @JoinTable(name="ecommerce_products_categories",
            joinColumns={{"name"="product_id", "referencedColumnName"="id"}},
            inverseJoinColumns={{"name"="category_id", "referencedColumnName"="id"}})
    private $categories;
     */

46 47 48 49 50
    public function __construct()
    {
        $this->features = new \Doctrine\Common\Collections\Collection;
    }

51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
    public function getId()
    {
        return $this->id;
    }

    public function getName()
    {
        return $this->name;
    }

    public function setName($name)
    {
        $this->name = $name;
    }

    public function getShipping()
    {
        return $this->shipping;
    }

    public function setShipping(ECommerceShipping $shipping)
    {
        $this->shipping = $shipping;
    }

    public function removeShipping()
    {
        $this->shipping = null;
    }
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96

    public function getFeatures()
    {
        return $this->features;
    }

    public function addFeature(ECommerceFeature $feature) {
        $this->features[] = $feature;
        $feature->setProduct($this);
    }

    /** does not set the owning side */
    public function brokenAddFeature(ECommerceFeature $feature) {
        $this->features[] = $feature;
    }

    public function removeFeature(ECommerceFeature $feature) {
97 98 99 100 101 102
        if ($this->features->contains($feature)) {
            $removed = $this->features->removeElement($feature);
            if ($removed) {
                $feature->removeProduct();
                return true;
            }
103 104 105
        }
        return false;
    }
106
}