src/CoreBundle/Entity/Post.php line 15

Open in your IDE?
  1. <?php
  2. namespace CoreBundle\Entity;
  3. use CoreBundle\Entity\Vehicles\Vehicle;
  4. use Application\Sonata\MediaBundle\Entity\Gallery;
  5. use Application\Sonata\MediaBundle\Entity\Media;
  6. use DateTime;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. /**
  10.  * Post
  11.  */
  12. class Post
  13. {
  14.     /**
  15.      * @var integer
  16.      */
  17.     private $id;
  18.     /**
  19.      * @var integer
  20.      */
  21.     private $state;
  22.     /**
  23.      * @var DateTime
  24.      */
  25.     private $date_start;
  26.     /**
  27.      * @var DateTime
  28.      */
  29.     private $date_end;
  30.     /**
  31.      * @var DateTime
  32.      */
  33.     private $date_create;
  34.     /**
  35.      * @var integer
  36.      */
  37.     private $bundle;
  38.     /**
  39.      * @var integer
  40.      */
  41.     private $post_type;
  42.     /**
  43.      * @var Collection
  44.      */
  45.     private $content;
  46.     /**
  47.      * @var User
  48.      */
  49.     private $creator;
  50.     /**
  51.      * @var Dealer
  52.      */
  53.     private $dealer;
  54.     private DateTime $updatedAt;
  55.     /**
  56.      * Constructor
  57.      */
  58.     public function __construct()
  59.     {
  60.         $this->content = new ArrayCollection();
  61.         $this->content->add((new PostContent())->setLanguage('ru'));
  62.         $this->content->add((new PostContent())->setLanguage('ua'));
  63.         $this->date_create = new DateTime();
  64.     }
  65.     /**
  66.      * Get id
  67.      *
  68.      * @return integer
  69.      */
  70.     public function getId()
  71.     {
  72.         return $this->id;
  73.     }
  74.     /**
  75.      * Set state
  76.      *
  77.      * @param integer $state
  78.      *
  79.      * @return Post
  80.      */
  81.     public function setState($state)
  82.     {
  83.         $this->state $state;
  84.         return $this;
  85.     }
  86.     /**
  87.      * Get state
  88.      *
  89.      * @return integer
  90.      */
  91.     public function getState()
  92.     {
  93.         return $this->state 0;
  94.     }
  95.     /**
  96.      * Set dateStart
  97.      *
  98.      * @param DateTime $dateStart
  99.      *
  100.      * @return Post
  101.      */
  102.     public function setDateStart($dateStart)
  103.     {
  104.         $this->date_start $dateStart;
  105.         return $this;
  106.     }
  107.     /**
  108.      * Get dateStart
  109.      *
  110.      * @return DateTime
  111.      */
  112.     public function getDateStart()
  113.     {
  114.         return $this->date_start;
  115.     }
  116.     /**
  117.      * Set dateEnd
  118.      *
  119.      * @param DateTime $dateEnd
  120.      *
  121.      * @return Post
  122.      */
  123.     public function setDateEnd($dateEnd)
  124.     {
  125.         $this->date_end $dateEnd;
  126.         return $this;
  127.     }
  128.     /**
  129.      * Get dateEnd
  130.      *
  131.      * @return DateTime
  132.      */
  133.     public function getDateEnd()
  134.     {
  135.         return $this->date_end;
  136.     }
  137.     /**
  138.      * Set dateCreate
  139.      *
  140.      * @param DateTime $dateCreate
  141.      *
  142.      * @return Post
  143.      */
  144.     public function setDateCreate($dateCreate)
  145.     {
  146.         $this->date_create $dateCreate;
  147.         return $this;
  148.     }
  149.     /**
  150.      * Get dateCreate
  151.      *
  152.      * @return DateTime
  153.      */
  154.     public function getDateCreate()
  155.     {
  156.         return $this->date_create;
  157.     }
  158.     /**
  159.      * Set bundle
  160.      *
  161.      * @param integer $bundle
  162.      *
  163.      * @return Post
  164.      */
  165.     public function setBundle($bundle)
  166.     {
  167.         $this->bundle $bundle;
  168.         return $this;
  169.     }
  170.     /**
  171.      * Get bundle
  172.      *
  173.      * @return integer
  174.      */
  175.     public function getBundle()
  176.     {
  177.         return $this->bundle;
  178.     }
  179.     /**
  180.      * Set postType
  181.      *
  182.      * @param integer $postType
  183.      *
  184.      * @return Post
  185.      */
  186.     public function setPostType($postType)
  187.     {
  188.         $this->post_type $postType;
  189.         return $this;
  190.     }
  191.     /**
  192.      * Get postType
  193.      *
  194.      * @return integer
  195.      */
  196.     public function getPostType()
  197.     {
  198.         return $this->post_type;
  199.     }
  200.     /**
  201.      * Add content
  202.      *
  203.      * @param PostContent $content
  204.      *
  205.      * @return Post
  206.      */
  207.     public function addContent(PostContent $content)
  208.     {
  209.         $this->content[] = $content;
  210.         return $this;
  211.     }
  212.     /**
  213.      * Remove content
  214.      *
  215.      * @param PostContent $content
  216.      */
  217.     public function removeContent(PostContent $content)
  218.     {
  219.         $this->content->removeElement($content);
  220.     }
  221.     /**
  222.      * Get content
  223.      *
  224.      * @return Collection
  225.      */
  226.     public function getContent()
  227.     {
  228.         return $this->content;
  229.     }
  230.     /**
  231.      * Set creator
  232.      *
  233.      * @param User $creator
  234.      *
  235.      * @return Post
  236.      */
  237.     public function setCreator(User $creator null)
  238.     {
  239.         $this->creator $creator;
  240.         return $this;
  241.     }
  242.     /**
  243.      * Get creator
  244.      *
  245.      * @return User
  246.      */
  247.     public function getCreator()
  248.     {
  249.         return $this->creator;
  250.     }
  251.     /**
  252.      * Set dealer
  253.      *
  254.      * @param Dealer $dealer
  255.      *
  256.      * @return Post
  257.      */
  258.     public function setDealer(Dealer $dealer null)
  259.     {
  260.         $this->dealer $dealer;
  261.         return $this;
  262.     }
  263.     /**
  264.      * Get dealer
  265.      *
  266.      * @return Dealer
  267.      */
  268.     public function getDealer()
  269.     {
  270.         return $this->dealer;
  271.     }
  272.     /**
  273.      * @var integer
  274.      */
  275.     private $action_chapter;
  276.     /**
  277.      * Set actionChapter
  278.      *
  279.      * @param integer $actionChapter
  280.      *
  281.      * @return Post
  282.      */
  283.     public function setActionChapter($actionChapter)
  284.     {
  285.         $this->action_chapter $actionChapter;
  286.         return $this;
  287.     }
  288.     /**
  289.      * @param string $locale
  290.      * @return PostContent
  291.      */
  292.     public function getContentByLocale($locale 'ru')
  293.     {
  294.         if(!$locale) return $this->content->first();
  295.         /** @var PostContent $content */
  296.         foreach ($this->content as $content) {
  297.             if ($content->getLanguage() === $locale) {
  298.                 return $content;
  299.             }
  300.         }
  301.         return $this->content->first();
  302.     }
  303.     /**
  304.      * Get actionChapter
  305.      *
  306.      * @return integer
  307.      */
  308.     public function getActionChapter()
  309.     {
  310.         return $this->action_chapter;
  311.     }
  312.     /**
  313.      * @param null $locale
  314.      * @return string
  315.      */
  316.     public function getTitle($locale null)
  317.     {
  318.         $content $this->getContentByLocale($locale);
  319.         if(!$content) return '';
  320.         return $content->getTitle();
  321.     }
  322.     /**
  323.      * @param null $locale
  324.      * @return string
  325.      */
  326.     public function getDescription($locale null)
  327.     {
  328.         $content $this->getContentByLocale($locale);
  329.         if(!$content) return '';
  330.         return $content->getDescription();
  331.     }
  332.     /**
  333.      * @param null $locale
  334.      * @return string
  335.      */
  336.     public function getSeoTitle($locale null)
  337.     {
  338.         $content $this->getContentByLocale($locale);
  339.         if(!$content) return '';
  340.         return $content->getTitle();
  341.     }
  342.     /**
  343.      * @param null $locale
  344.      * @return string
  345.      */
  346.     public function getSeoDescription($locale null)
  347.     {
  348.         $content $this->getContentByLocale($locale);
  349.         if(!$content) return '';
  350.         return $content->getSeoDescription();
  351.     }
  352.     /**
  353.      * @param null $locale
  354.      * @return Media|string
  355.      */
  356.     public function getImage($locale null)
  357.     {
  358.         $content $this->getContentByLocale($locale);
  359.         if(!$content) return '';
  360.         return $content->getImage();
  361.     }
  362.     /**
  363.      * @param null $locale
  364.      * @return string
  365.      */
  366.     public function getContentHtml($locale null)
  367.     {
  368.         $content $this->getContentByLocale($locale);
  369.         if(!$content) return '';
  370.         return $content->getContent();
  371.     }
  372.     /**
  373.      * @return string
  374.      */
  375.     public function __toString()
  376.     {
  377.         return ($this->getContentByLocale()) ? (string) $this->getContentByLocale()->getTitle() : '';
  378.     }
  379.     /**
  380.      * @var string
  381.      */
  382.     private $url;
  383.     /**
  384.      * Set url
  385.      *
  386.      * @param string $url
  387.      *
  388.      * @return Post
  389.      */
  390.     public function setUrl($url)
  391.     {
  392.         $this->url $url;
  393.         return $this;
  394.     }
  395.     /**
  396.      * Get url
  397.      *
  398.      * @return string
  399.      */
  400.     public function getUrl()
  401.     {
  402.         return $this->url;
  403.     }
  404.     /**
  405.      * @var Gallery
  406.      */
  407.     private $gallery;
  408.     /**
  409.      * Set gallery
  410.      *
  411.      * @param Gallery $gallery
  412.      *
  413.      * @return Post
  414.      */
  415.     public function setGallery(Gallery $gallery null)
  416.     {
  417.         $this->gallery $gallery;
  418.         return $this;
  419.     }
  420.     /**
  421.      * Get gallery
  422.      *
  423.      * @return Gallery
  424.      */
  425.     public function getGallery()
  426.     {
  427.         return $this->gallery;
  428.     }
  429.     /**
  430.      * @var boolean
  431.      */
  432.     private $on_portal;
  433.     /**
  434.      * Set onPortal
  435.      *
  436.      * @param boolean $onPortal
  437.      *
  438.      * @return Post
  439.      */
  440.     public function setOnPortal($onPortal)
  441.     {
  442.         $this->on_portal $onPortal;
  443.         return $this;
  444.     }
  445.     /**
  446.      * Get onPortal
  447.      *
  448.      * @return boolean
  449.      */
  450.     public function getOnPortal()
  451.     {
  452.         return $this->on_portal;
  453.     }
  454.     /**
  455.      * @param $locale
  456.      * @return string
  457.      */
  458.     public function getTypeName($locale)
  459.     {
  460.         return \CoreBundle\Model\Post::getTypeName($this->getPostType(), $locale);
  461.     }
  462.     /**
  463.      * @param $locale string
  464.      * @return string
  465.      */
  466.     public function getActionTypeName($locale)
  467.     {
  468.         return \CoreBundle\Model\Post::getTypeName($this->getPostType(), $locale);
  469.     }
  470.     /**
  471.      * @var Collection
  472.      */
  473.     private $vehicles;
  474.     /**
  475.      * Add vehicle
  476.      *
  477.      * @param Vehicle $vehicle
  478.      *
  479.      * @return Post
  480.      */
  481.     public function addVehicle(Vehicle $vehicle)
  482.     {
  483.         $this->vehicles[] = $vehicle;
  484.         return $this;
  485.     }
  486.     /**
  487.      * Remove vehicle
  488.      *
  489.      * @param Vehicle $vehicle
  490.      */
  491.     public function removeVehicle(Vehicle $vehicle)
  492.     {
  493.         $this->vehicles->removeElement($vehicle);
  494.     }
  495.     /**
  496.      * Get vehicles
  497.      *
  498.      * @return Collection
  499.      */
  500.     public function getVehicles()
  501.     {
  502.         return $this->vehicles;
  503.     }
  504.     /**
  505.      * @var string
  506.      */
  507.     private $uid;
  508.     /**
  509.      * Set uid
  510.      *
  511.      * @param string $uid
  512.      *
  513.      * @return Post
  514.      */
  515.     public function setUid($uid)
  516.     {
  517.         $this->uid $uid;
  518.         return $this;
  519.     }
  520.     /**
  521.      * Get uid
  522.      *
  523.      * @return string
  524.      */
  525.     public function getUid()
  526.     {
  527.         return $this->uid;
  528.     }
  529.     /**
  530.      * @var Collection
  531.      */
  532.     private $log;
  533.     /**
  534.      * Add log
  535.      *
  536.      * @param PostLog $log
  537.      *
  538.      * @return Post
  539.      */
  540.     public function addLog(PostLog $log)
  541.     {
  542.         $this->log[] = $log;
  543.         return $this;
  544.     }
  545.     /**
  546.      * Remove log
  547.      *
  548.      * @param PostLog $log
  549.      */
  550.     public function removeLog(PostLog $log)
  551.     {
  552.         $this->log->removeElement($log);
  553.     }
  554.     /**
  555.      * Get log
  556.      *
  557.      * @return Collection
  558.      */
  559.     public function getLog()
  560.     {
  561.         return $this->log;
  562.     }
  563.     /**
  564.      * @var integer
  565.      */
  566.     private $active_link;
  567.     /**
  568.      * Set activeLink
  569.      *
  570.      * @param integer $activeLink
  571.      *
  572.      * @return Post
  573.      */
  574.     public function setActiveLink($activeLink)
  575.     {
  576.         $this->active_link $activeLink;
  577.         return $this;
  578.     }
  579.     /**
  580.      * Get activeLink
  581.      *
  582.      * @return integer
  583.      */
  584.     public function getActiveLink()
  585.     {
  586.         return $this->active_link 0;
  587.     }
  588.     /**
  589.      * @var int|null
  590.      */
  591.     private $show_button;
  592.     /**
  593.      * @var int|null
  594.      */
  595.     private $button_type;
  596.     /**
  597.      * Set showButton.
  598.      *
  599.      * @param integer $showButton
  600.      *
  601.      * @return Post
  602.      */
  603.     public function setShowButton($showButton)
  604.     {
  605.         $this->show_button $showButton;
  606.         return $this;
  607.     }
  608.     /**
  609.      * Get show_button
  610.      *
  611.      * @return integer
  612.      */
  613.     public function getShowButton()
  614.     {
  615.         return $this->show_button 0;
  616.     }
  617.     /**
  618.      * @var string|null
  619.      */
  620.     private $button_text;
  621.     /**
  622.      * @var string|null
  623.      */
  624.     private $button_href;
  625.     /**
  626.      * Set buttonText.
  627.      *
  628.      * @param string|null $buttonText
  629.      *
  630.      * @return Post
  631.      */
  632.     public function setButtonText($buttonText null)
  633.     {
  634.         $this->button_text $buttonText;
  635.         return $this;
  636.     }
  637.     /**
  638.      * Get buttonText.
  639.      *
  640.      * @return string|null
  641.      */
  642.     public function getButtonText($locale)
  643.     {
  644.         $content $this->getContentByLocale($locale);
  645.         if(!$content) return '';
  646.         return $content->getButtonText();
  647.     }
  648.     /**
  649.      * Set buttonHref.
  650.      *
  651.      * @param string|null $buttonHref
  652.      *
  653.      * @return Post
  654.      */
  655.     public function setButtonHref($buttonHref null)
  656.     {
  657.         $this->button_href $buttonHref;
  658.         return $this;
  659.     }
  660.     /**
  661.      * Get buttonHref.
  662.      *
  663.      * @return string|null
  664.      */
  665.     public function getButtonHref()
  666.     {
  667.         return $this->button_href;
  668.     }
  669.     /**
  670.      * @var string|null
  671.      */
  672.     private $modal_data;
  673.     /**
  674.      * Set modalData.
  675.      *
  676.      * @param string|null $modalData
  677.      *
  678.      * @return Post
  679.      */
  680.     public function setModalData($modalData null)
  681.     {
  682.         $this->modal_data $modalData;
  683.         return $this;
  684.     }
  685.     /**
  686.      * Get modalData.
  687.      *
  688.      * @return string|null
  689.      */
  690.     public function getModalData()
  691.     {
  692.         return $this->modal_data;
  693.     }
  694.     public function getUpdatedAt(): \DateTimeInterface
  695.     {
  696.         return $this->updatedAt;
  697.     }
  698.     public function setUpdatedAt(): self
  699.     {
  700.         $this->updatedAt = new \DateTime();
  701.         return $this;
  702.     }
  703. }