lib/boab/cms-bundle/src/Entity/Content.php line 24

Open in your IDE?
  1. <?php
  2. namespace Boab\CmsBundle\Entity;
  3. use Boab\CmsBundle\Contract\ThumbnailInterface;
  4. use Boab\CmsBundle\Contract\ThumbnailTrait;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Boab\CmsBundle\Entity\UserRelationInterface;
  9. use Boab\CmsBundle\Entity\User;
  10. use Boab\CmsBundle\Contract\SeoInterface;
  11. use Boab\CmsBundle\Contract\SeoTrait;
  12. use Tchoulom\ViewCounterBundle\Model\ViewCountable;
  13. use Symfony\Cmf\Component\Routing\RouteReferrersInterface;
  14. use Symfony\Component\Routing\Route;
  15. use Boab\CmsBundle\Entity\PageRoute;
  16. /**
  17.  * @ORM\Entity (repositoryClass="Boab\CmsBundle\Repository\ContentRepository")
  18.  * @ORM\Table(name="contents")
  19.  * @ORM\InheritanceType("JOINED")
  20.  * @ORM\DiscriminatorColumn(name="content_type", type="string")
  21.  */
  22. abstract class Content implements ContentInterfaceRouteReferrersInterfaceUserRelationInterfaceSeoInterfaceThumbnailInterfaceViewCountable
  23. {
  24.     protected $dateformat 'Y-m-d H:i:s';
  25.     use ThumbnailTrait;
  26.     use SeoTrait;   
  27.     use ViewCounterTrait;
  28.    /**
  29.      * @var integer
  30.      *
  31.      * @ORM\Column(name="id", type="integer")
  32.      * @ORM\Id
  33.      * @ORM\GeneratedValue(strategy="AUTO")
  34.      */
  35.     protected $id;
  36.     /**
  37.      * @var string
  38.      *
  39.      * @ORM\Column(name="unique_id", type="string", nullable=true, unique=true)
  40.      */
  41.     protected $uniqueId;    
  42.     /**
  43.      * @var string
  44.      *
  45.      * @ORM\Column(name="title", type="string", length=255, precision=0, scale=0, nullable=false, unique=false)
  46.      */
  47.     protected $title;
  48.     /**
  49.      * @var string
  50.      *
  51.      * @ORM\Column(name="slug", type="string", length=255, precision=0, scale=0, nullable=false, unique=true)
  52.      */
  53.     protected $slug;
  54.     /**
  55.      * @var string
  56.      *
  57.      * @ORM\Column(name="summary", type="text", precision=0, scale=0, nullable=true, unique=false)
  58.      */
  59.     protected $summary;
  60.     /**
  61.      * @var string
  62.      *
  63.      * @ORM\Column(name="body", type="text", precision=0, scale=0, nullable=true, unique=false)
  64.      */
  65.     protected $body;
  66.     /**
  67.      * @var string
  68.      *
  69.      * @ORM\Column(name="thumbnail", type="string", length=255, precision=0, scale=0, nullable=true, unique=false)
  70.      */
  71.     protected $thumbnail;
  72.     /**
  73.      * @var integer
  74.      *
  75.      * @ORM\Column(name="status", type="string", length=20, precision=0, scale=0, nullable=false, unique=false)
  76.      */
  77.     protected $status;
  78.     /**
  79.      * @var integer
  80.      *
  81.      * @ORM\Column(name="is_featured", type="boolean",  nullable=true)
  82.      */
  83.     protected $isFeatured=null;
  84.     /**
  85.      * @var integer
  86.      *
  87.      * @ORM\Column(name="promoted", type="boolean",  nullable=true)
  88.      */
  89.     protected $promoted;
  90.     /**
  91.      * @var integer
  92.      *
  93.      * @ORM\Column(name="publish_on_socialmedia", type="boolean",  nullable=true)
  94.      */
  95.     protected $publishOnSocialMedia;   
  96.     
  97.     /**
  98.      * @var integer
  99.      *
  100.      * @ORM\Column(name="is_published_social_media", type="boolean",  nullable=true)
  101.      */
  102.     protected $isPublishedOnSocialMedia;      
  103.     /**
  104.      * @var integer
  105.      *
  106.      * @ORM\Column(name="is_home", type="boolean",  nullable=true)
  107.      */
  108.     protected $isHome;    
  109.     /**
  110.      * @var \DateTime
  111.      *
  112.      * @ORM\Column(name="date_created", type="datetime", precision=0, scale=0, nullable=false)
  113.      */
  114.     protected $dateCreated;
  115.     /**
  116.      * @var \DateTime
  117.      *
  118.      * @ORM\Column(name="date_published", type="datetime", precision=0, scale=0, nullable=true)
  119.      */
  120.     protected $datePublished;
  121.     /**
  122.      * @var string
  123.      *
  124.      * @ORM\Column(name="meta_keywords", type="string", length=255, precision=0, scale=0, nullable=true, unique=false)
  125.      */
  126.     protected $metaKeywords;
  127.     /**
  128.      * @var string
  129.      *
  130.      * @ORM\Column(name="meta_description", type="string", length=255, precision=0, scale=0, nullable=true, unique=false)
  131.      */
  132.     protected $metaDescription;
  133.     /**
  134.      * @var \Boab\CmsBundle\Entity\UserAdmin
  135.      *
  136.      * @ORM\ManyToOne(targetEntity="Boab\CmsBundle\Entity\User", inversedBy="contents")
  137.      * @ORM\JoinColumns({
  138.      *   @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=false)
  139.      * })
  140.      */
  141.     protected $user;
  142.     /**
  143.      *
  144.      * @ORM\ManyToOne(targetEntity="Boab\CmsBundle\Entity\Term", inversedBy="contents", fetch="EAGER")
  145.      * @ORM\JoinColumns({
  146.      * @ORM\JoinColumn(name="term_id", referencedColumnName="id", nullable=true)
  147.      * })
  148.      */
  149.     protected $term;
  150.     /**
  151.      * @var \Doctrine\Common\Collections\Collection
  152.      *
  153.      * @ORM\OneToMany(targetEntity="Boab\CmsBundle\Entity\Photo", mappedBy="content", cascade={"persist","remove"}, orphanRemoval=true)
  154.      */
  155.     protected $photos;
  156.     /**
  157.      * @ORM\Column(type="datetime_immutable", nullable=true)
  158.      */
  159.     private $updatedAt;
  160.     /**
  161.      * @ORM\OneToMany(targetEntity=Media::class, mappedBy="content", cascade={"persist","remove"}, orphanRemoval=true)
  162.      */
  163.     private $media;
  164.     /**
  165.      * @ORM\Column(type="string", length=10, nullable=true)
  166.      */
  167.     private $position;    
  168.     /**
  169.      * @var RouteObjectInterface[]|ArrayCollection
  170.      *
  171.      * @ORM\ManyToMany(targetEntity=PageRoute::class, cascade={"persist", "remove"})
  172.      */
  173.     private $routes;  
  174.     /**
  175.      * Constructor
  176.      */
  177.     public function __construct()
  178.     {
  179.         $this->photos = new \Doctrine\Common\Collections\ArrayCollection();
  180.         $this->media = new ArrayCollection();
  181.         $this->routes = new ArrayCollection();
  182.     }
  183.     /**
  184.      * Add photo
  185.      *
  186.      * @param \Boab\CmsBundle\Entity\Photo $photo
  187.      *
  188.      * @return Content
  189.      */
  190.     public function addPhoto(\Boab\CmsBundle\Entity\Photo $photo)
  191.     {
  192.         $this->photos[] = $photo;
  193.         return $this;
  194.     }
  195.     /**
  196.      * Remove photo
  197.      *
  198.      * @param \Boab\CmsBundle\Entity\Photo $photo
  199.      */
  200.     public function removePhoto(\Boab\CmsBundle\Entity\Photo $photo)
  201.     {
  202.         $this->photos->removeElement($photo);
  203.     }
  204.     /**
  205.      * Get photos
  206.      *
  207.      * @return \Doctrine\Common\Collections\Collection
  208.      */
  209.     public function getPhotos()
  210.     {
  211.         return $this->photos;
  212.     }
  213.      /**
  214.      * Get id
  215.      *
  216.      * @return integer
  217.      */
  218.     public function getId()
  219.     {
  220.         return $this->id;
  221.     }
  222.     /**
  223.      * Set uniqueId.
  224.      *
  225.      * @param string $uniqueId
  226.      *
  227.      * @return Content
  228.      */
  229.     public function setUniqueId($uniqueId)
  230.     {
  231.         $this->uniqueId $uniqueId;
  232.         return $this;
  233.     }
  234.     /**
  235.      * Get uniqueId.
  236.      *
  237.      * @return string
  238.      */
  239.     public function getUniqueId()
  240.     {
  241.         return $this->uniqueId;
  242.     }    
  243.     /**
  244.      * Set title
  245.      *
  246.      * @param  string $title
  247.      * @return Page
  248.      */
  249.     public function setTitle($title)
  250.     {
  251.         $this->title $title;
  252.         return $this;
  253.     }
  254.     /**
  255.      * Get title
  256.      *
  257.      * @return string
  258.      */
  259.     public function getTitle()
  260.     {
  261.         return $this->title;
  262.     }
  263.     /**
  264.      * Set slug
  265.      *
  266.      * @param  string $slug
  267.      * @return Page
  268.      */
  269.     public function setSlug($slug)
  270.     {
  271.         $this->slug $slug;
  272.         return $this;
  273.     }
  274.     /**
  275.      * Get slug
  276.      *
  277.      * @return string
  278.      */
  279.     public function getSlug()
  280.     {
  281.         return $this->slug;
  282.     }
  283.     /**
  284.      * Set summary
  285.      *
  286.      * @param  string $summary
  287.      * @return Page
  288.      */
  289.     public function setSummary($summary)
  290.     {
  291.         $this->summary $summary;
  292.         return $this;
  293.     }
  294.     /**
  295.      * Get summary
  296.      *
  297.      * @return string
  298.      */
  299.     public function getSummary()
  300.     {
  301.         return $this->summary;
  302.     }
  303.     /**
  304.      * Set body
  305.      *
  306.      * @param  string  $body
  307.      * @return Content
  308.      */
  309.     public function setBody($body)
  310.     {
  311.         $this->body $body;
  312.         return $this;
  313.     }
  314.     /**
  315.      * Get body
  316.      *
  317.      * @return string
  318.      */
  319.     public function getBody()
  320.     {
  321.         return $this->body;
  322.     }
  323.     /**
  324.      * Set user
  325.      *
  326.      * @param  \Boab\CmsBundle\Entity\User $user
  327.      * @return Page
  328.      */
  329.     public function setUser(User $user)
  330.     {
  331.         $this->user $user;
  332.         return $this;
  333.     }
  334.     /**
  335.      * Get user
  336.      *
  337.      * @return \Boab\CmsBundle\Entity\User
  338.      */
  339.     public function getUser()
  340.     {
  341.         return $this->user;
  342.     }
  343.     /**
  344.      * Set status
  345.      *
  346.      * @param  integer $status
  347.      * @return Page
  348.      */
  349.     public function setStatus($status)
  350.     {
  351.         $this->status $status;
  352.         return $this;
  353.     }
  354.     /**
  355.      * Get status
  356.      *
  357.      * @return integer
  358.      */
  359.     public function getStatus()
  360.     {
  361.         return $this->status;
  362.     }
  363.     /**
  364.      * Set isFeatured
  365.      *
  366.      * @param  integer $isFeatured
  367.      * @return Content
  368.      */
  369.     public function setIsFeatured($isFeatured)
  370.     {
  371.         $this->isFeatured = !empty($isFeatured) ? 0;
  372.         return $this;
  373.     }
  374.     /**
  375.      * Get isFeatured
  376.      *
  377.      * @return integer
  378.      */
  379.     public function getIsFeatured()
  380.     {
  381.         return $this->isFeatured;
  382.     }
  383.     public function isFeatured()
  384.     {
  385.         return (bool) $this->getIsFeatured();
  386.     }
  387.     /**
  388.      * Set promoted
  389.      *
  390.      * @param  integer $promoted
  391.      * @return Content
  392.      */
  393.     public function setPromoted($promoted='')
  394.     {
  395.         $this->promoted = !empty($promoted) ? 0;
  396.         return $this;
  397.     }
  398.     /**
  399.      * Get promoted
  400.      *
  401.      * @return integer
  402.      */
  403.     public function getPromoted()
  404.     {
  405.         return $this->promoted;
  406.     }
  407.     public function isPromoted()
  408.     {
  409.         return (bool) $this->getPromoted();
  410.     }
  411.     /**
  412.      * Set isHome
  413.      *
  414.      * @param boolean $isHome
  415.      *
  416.      * @return Content
  417.      */
  418.     public function setIsHome($isHome)
  419.     {
  420.         $this->isHome $isHome;
  421.         return $this;
  422.     }
  423.     /**
  424.      * Get isHome
  425.      *
  426.      * @return boolean
  427.      */
  428.     public function getIsHome()
  429.     {
  430.         return $this->isHome;
  431.     }    
  432.     /**
  433.      * Set dateCreated
  434.      *
  435.      * @param  \DateTime $dateCreated
  436.      * @return Page
  437.      */
  438.     public function setDateCreated($dateCreated)
  439.     {
  440.         $this->dateCreated $dateCreated;
  441.         return $this;
  442.     }
  443.     /**
  444.      * Get dateCreated
  445.      *
  446.      * @return \DateTime
  447.      */
  448.     public function getDateCreated()
  449.     {
  450.         return $this->dateCreated;
  451.     }
  452.     /**
  453.      * Set datePublished
  454.      *
  455.      * @param  \DateTime $datePublished
  456.      * @return Page
  457.      */
  458.     public function setDatePublished($datePublished null)
  459.     {
  460.         $this->datePublished $datePublished;
  461.         return $this;
  462.     }
  463.     /**
  464.      * Get datePublished
  465.      *
  466.      * @return \DateTime
  467.      */
  468.     public function getDatePublished()
  469.     {
  470.         return $this->datePublished;
  471.     }
  472.     /**
  473.      * Set metaKeyWords
  474.      *
  475.      * @param string $metaKeyWords
  476.      *
  477.      * @return Content
  478.      */
  479.     public function setMetaKeywords($metaKeywords)
  480.     {
  481.         $this->metaKeywords $metaKeywords;
  482.         return $this;
  483.     }
  484.     /**
  485.      * Get metaKeyWords
  486.      *
  487.      * @return string
  488.      */
  489.     public function getMetaKeyWords()
  490.     {
  491.         return $this->metaKeywords;
  492.     }
  493.     /**
  494.      * Set metaDescription
  495.      *
  496.      * @param string $metaDescription
  497.      *
  498.      * @return Content
  499.      */
  500.     public function setMetaDescription($metaDescription)
  501.     {
  502.         $this->metaDescription $metaDescription;
  503.         return $this;
  504.     }
  505.     /**
  506.      * Get metaDescription
  507.      *
  508.      * @return string
  509.      */
  510.     public function getMetaDescription()
  511.     {     
  512.         return $this->metaDescription;
  513.     }
  514.     /**
  515.      * Set term
  516.      *
  517.      * @param \Boab\CmsBundle\Entity\Term $term
  518.      *
  519.      * @return Content
  520.      */
  521.     public function setTerm(\Boab\CmsBundle\Entity\Term $term null)
  522.     {
  523.         $this->term $term;
  524.         return $this;
  525.     }
  526.     /**
  527.      * Get term
  528.      *
  529.      * @return \Boab\CmsBundle\Entity\Term
  530.      */
  531.     public function getTerm()
  532.     {
  533.         return $this->term;
  534.     }    
  535.     /**
  536.     * Remove all user Roles
  537.     */
  538.     public function removeAllPhotos()
  539.     {
  540.        $this->photos->clear();
  541.     }  
  542.     
  543.     public function getAuthoredBy()
  544.     {
  545.         if(null == $this->getUser()){
  546.             return;
  547.         }
  548.         return $this->getUser()->getFullName();
  549.     }
  550.     public function isPublished()
  551.     {
  552.         return (self::STATUS_PUBLISHED == $this->getStatus());
  553.     } 
  554.         
  555.     /**
  556.      * Set publishOnSocialMedia.
  557.      *
  558.      * @param bool|null $publishOnSocialMedia
  559.      *
  560.      * @return Content
  561.      */
  562.     public function setPublishOnSocialMedia($publishOnSocialMedia null)
  563.     {
  564.         $this->publishOnSocialMedia $publishOnSocialMedia;
  565.         return $this;
  566.     }
  567.     /**
  568.      * Get publishOnSocialMedia.
  569.      *
  570.      * @return bool|null
  571.      */
  572.     public function getPublishOnSocialMedia()
  573.     {
  574.         return $this->publishOnSocialMedia;
  575.     }
  576.     /**
  577.      * Set isPublishedOnSocialMedia.
  578.      *
  579.      * @param bool|null $isPublishedOnSocialMedia
  580.      *
  581.      * @return Content
  582.      */
  583.     public function setIsPublishedOnSocialMedia($isPublishedOnSocialMedia null)
  584.     {
  585.         $this->isPublishedOnSocialMedia $isPublishedOnSocialMedia;
  586.         return $this;
  587.     }
  588.     /**
  589.      * Get isPublishedOnSocialMedia.
  590.      *
  591.      * @return bool|null
  592.      */
  593.     public function getIsPublishedOnSocialMedia()
  594.     {
  595.         return $this->isPublishedOnSocialMedia;
  596.     }
  597.     public function getUpdatedAt(): ?\DateTimeImmutable
  598.     {
  599.         return $this->updatedAt;
  600.     }
  601.     public function setUpdatedAt(?\DateTimeImmutable $updatedAt): self
  602.     {
  603.         $this->updatedAt $updatedAt;
  604.         return $this;
  605.     }
  606.     /**
  607.      * @return Collection<int, Media>
  608.      */
  609.     public function getMedia(): Collection
  610.     {
  611.         return $this->media;
  612.     }
  613.     public function addMedium(Media $medium): self
  614.     {
  615.         if (!$this->media->contains($medium)) {
  616.             $this->media[] = $medium;
  617.             $medium->setContent($this);
  618.         }
  619.         return $this;
  620.     }
  621.     public function removeMedium(Media $medium): self
  622.     {
  623.         if ($this->media->removeElement($medium)) {
  624.             // set the owning side to null (unless already changed)
  625.             if ($medium->getContent() === $this) {
  626.                 $medium->setContent(null);
  627.             }
  628.         }
  629.         return $this;
  630.     }
  631.     public function getPosition(): ?string
  632.     {
  633.         return $this->position;
  634.     }
  635.     public function setPosition(?string $position): self
  636.     {
  637.         $this->position $position;
  638.         return $this;
  639.     }
  640.     /**
  641.      * @return RouteObjectInterface[]|ArrayCollection
  642.      */
  643.     public function getRoutes(): iterable
  644.     {
  645.         return $this->routes;
  646.     }
  647.     /**
  648.      * @param RouteObjectInterface[]|ArrayCollection $routes
  649.      */
  650.     public function setRoutes($routes)
  651.     {
  652.         $this->routes $routes;
  653.     }
  654.     /**
  655.      * @param RouteObjectInterface $route
  656.      *
  657.      * @return $this
  658.      */
  659.     public function addRoute(Route $route): void
  660.     {
  661.         $this->routes[] = $route;
  662.     }
  663.     /**
  664.      * @param RouteObjectInterface $route
  665.      *
  666.      * @return $this
  667.      */
  668.     public function removeRoute(Route $route):void
  669.     {
  670.         $this->routes->removeElement($route);
  671.     }
  672. }