Skip to content

Instantly share code, notes, and snippets.

@treetop1500
Created September 12, 2016 16:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save treetop1500/bdeca27c277d2f1f74f5585603d17b4d to your computer and use it in GitHub Desktop.
Save treetop1500/bdeca27c277d2f1f74f5585603d17b4d to your computer and use it in GitHub Desktop.
Product Entity for Symfony3 Projects (Extends BaseContent)
<?php
namespace Common\ContentBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Doctrine\Common\Collections\ArrayCollection;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* Product
*
* @ORM\Table(name="product")
* @ORM\Entity(repositoryClass="Common\ContentBundle\Repository\ProductRepository")
* @Vich\Uploadable
*/
class Product extends BaseContent
{
/**
* @var string
*
* @ORM\Column(name="subtitle", type="string", length=255)
* @Assert\NotBlank(message="This is a required field.")
*/
private $subtitle;
/**
* @var string
*
* @ORM\Column(name="snippet", type="text", nullable=true)
*/
private $snippet;
/**
* @var string
*
* @ORM\Column(name="expertInformation", type="text", nullable=true)
*/
private $expertInformation;
/**
* @Vich\UploadableField(mapping="logo_image", fileNameProperty="logoImagePath")
*
* @var File
*/
private $logoImageFile;
/**
* @var string
*
* @ORM\Column(name="logoImagePath", type="string", length=255, nullable=true)
*/
private $logoImagePath;
/**
* @Vich\UploadableField(mapping="lifestyle_image", fileNameProperty="lifestyleImagePath")
*
* @var File
*/
private $lifestyleImageFile;
/**
* @var string
*
* @ORM\Column(name="lifestyleImagePath", type="string", length=255, nullable=true)
*/
private $lifestyleImagePath;
/**
* @ORM\OneToOne(targetEntity="FactSheet", cascade={"all"}, orphanRemoval=true)
*/
private $factSheet;
/**
* @var string
*
* @ORM\Column(name="couponLink", type="text", length=255, nullable=true)
*/
private $couponLink;
/**
* @var string
*
* @ORM\Column(name="primaryColor", type="string", length=10)
* @Assert\NotBlank(message="This is a required field.")
*/
private $primaryColor;
/**
* @ORM\OneToMany(targetEntity="Common\ContentBundle\Entity\Product", mappedBy="parent")
* @ORM\OrderBy({"sortOrder":"ASC"})
*/
private $children;
/**
* @ORM\ManyToOne(targetEntity="Common\ContentBundle\Entity\Product", inversedBy="children")
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id")
*/
private $parent;
/**
* @ORM\ManyToMany(targetEntity="ProductImage", cascade={"remove", "persist"})
* @ORM\OrderBy({"sortOrder" = "ASC"})
* @ORM\JoinTable(name="product_productImages",
* joinColumns={@ORM\JoinColumn(name="product_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="productImage_id", referencedColumnName="id", unique=true)}
* )
*/
private $productImages;
/**
* @ORM\ManyToMany(targetEntity="Faq", cascade={"remove", "persist"})
* @ORM\OrderBy({"sortOrder" = "ASC"})
* @ORM\JoinTable(name="product_faqs",
* joinColumns={@ORM\JoinColumn(name="product_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="faq_id", referencedColumnName="id", unique=true)}
* )
*/
private $faqs;
/**
* @ORM\ManyToMany(targetEntity="Video", cascade={"remove", "persist"})
* @ORM\OrderBy({"sortOrder" = "ASC"})
* @ORM\JoinTable(name="product_videos",
* joinColumns={@ORM\JoinColumn(name="product_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="video_id", referencedColumnName="id", unique=true)}
* )
*/
private $videos;
/**
* @ORM\ManyToMany(targetEntity="InterestGroup", inversedBy="products")
* @ORM\OrderBy({"parent" = "ASC", "sortOrder" = "ASC"})
* @ORM\JoinTable(name="product_interestGroups")
*/
private $interestGroups;
/**
* @ORM\ManyToOne(targetEntity="Domain", inversedBy="products", cascade={"persist"})
* @ORM\JoinColumn(name="domain_id", referencedColumnName="id", nullable=true)
*/
private $domain;
/**
* Product constructor.
*/
public function __construct()
{
parent::__construct();
$this->productImages = new ArrayCollection();
$this->videos = new ArrayCollection();
$this->faqs = new ArrayCollection();
$this->interestGroups = new ArrayCollection();
$this->children = new ArrayCollection();
}
/**
* Set subtitle
*
* @param string $subtitle
*
* @return Product
*/
public function setSubtitle($subtitle)
{
$this->subtitle = $subtitle;
return $this;
}
/**
* Get subtitle
*
* @return string
*/
public function getSubtitle()
{
return $this->subtitle;
}
/**
* Set snippet
*
* @param string $snippet
*
* @return Product
*/
public function setSnippet($snippet)
{
$this->snippet = $snippet;
return $this;
}
/**
* Get snippet
*
* @return string
*/
public function getSnippet()
{
return $this->snippet;
}
/**
* Set expertInformation
*
* @param string $expertInformation
*
* @return Product
*/
public function setExpertInformation($expertInformation)
{
$this->expertInformation = $expertInformation;
return $this;
}
/**
* Get expertInformation
*
* @return string
*/
public function getExpertInformation()
{
return $this->expertInformation;
}
/**
* Set logoImagePath
*
* @param string $logoImagePath
*
* @return Product
*/
public function setLogoImagePath($logoImagePath)
{
$this->logoImagePath = $logoImagePath;
return $this;
}
/**
* Get logoImagePath
*
* @return string
*/
public function getLogoImagePath()
{
return $this->logoImagePath;
}
/**
* If manually uploading a file (i.e. not using Symfony Form) ensure an instance
* of 'UploadedFile' is injected into this setter to trigger the update. If this
* bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
* must be able to accept an instance of 'File' as the bundle will inject one here
* during Doctrine hydration.
*
* @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $image
*
* @return Product
*/
public function setLogoImageFile(File $image = null)
{
$this->logoImageFile = $image;
if ($image) {
$this->setUpdatedAt(new \DateTime('now'));
}
return $this;
}
/**
* @return File
*/
public function getLogoImageFile()
{
return $this->logoImageFile;
}
/**
* Set lifestyleImagePath
*
* @param string $lifestyleImagePath
*
* @return Product
*/
public function setLifestyleImagePath($lifestyleImagePath)
{
$this->lifestyleImagePath = $lifestyleImagePath;
return $this;
}
/**
* Get lifestyleImagePath
*
* @return string
*/
public function getLifestyleImagePath()
{
return $this->lifestyleImagePath;
}
/**
* If manually uploading a file (i.e. not using Symfony Form) ensure an instance
* of 'UploadedFile' is injected into this setter to trigger the update. If this
* bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
* must be able to accept an instance of 'File' as the bundle will inject one here
* during Doctrine hydration.
*
* @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $image
*
* @return Product
*/
public function setLifestyleImageFile(File $image = null)
{
$this->lifestyleImageFile = $image;
if ($image) {
$this->setUpdatedAt(new \DateTime('now'));
}
return $this;
}
/**
* @return File
*/
public function getLifestyleImageFile()
{
return $this->lifestyleImageFile;
}
/**
* Set couponLink
*
* @param string $couponLink
*
* @return Product
*/
public function setCouponLink($couponLink)
{
$this->couponLink = $couponLink;
return $this;
}
/**
* Get couponLink
*
* @return string
*/
public function getCouponLink()
{
return $this->couponLink;
}
/**
* Set primaryColor
*
* @param string $primaryColor
*
* @return Product
*/
public function setPrimaryColor($primaryColor)
{
$this->primaryColor = $primaryColor;
return $this;
}
/**
* Get primaryColor
*
* @return string
*/
public function getPrimaryColor()
{
return $this->primaryColor;
}
/**
* @return mixed
*/
public function getChildren()
{
return $this->children;
}
/**
* @param mixed $children
*/
public function setChildren($children)
{
$this->children = $children;
}
/**
* @return mixed
*/
public function getParent()
{
return $this->parent;
}
/**
* @param mixed $parent
*/
public function setParent($parent)
{
$this->parent = $parent;
}
/**
* @return mixed
*/
public function getProductImages()
{
return $this->productImages;
}
public function addProductImage(ProductImage $productImage)
{
$this->productImages->add($productImage);
}
public function removeProductImage(ProductImage $productImage)
{
$this->productImages->removeElement($productImage);
}
/**
* Get videos
*
* @return int
*/
public function getVideos()
{
return $this->videos;
}
public function addVideo(Video $video)
{
$this->videos->add($video);
}
public function removeVideo(Video $video)
{
$this->videos->removeElement($video);
}
/**
* Get domain
*
* @return int
*/
public function getDomain()
{
return $this->domain;
}
/**
* @param mixed $domain
*/
public function setDomain($domain)
{
$this->domain = $domain;
}
/**
* Get faqs
*
* @return int
*/
public function getFaqs()
{
return $this->faqs;
}
public function addFaq(Faq $faq)
{
$this->faqs->add($faq);
}
public function removeFaq(Faq $faq)
{
$this->faqs->removeElement($faq);
}
/**
* Get faqs
*
* @return int
*/
public function getInterestGroups()
{
return $this->interestGroups;
}
public function addInterestGroup(InterestGroup $interestGroup)
{
$this->interestGroups->add($interestGroup);
}
public function removeInterestGroup(InterestGroup $interestGroup)
{
$this->interestGroups->removeElement($interestGroup);
}
/**
* @return mixed
*/
public function getFactSheet()
{
return $this->factSheet;
}
/**
* @param mixed $factSheet
*/
public function setFactSheet($factSheet)
{
$this->factSheet = $factSheet;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment