2009-07-01 16:03:41 +04:00
|
|
|
<?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;
|
|
|
|
|
|
|
|
/**
|
2009-07-02 13:37:59 +04:00
|
|
|
* @Column(type="string", length=50, nullable="true")
|
2009-07-01 16:03:41 +04:00
|
|
|
*/
|
|
|
|
private $name;
|
|
|
|
|
2009-07-01 17:11:45 +04:00
|
|
|
/**
|
|
|
|
* @OneToOne(targetEntity="ECommerceShipping", cascade={"save"})
|
|
|
|
* @JoinColumn(name="shipping_id", referencedColumnName="id")
|
|
|
|
*/
|
|
|
|
private $shipping;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @OneToMany(targetEntity="ECommerceFeature", mappedBy="product", cascade={"save"})
|
|
|
|
*/
|
|
|
|
private $features;
|
|
|
|
|
2009-07-01 16:03:41 +04:00
|
|
|
/**
|
|
|
|
* @ManyToMany(targetEntity="ECommerceCategory", cascade={"save"})
|
|
|
|
* @JoinTable(name="ecommerce_products_categories",
|
|
|
|
joinColumns={{"name"="product_id", "referencedColumnName"="id"}},
|
|
|
|
inverseJoinColumns={{"name"="category_id", "referencedColumnName"="id"}})
|
|
|
|
*/
|
2009-07-02 13:37:59 +04:00
|
|
|
private $categories;
|
2009-07-01 16:03:41 +04:00
|
|
|
|
2009-07-02 11:47:24 +04:00
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->features = new \Doctrine\Common\Collections\Collection;
|
2009-07-02 13:37:59 +04:00
|
|
|
$this->categories = new \Doctrine\Common\Collections\Collection;
|
2009-07-02 11:47:24 +04:00
|
|
|
}
|
|
|
|
|
2009-07-01 16:03:41 +04:00
|
|
|
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;
|
|
|
|
}
|
2009-07-01 17:11:45 +04:00
|
|
|
|
|
|
|
public function getFeatures()
|
|
|
|
{
|
|
|
|
return $this->features;
|
|
|
|
}
|
|
|
|
|
2009-07-02 13:37:59 +04:00
|
|
|
public function addFeature(ECommerceFeature $feature)
|
|
|
|
{
|
2009-07-01 17:11:45 +04:00
|
|
|
$this->features[] = $feature;
|
|
|
|
$feature->setProduct($this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** does not set the owning side */
|
2009-07-02 13:37:59 +04:00
|
|
|
public function brokenAddFeature(ECommerceFeature $feature)
|
|
|
|
{
|
2009-07-01 17:11:45 +04:00
|
|
|
$this->features[] = $feature;
|
|
|
|
}
|
|
|
|
|
2009-07-02 13:37:59 +04:00
|
|
|
public function removeFeature(ECommerceFeature $feature)
|
|
|
|
{
|
2009-07-02 11:47:24 +04:00
|
|
|
if ($this->features->contains($feature)) {
|
|
|
|
$removed = $this->features->removeElement($feature);
|
|
|
|
if ($removed) {
|
|
|
|
$feature->removeProduct();
|
|
|
|
return true;
|
|
|
|
}
|
2009-07-01 17:11:45 +04:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2009-07-02 13:37:59 +04:00
|
|
|
|
|
|
|
public function addCategory(ECommerceCategory $category)
|
|
|
|
{
|
|
|
|
if (!$this->categories->contains($category)) {
|
|
|
|
$this->categories[] = $category;
|
|
|
|
$category->addProduct($this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function removeCategory(ECommerceCategory $category)
|
|
|
|
{
|
|
|
|
if ($this->categories->contains($category)) {
|
|
|
|
$this->categories->removeElement($category);
|
|
|
|
$category->removeProduct($this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCategories()
|
|
|
|
{
|
|
|
|
return $this->categories;
|
|
|
|
}
|
2009-07-01 16:03:41 +04:00
|
|
|
}
|