1
0
mirror of synced 2024-12-15 07:36:03 +03:00
doctrine2/tests/Doctrine/Tests/Models/ECommerce/ECommerceProduct.php

170 lines
4.0 KiB
PHP
Raw Normal View History

<?php
namespace Doctrine\Tests\Models\ECommerce;
use Doctrine\Common\Collections\ArrayCollection;
/**
* 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"})})
*/
class ECommerceProduct
{
/**
* @Column(type="integer")
* @Id
2010-04-10 02:00:36 +04:00
* @GeneratedValue
*/
private $id;
/**
* @Column(type="string", length=50, nullable="true")
*/
private $name;
/**
* @OneToOne(targetEntity="ECommerceShipping", cascade={"persist"})
* @JoinColumn(name="shipping_id", referencedColumnName="id")
*/
private $shipping;
/**
* @OneToMany(targetEntity="ECommerceFeature", mappedBy="product", cascade={"persist"})
*/
private $features;
/**
2010-04-10 02:00:36 +04:00
* @ManyToMany(targetEntity="ECommerceCategory", cascade={"persist"}, inversedBy="products")
* @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")})
*/
private $categories;
/**
* This relation is saved with two records in the association table for
* simplicity.
* @ManyToMany(targetEntity="ECommerceProduct", cascade={"persist"})
* @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")})
*/
private $related;
public $isCloned = false;
2009-07-02 11:47:24 +04:00
public function __construct()
{
$this->features = new ArrayCollection;
$this->categories = new ArrayCollection;
$this->related = new ArrayCollection;
2009-07-02 11:47:24 +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;
}
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)
{
2009-07-02 13:44:06 +04:00
$removed = $this->features->removeElement($feature);
if ($removed) {
$feature->removeProduct();
}
return $removed;
}
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) {
$category->removeProduct($this);
}
}
public function getCategories()
{
return $this->categories;
}
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);
}
}
public function __clone()
{
$this->isCloned = true;
}
}