modules/XC/News/src/Model/NewsMessage.php line 22

Open in your IDE?
  1. <?php
  2. /**
  3.  * Copyright (c) 2011-present Qualiteam software Ltd. All rights reserved.
  4.  * See https://www.x-cart.com/license-agreement.html for license details.
  5.  */
  6. namespace XC\News\Model;
  7. use Doctrine\ORM\Mapping as ORM;
  8. /**
  9.  * NewsMessage
  10.  *
  11.  * @ORM\Entity
  12.  * @ORM\Table  (name="news",
  13.  *      indexes={
  14.  *          @ORM\Index (name="enabled", columns={"enabled"}),
  15.  *      }
  16.  * )
  17.  */
  18. class NewsMessage extends \XLite\Model\Base\Catalog
  19. {
  20.     /**
  21.      * Unique ID
  22.      *
  23.      * @var integer
  24.      *
  25.      * @ORM\Id
  26.      * @ORM\GeneratedValue (strategy="AUTO")
  27.      * @ORM\Column         (type="integer", options={ "unsigned": true })
  28.      */
  29.     protected $id;
  30.     /**
  31.      * Is menu enabled or not
  32.      *
  33.      * @var boolean
  34.      *
  35.      * @ORM\Column (type="boolean")
  36.      */
  37.     protected $enabled true;
  38.     /**
  39.      * Date add news message
  40.      *
  41.      * @var integer
  42.      *
  43.      * @ORM\Column (type="integer")
  44.      */
  45.     protected $date;
  46.     /**
  47.      * Clean URLs
  48.      *
  49.      * @var \Doctrine\Common\Collections\Collection
  50.      *
  51.      * @ORM\OneToMany (targetEntity="XLite\Model\CleanURL", mappedBy="newsMessage", cascade={"all"})
  52.      * @ORM\OrderBy   ({"id" = "ASC"})
  53.      */
  54.     protected $cleanURLs;
  55.     /**
  56.      * Meta description type
  57.      *
  58.      * @var string
  59.      *
  60.      * @ORM\Column (type="string", length=1)
  61.      */
  62.     protected $metaDescType 'A';
  63.     /**
  64.      * @var \Doctrine\Common\Collections\Collection
  65.      *
  66.      * @ORM\OneToMany (targetEntity="XC\News\Model\NewsMessageTranslation", mappedBy="owner", cascade={"all"})
  67.      */
  68.     protected $translations;
  69.     /**
  70.      * Check - news is enabled or not
  71.      *
  72.      * @return boolean
  73.      */
  74.     public function isEnabled()
  75.     {
  76.         return $this->getEnabled()
  77.             && $this->getDate() < \XLite\Core\Converter::time();
  78.     }
  79.     /**
  80.      * Get front URL
  81.      *
  82.      * @return string
  83.      */
  84.     public function getFrontURL()
  85.     {
  86.         $url null;
  87.         if ($this->getId()) {
  88.             $url \XLite\Core\Converter::makeURLValid(
  89.                 \XLite::getInstance()->getShopURL(
  90.                     \XLite\Core\Converter::buildURL(
  91.                         'newsMessage',
  92.                         '',
  93.                         ['id' => $this->getId()],
  94.                         \XLite::getCustomerScript(),
  95.                         true
  96.                     )
  97.                 )
  98.             );
  99.         }
  100.         return $url;
  101.     }
  102.     /**
  103.      * Returns meta description
  104.      *
  105.      * @return string
  106.      */
  107.     public function getMetaDesc()
  108.     {
  109.         return $this->getMetaDescType() === 'A' || !$this->getSoftTranslation()->getMetaDesc()
  110.             ? static::postprocessMetaDescription($this->getBody())
  111.             : $this->getSoftTranslation()->getMetaDesc();
  112.     }
  113.     /**
  114.      * Returns meta description type
  115.      *
  116.      * @return string
  117.      */
  118.     public function getMetaDescType()
  119.     {
  120.         $result $this->metaDescType;
  121.         if (!$result) {
  122.             $metaDescPresent array_reduce($this->getTranslations()->toArray(), static function ($carry$item) {
  123.                 return $carry ?: (bool) $item->getMetaDesc();
  124.             }, false);
  125.             $result $metaDescPresent 'C' 'A';
  126.         }
  127.         return $result;
  128.     }
  129.     /**
  130.      * Get id
  131.      *
  132.      * @return integer
  133.      */
  134.     public function getId()
  135.     {
  136.         return $this->id;
  137.     }
  138.     /**
  139.      * Set enabled
  140.      *
  141.      * @param boolean $enabled
  142.      * @return NewsMessage
  143.      */
  144.     public function setEnabled($enabled)
  145.     {
  146.         $this->enabled = (bool)$enabled;
  147.         return $this;
  148.     }
  149.     /**
  150.      * Get enabled
  151.      *
  152.      * @return boolean
  153.      */
  154.     public function getEnabled()
  155.     {
  156.         return $this->enabled;
  157.     }
  158.     /**
  159.      * Set date
  160.      *
  161.      * @param integer $date
  162.      * @return NewsMessage
  163.      */
  164.     public function setDate($date)
  165.     {
  166.         $this->date $date;
  167.         return $this;
  168.     }
  169.     /**
  170.      * Get date
  171.      *
  172.      * @return integer
  173.      */
  174.     public function getDate()
  175.     {
  176.         return $this->date;
  177.     }
  178.     /**
  179.      * Set metaDescType
  180.      *
  181.      * @param string $metaDescType
  182.      * @return NewsMessage
  183.      */
  184.     public function setMetaDescType($metaDescType)
  185.     {
  186.         $this->metaDescType $metaDescType;
  187.         return $this;
  188.     }
  189.     /**
  190.      * Add cleanURLs
  191.      *
  192.      * @param \XLite\Model\CleanURL $cleanURLs
  193.      * @return NewsMessage
  194.      */
  195.     public function addCleanURLs(\XLite\Model\CleanURL $cleanURLs)
  196.     {
  197.         $this->cleanURLs[] = $cleanURLs;
  198.         return $this;
  199.     }
  200.     /**
  201.      * Get cleanURLs
  202.      *
  203.      * @return \Doctrine\Common\Collections\Collection
  204.      */
  205.     public function getCleanURLs()
  206.     {
  207.         return $this->cleanURLs;
  208.     }
  209.     // {{{ Translation Getters / setters
  210.     /**
  211.      * @return string
  212.      */
  213.     public function getBody()
  214.     {
  215.         return $this->getTranslationField(__FUNCTION__);
  216.     }
  217.     /**
  218.      * @param string $body
  219.      *
  220.      * @return \XLite\Model\Base\Translation
  221.      */
  222.     public function setBody($body)
  223.     {
  224.         return $this->setTranslationField(__FUNCTION__$body);
  225.     }
  226.     /**
  227.      * @return string
  228.      */
  229.     public function getBriefDescription()
  230.     {
  231.         return $this->getTranslationField(__FUNCTION__);
  232.     }
  233.     /**
  234.      * @param string $briefDescription
  235.      *
  236.      * @return \XLite\Model\Base\Translation
  237.      */
  238.     public function setBriefDescription($briefDescription)
  239.     {
  240.         return $this->setTranslationField(__FUNCTION__$briefDescription);
  241.     }
  242.     /**
  243.      * @return string
  244.      */
  245.     public function getMetaTags()
  246.     {
  247.         return $this->getTranslationField(__FUNCTION__);
  248.     }
  249.     /**
  250.      * @param string $metaTags
  251.      *
  252.      * @return \XLite\Model\Base\Translation
  253.      */
  254.     public function setMetaTags($metaTags)
  255.     {
  256.         return $this->setTranslationField(__FUNCTION__$metaTags);
  257.     }
  258.     /**
  259.      * @param string $country
  260.      *
  261.      * @return \XLite\Model\Base\Translation
  262.      */
  263.     public function setMetaDesc($country)
  264.     {
  265.         return $this->setTranslationField(__FUNCTION__$country);
  266.     }
  267.     /**
  268.      * @return string
  269.      */
  270.     public function getMetaTitle()
  271.     {
  272.         return $this->getTranslationField(__FUNCTION__);
  273.     }
  274.     /**
  275.      * @param string $metaTitle
  276.      *
  277.      * @return \XLite\Model\Base\Translation
  278.      */
  279.     public function setMetaTitle($metaTitle)
  280.     {
  281.         return $this->setTranslationField(__FUNCTION__$metaTitle);
  282.     }
  283.     // }}}
  284. }