vendor/webbamboo/spinners-common/src/Entity/Article.php line 14

  1. <?php
  2. namespace Webbamboo\SpinnersCommon\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. /**
  5.  * Article
  6.  *
  7.  * @ORM\Table("Article")
  8.  * @ORM\Entity
  9.  */
  10. #[ORM\Entity(repositoryClassArticleRepository::class)]
  11. class Article
  12. {
  13.     public const STATUS_DRAFT 'draft';
  14.     public const STATUS_PUBLISHED 'published';
  15.     /**
  16.      * @var integer
  17.      *
  18.      * @ORM\Column(name="id", type="integer")
  19.      * @ORM\Id
  20.      * @ORM\GeneratedValue(strategy="AUTO")
  21.      */
  22.     private $id;
  23.     /**
  24.      * @var string
  25.      *
  26.      * @ORM\Column(name="title", type="string", length=255)
  27.      */
  28.     private $title;
  29.     /**
  30.      * @var string
  31.      *
  32.      * @ORM\Column(name="metatitle", type="string", length=255)
  33.      */
  34.     private $metatitle;
  35.     /**
  36.      * @var string
  37.      *
  38.      * @ORM\Column(name="metadescription", type="string", length=255)
  39.      */
  40.     private $metadescription;
  41.     /**
  42.      * @var string
  43.      *
  44.      * @ORM\Column(name="permalink", type="string", length=255)
  45.      */
  46.     private $permalink;
  47.     /**
  48.      * @var string
  49.      *
  50.      * @ORM\Column(name="content", type="text")
  51.      */
  52.     private $content;
  53.     /**
  54.      * @var string
  55.      *
  56.      * @ORM\Column(name="interestingarticle1", type="string", length=255, nullable=true)
  57.      */
  58.     private $interestingtitle1;
  59.     /**
  60.      * @var string
  61.      *
  62.      * @ORM\Column(name="interestingarticle2", type="string", length=255, nullable=true)
  63.      */
  64.     private $interestingtitle2;
  65.     /**
  66.      * @var string
  67.      *
  68.      * @ORM\Column(name="interestingarticle3", type="string", length=255, nullable=true)
  69.      */
  70.     private $interestingtitle3;
  71.     /**
  72.      * @var string
  73.      *
  74.      * @ORM\Column(name="interestingarticle4", type="string", length=255, nullable=true)
  75.      */
  76.     private $interestingtitle4;
  77.     /**
  78.      * @var string
  79.      *
  80.      * @ORM\Column(name="interestingarticle5", type="string", length=255, nullable=true)
  81.      */
  82.     private $interestingtitle5;
  83.     /**
  84.      * @var \DateTime
  85.      *
  86.      * @ORM\Column(name="published", type="datetime")
  87.      */
  88.     private $published;
  89.     /**
  90.      * @var string
  91.      *
  92.      * @ORM\Column(name="status", type="string", length=255, nullable=true)
  93.      */
  94.     private $status self::STATUS_PUBLISHED;
  95.     /**
  96.      * Get id
  97.      *
  98.      * @return integer
  99.      */
  100.     public function getId()
  101.     {
  102.         return $this->id;
  103.     }
  104.     /**
  105.      * Set title
  106.      *
  107.      * @param string $title
  108.      * @return Article
  109.      */
  110.     public function setTitle($title)
  111.     {
  112.         $this->title $title;
  113.         return $this;
  114.     }
  115.     /**
  116.      * Get title
  117.      *
  118.      * @return string
  119.      */
  120.     public function getTitle()
  121.     {
  122.         return $this->title;
  123.     }
  124.     /**
  125.      * Set metatitle
  126.      *
  127.      * @param string $metatitle
  128.      * @return Article
  129.      */
  130.     public function setMetatitle($metatitle)
  131.     {
  132.         $this->metatitle $metatitle;
  133.         return $this;
  134.     }
  135.     /**
  136.      * Get metatitle
  137.      *
  138.      * @return string
  139.      */
  140.     public function getMetatitle()
  141.     {
  142.         return $this->metatitle;
  143.     }
  144.     /**
  145.      * Set metadescription
  146.      *
  147.      * @param string $metadescription
  148.      * @return Article
  149.      */
  150.     public function setMetadescription($metadescription)
  151.     {
  152.         $this->metadescription $metadescription;
  153.         return $this;
  154.     }
  155.     /**
  156.      * Get metadescription
  157.      *
  158.      * @return string
  159.      */
  160.     public function getMetadescription()
  161.     {
  162.         return $this->metadescription;
  163.     }
  164.     /**
  165.      * Set permalink
  166.      *
  167.      * @param string $permalink
  168.      * @return Article
  169.      */
  170.     public function setPermalink($permalink)
  171.     {
  172.         $this->permalink $permalink;
  173.         return $this;
  174.     }
  175.     /**
  176.      * Get permalink
  177.      *
  178.      * @return string
  179.      */
  180.     public function getPermalink()
  181.     {
  182.         return $this->permalink;
  183.     }
  184.     public function getPermalinkP()
  185.     {
  186.         $url=array(
  187.         "%C3%85","%C3%A5",
  188.         "%C3%84","%C3%A4",
  189.         "%C3%96","%C3%B6",
  190.         );
  191.         $char=array(
  192.          "Å","å",
  193.          "Ä","ä",
  194.          "Ö","ö",
  195.         );
  196.         return str_replace($url$char$this->permalink);
  197.     }
  198.     /**
  199.      * Set content
  200.      *
  201.      * @param string $content
  202.      * @return Article
  203.      */
  204.     public function setContent($content)
  205.     {
  206.         $this->content $content;
  207.         return $this;
  208.     }
  209.     /**
  210.      * Get content
  211.      *
  212.      * @return string
  213.      */
  214.     public function getContent($stripped=false)
  215.     {
  216.         if (!$stripped) {
  217.             return $this->content;
  218.         } else {
  219.             return str_replace(array('[part]''[/part]'), ''$this->content);
  220.         }
  221.     }
  222.     private function first_n_words($text$number_of_words)
  223.     {
  224.         $text strip_tags($text);
  225.         $text preg_replace("/^\W*((\w[\w'-]*\b\W*){1,$number_of_words}).*/ms"'\\1'$text);
  226.         return str_replace("\n"""$text);
  227.     }
  228.     // excerpt plus link if shortened
  229.     public function getExcerpt2($number_of_words=50)
  230.     {
  231.         $text=str_replace(array('[part]''[/part]'), ''$this->content);
  232.         $text strip_tags(html_entity_decode($text));
  233.         $excerpt $this->first_n_words($text$number_of_words);
  234.         return htmlentities($excerpt).'... <a href="[ReadMoreURL]">[ReadMoreText]</a></p>';
  235.     }
  236.     public function getRandomexcerpt()
  237.     {
  238.         $delimiter '#';
  239.         $startTag '[part]';
  240.         $endTag '[/part]';
  241.         $regex $delimiter preg_quote($startTag$delimiter)
  242.                             . '(.*?)'
  243.                             preg_quote($endTag$delimiter)
  244.                             . $delimiter
  245.                             's';
  246.         preg_match_all($regex$this->content$matches);
  247.         //var_dump($matches[1]);
  248.         shuffle($matches[1]);
  249.         $text $matches[1][0];
  250.         $text strip_tags(html_entity_decode($text));
  251.         $excerpt $this->first_n_words($text50);
  252.         return htmlentities($excerpt).'... <a href="[ReadMoreURL]">[ReadMoreText]</a></p>';
  253.     }
  254.     /**
  255.      * Set published
  256.      *
  257.      * @param \DateTime $published
  258.      * @return Article
  259.      */
  260.     public function setPublished($published)
  261.     {
  262.         $this->published $published;
  263.         return $this;
  264.     }
  265.     /**
  266.      * Get published
  267.      *
  268.      * @return \DateTime
  269.      */
  270.     public function getPublished()
  271.     {
  272.         return $this->published;
  273.     }
  274.     /**
  275.      * Set interestingtitle1
  276.      *
  277.      * @param string $interestingtitle1
  278.      * @return Article
  279.      */
  280.     public function setInterestingtitle1($interestingtitle1)
  281.     {
  282.         $this->interestingtitle1 $interestingtitle1;
  283.         return $this;
  284.     }
  285.     /**
  286.      * Get interestingtitle1
  287.      *
  288.      * @return string
  289.      */
  290.     public function getInterestingtitle1()
  291.     {
  292.         return $this->interestingtitle1;
  293.     }
  294.     /**
  295.      * Set interestingtitle2
  296.      *
  297.      * @param string $interestingtitle2
  298.      * @return Article
  299.      */
  300.     public function setInterestingtitle2($interestingtitle2)
  301.     {
  302.         $this->interestingtitle2 $interestingtitle2;
  303.         return $this;
  304.     }
  305.     /**
  306.      * Get interestingtitle2
  307.      *
  308.      * @return string
  309.      */
  310.     public function getInterestingtitle2()
  311.     {
  312.         return $this->interestingtitle2;
  313.     }
  314.     /**
  315.      * Set interestingtitle3
  316.      *
  317.      * @param string $interestingtitle3
  318.      * @return Article
  319.      */
  320.     public function setInterestingtitle3($interestingtitle3)
  321.     {
  322.         $this->interestingtitle3 $interestingtitle3;
  323.         return $this;
  324.     }
  325.     /**
  326.      * Get interestingtitle3
  327.      *
  328.      * @return string
  329.      */
  330.     public function getInterestingtitle3()
  331.     {
  332.         return $this->interestingtitle3;
  333.     }
  334.     /**
  335.      * Set interestingtitle4
  336.      *
  337.      * @param string $interestingtitle4
  338.      * @return Article
  339.      */
  340.     public function setInterestingtitle4($interestingtitle4)
  341.     {
  342.         $this->interestingtitle4 $interestingtitle4;
  343.         return $this;
  344.     }
  345.     /**
  346.      * Get interestingtitle4
  347.      *
  348.      * @return string
  349.      */
  350.     public function getInterestingtitle4()
  351.     {
  352.         return $this->interestingtitle4;
  353.     }
  354.     /**
  355.      * Set interestingtitle5
  356.      *
  357.      * @param string $interestingtitle5
  358.      * @return Article
  359.      */
  360.     public function setInterestingtitle5($interestingtitle5)
  361.     {
  362.         $this->interestingtitle5 $interestingtitle5;
  363.         return $this;
  364.     }
  365.     /**
  366.      * Get interestingtitle5
  367.      *
  368.      * @return string
  369.      */
  370.     public function getInterestingtitle5()
  371.     {
  372.         return $this->interestingtitle5;
  373.     }
  374.     /**
  375.      * Set status
  376.      *
  377.      * @param string $status
  378.      * @return Article
  379.      */
  380.     public function setStatus($status)
  381.     {
  382.         $this->status $status;
  383.         return $this;
  384.     }
  385.     /**
  386.      * Get status
  387.      *
  388.      * @return string
  389.      */
  390.     public function getStatus()
  391.     {
  392.         return $this->status;
  393.     }
  394. }