src/AtechNet/CoreBundle/Entity/ProductAttribute.php line 29

Open in your IDE?
  1. <?php
  2. namespace App\AtechNet\CoreBundle\Entity;
  3. use Doctrine\ORM\Mapping\Column;
  4. use Doctrine\ORM\Mapping\Entity;
  5. use Doctrine\ORM\Mapping\HasLifecycleCallbacks;
  6. use Doctrine\ORM\Mapping\JoinColumn;
  7. use Doctrine\ORM\Mapping\ManyToOne;
  8. use Doctrine\ORM\Mapping\Table as Table;
  9. use Doctrine\ORM\Mapping\UniqueConstraint;
  10. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  11. use Symfony\Component\Validator\Constraints as Assert;
  12. /**
  13.  * Album
  14.  *
  15.  * @Entity
  16.  * @Table(name="products__attributes", uniqueConstraints={
  17.  *     @UniqueConstraint(name="unique_product_attribute", columns={"product_id", "option_id"})
  18.  * })
  19.  * @UniqueEntity(
  20.  *     fields={"product", "option"},
  21.  *     errorPath="option",
  22.  *     message="This attribute is already added."
  23.  * )
  24.  * @HasLifecycleCallbacks
  25.  */
  26. class ProductAttribute extends AbstractEntity
  27. {
  28.     /**
  29.      * @var Product
  30.      *
  31.      * @Assert\NotNull
  32.      *
  33.      * @ManyToOne(targetEntity="Product", inversedBy="productAttributes")
  34.      * @JoinColumn(name="product_id", referencedColumnName="id")
  35.      */
  36.     private $product;
  37.     /**
  38.      * @var AttributeOption
  39.      *
  40.      * @Assert\NotNull
  41.      *
  42.      * @ManyToOne(targetEntity="AttributeOption", inversedBy="productAttributes")
  43.      * @JoinColumn(name="option_id", referencedColumnName="id", nullable=false)
  44.      */
  45.     private $option;
  46.     /**
  47.      * @var bool
  48.      *
  49.      * @Assert\NotNull
  50.      *
  51.      * @Column(name="used", type="boolean", nullable=false)
  52.      */
  53.     private $used = false;
  54.     /**
  55.      * @var integer
  56.      *
  57.      * @Assert\NotNull
  58.      *
  59.      * @Column(name="multiplier", type="integer")
  60.      */
  61.     private $multiplier = 0;
  62.     /**
  63.      * @var bool
  64.      *
  65.      * @Assert\NotNull
  66.      *
  67.      * @Column(name="always", type="boolean")
  68.      */
  69.     private $always = false;
  70.     public function __construct()
  71.     {
  72.         parent::__construct();
  73.     }
  74.     /**
  75.      * @return Product
  76.      */
  77.     public function getProduct()
  78.     {
  79.         return $this->product;
  80.     }
  81.     /**
  82.      * @param Product $product
  83.      */
  84.     public function setProduct($product)
  85.     {
  86.         $this->product = $product;
  87.         $product->addProductAttribute($this);
  88.     }
  89.     /**
  90.      * @return AttributeOption
  91.      */
  92.     public function getOption()
  93.     {
  94.         return $this->option;
  95.     }
  96.     /**
  97.      * @param AttributeOption $option
  98.      */
  99.     public function setOption($option)
  100.     {
  101.         $this->option = $option;
  102.     }
  103.     /**
  104.      * @return boolean
  105.      */
  106.     public function isUsed()
  107.     {
  108.         return $this->used;
  109.     }
  110.     /**
  111.      * @param boolean $used
  112.      */
  113.     public function setUsed($used)
  114.     {
  115.         $this->used = $used;
  116.     }
  117.     /**
  118.      * @return int
  119.      */
  120.     public function getMultiplier()
  121.     {
  122.         return $this->multiplier;
  123.     }
  124.     /**
  125.      * @param int $multiplier
  126.      */
  127.     public function setMultiplier($multiplier)
  128.     {
  129.         $this->multiplier = $multiplier;
  130.     }
  131.     /**
  132.      * @return boolean
  133.      */
  134.     public function isAlways()
  135.     {
  136.         return $this->always;
  137.     }
  138.     /**
  139.      * @param boolean $always
  140.      */
  141.     public function setAlways($always)
  142.     {
  143.         $this->always = $always;
  144.     }
  145. }