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;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Column(type="string", length=50)
|
|
|
|
*/
|
|
|
|
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"}})
|
|
|
|
private $categories;
|
|
|
|
*/
|
|
|
|
|
2009-07-02 11:47:24 +04:00
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->features = new \Doctrine\Common\Collections\Collection;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 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-01 16:03:41 +04:00
|
|
|
}
|