2009-07-01 16:03:41 +04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Doctrine\Tests\Models\ECommerce;
|
|
|
|
|
2009-07-29 15:57:27 +04:00
|
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
2009-07-03 21:36:41 +04:00
|
|
|
|
2009-07-01 16:03:41 +04:00
|
|
|
/**
|
|
|
|
* ECommerceProduct
|
|
|
|
* Represents a type of product of a shopping application.
|
|
|
|
*
|
|
|
|
* @author Giorgio Sironi
|
|
|
|
* @Entity
|
2009-12-04 10:19:51 +03:00
|
|
|
* @Table(name="ecommerce_products",indexes={@index(name="name_idx", columns={"name"})})
|
2009-07-01 16:03:41 +04:00
|
|
|
*/
|
|
|
|
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
|
|
|
/**
|
2009-07-25 20:33:29 +04:00
|
|
|
* @OneToOne(targetEntity="ECommerceShipping", cascade={"persist"})
|
2009-07-01 17:11:45 +04:00
|
|
|
* @JoinColumn(name="shipping_id", referencedColumnName="id")
|
|
|
|
*/
|
|
|
|
private $shipping;
|
|
|
|
|
|
|
|
/**
|
2009-07-25 20:33:29 +04:00
|
|
|
* @OneToMany(targetEntity="ECommerceFeature", mappedBy="product", cascade={"persist"})
|
2009-07-01 17:11:45 +04:00
|
|
|
*/
|
|
|
|
private $features;
|
|
|
|
|
2009-07-01 16:03:41 +04:00
|
|
|
/**
|
2009-07-25 20:33:29 +04:00
|
|
|
* @ManyToMany(targetEntity="ECommerceCategory", cascade={"persist"})
|
2009-07-01 16:03:41 +04:00
|
|
|
* @JoinTable(name="ecommerce_products_categories",
|
2009-10-26 16:05:32 +03:00
|
|
|
* joinColumns={@JoinColumn(name="product_id", referencedColumnName="id")},
|
|
|
|
* inverseJoinColumns={@JoinColumn(name="category_id", referencedColumnName="id")})
|
2009-07-01 16:03:41 +04:00
|
|
|
*/
|
2009-07-02 13:37:59 +04:00
|
|
|
private $categories;
|
2009-07-01 16:03:41 +04:00
|
|
|
|
2009-07-06 16:18:04 +04:00
|
|
|
/**
|
|
|
|
* This relation is saved with two records in the association table for
|
|
|
|
* simplicity.
|
2009-07-25 20:33:29 +04:00
|
|
|
* @ManyToMany(targetEntity="ECommerceProduct", cascade={"persist"})
|
2009-07-06 16:18:04 +04:00
|
|
|
* @JoinTable(name="ecommerce_products_related",
|
2009-07-08 19:25:41 +04:00
|
|
|
joinColumns={@JoinColumn(name="product_id", referencedColumnName="id")},
|
|
|
|
inverseJoinColumns={@JoinColumn(name="related_id", referencedColumnName="id")})
|
2009-07-06 16:18:04 +04:00
|
|
|
*/
|
|
|
|
private $related;
|
|
|
|
|
2009-07-02 11:47:24 +04:00
|
|
|
public function __construct()
|
|
|
|
{
|
2009-07-29 15:57:27 +04:00
|
|
|
$this->features = new ArrayCollection;
|
|
|
|
$this->categories = new ArrayCollection;
|
|
|
|
$this->related = new ArrayCollection;
|
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 13:44:06 +04:00
|
|
|
$removed = $this->features->removeElement($feature);
|
|
|
|
if ($removed !== null) {
|
|
|
|
$removed->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)
|
|
|
|
{
|
2009-07-02 13:44:06 +04:00
|
|
|
$removed = $this->categories->removeElement($category);
|
|
|
|
if ($removed !== null) {
|
|
|
|
$removed->removeProduct($this);
|
2009-07-02 13:37:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCategories()
|
|
|
|
{
|
|
|
|
return $this->categories;
|
|
|
|
}
|
2009-07-06 16:18:04 +04:00
|
|
|
|
|
|
|
public function getRelated()
|
|
|
|
{
|
|
|
|
return $this->related;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function addRelated(ECommerceProduct $related)
|
|
|
|
{
|
|
|
|
if (!$this->related->contains($related)) {
|
|
|
|
$this->related[] = $related;
|
|
|
|
$related->addRelated($this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function removeRelated(ECommerceProduct $related)
|
|
|
|
{
|
|
|
|
$removed = $this->related->removeElement($related);
|
|
|
|
if ($removed) {
|
|
|
|
$related->removeRelated($this);
|
|
|
|
}
|
|
|
|
}
|
2009-07-01 16:03:41 +04:00
|
|
|
}
|