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
|
2010-04-10 02:00:36 +04: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
|
2010-04-10 02:00:36 +04:00
|
|
|
* @GeneratedValue
|
2009-07-01 16:03:41 +04:00
|
|
|
*/
|
|
|
|
private $id;
|
|
|
|
|
|
|
|
/**
|
2011-09-13 07:59:24 +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
|
|
|
/**
|
2010-04-10 02:00:36 +04:00
|
|
|
* @ManyToMany(targetEntity="ECommerceCategory", cascade={"persist"}, inversedBy="products")
|
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
|
|
|
/**
|
2011-12-20 01:56:19 +04:00
|
|
|
* This relation is saved with two records in the association table for
|
2009-07-06 16:18:04 +04:00
|
|
|
* 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",
|
2010-04-10 02:00:36 +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;
|
|
|
|
|
2011-02-26 14:47:59 +03:00
|
|
|
public $isCloned = false;
|
2011-07-09 14:12:44 +04:00
|
|
|
public $wakeUp = false;
|
2011-02-26 14:47:59 +03:00
|
|
|
|
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);
|
2010-09-01 22:43:23 +04:00
|
|
|
if ($removed) {
|
|
|
|
$feature->removeProduct();
|
2009-07-01 17:11:45 +04:00
|
|
|
}
|
2010-09-01 22:43:23 +04:00
|
|
|
return $removed;
|
2009-07-01 17:11:45 +04:00
|
|
|
}
|
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);
|
2010-09-01 22:43:23 +04:00
|
|
|
if ($removed) {
|
|
|
|
$category->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);
|
|
|
|
}
|
|
|
|
}
|
2011-02-26 14:47:59 +03:00
|
|
|
|
|
|
|
public function __clone()
|
|
|
|
{
|
|
|
|
$this->isCloned = true;
|
|
|
|
}
|
2011-07-09 14:12:44 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Testing docblock contents here
|
|
|
|
*/
|
|
|
|
public function __wakeup()
|
|
|
|
{
|
|
|
|
$this->wakeUp = true;
|
|
|
|
}
|
2009-07-01 16:03:41 +04:00
|
|
|
}
|