src/Entity/OmeloPost.php line 10

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. /**
  5.  * @ORM\Entity(repositoryClass="App\Repository\OmeloPostRepository")
  6.  */
  7. class OmeloPost
  8. {
  9.     /**
  10.      * @ORM\Id()
  11.      * @ORM\GeneratedValue()
  12.      * @ORM\Column(type="integer")
  13.      */
  14.     private $id;
  15.     /**
  16.      * @ORM\Column(type="string", length=255)
  17.      */
  18.     private $title;
  19.     /**
  20.      * @ORM\Column(type="text")
  21.      */
  22.     private $resume;
  23.     /**
  24.      * @ORM\Column(type="text")
  25.      */
  26.     private $text;
  27.     /**
  28.      * @ORM\Column(type="string", length=3)
  29.      */
  30.     private $lang;
  31.     /**
  32.      * @ORM\Column(type="datetime")
  33.      */
  34.     private $creationDate;
  35.     /**
  36.      * @ORM\Column(type="datetime")
  37.      */
  38.     private $publicationDate;
  39.     /**
  40.      * @ORM\ManyToOne(targetEntity="App\Entity\Image")
  41.      * @ORM\JoinColumn(onDelete="CASCADE")
  42.      */
  43.     private $image;
  44.     /**
  45.      * @ORM\Column(type="boolean")
  46.      */
  47.     private $active;
  48.     /**
  49.      * @ORM\Column(type="string", length=100, nullable=true)
  50.      */
  51.     private $metaTitle;
  52.     /**
  53.      * @ORM\Column(type="string", length=200, nullable=true)
  54.      */
  55.     private $metaDescription;
  56.     /**
  57.      * @ORM\Column(type="string", length=255, nullable=true)
  58.      */
  59.     private $author;
  60.     public function __construct(){
  61.         $this->creationDate = new \DateTime();
  62.     }
  63.     public function getId(): ?int
  64.     {
  65.         return $this->id;
  66.     }
  67.     public function getTitle(): ?string
  68.     {
  69.         return $this->title;
  70.     }
  71.     public function setTitle(string $title): self
  72.     {
  73.         $this->title $title;
  74.         return $this;
  75.     }
  76.     public function getResume(): ?string
  77.     {
  78.         return $this->resume;
  79.     }
  80.     public function setResume(string $resume): self
  81.     {
  82.         $this->resume$resume;
  83.         return $this;
  84.     }
  85.     public function getText(): ?string
  86.     {
  87.         return $this->text;
  88.     }
  89.     public function setText(string $text): self
  90.     {
  91.         $this->text $text;
  92.         return $this;
  93.     }
  94.     public function getLang(): ?string
  95.     {
  96.         return $this->lang;
  97.     }
  98.     public function setLang(string $lang): self
  99.     {
  100.         $this->lang $lang;
  101.         return $this;
  102.     }
  103.     public function getCreationDate(): ?\DateTimeInterface
  104.     {
  105.         return $this->creationDate;
  106.     }
  107.     public function setCreationDate(\DateTimeInterface $creationDate): self
  108.     {
  109.         $this->creationDate $creationDate;
  110.         return $this;
  111.     }
  112.     public function getPublicationDate(): ?\DateTimeInterface
  113.     {
  114.         return $this->publicationDate;
  115.     }
  116.     public function setPublicationDate(\DateTimeInterface $publicationDate): self
  117.     {
  118.         $this->publicationDate $publicationDate;
  119.         return $this;
  120.     }
  121.     public function getImage(): ?Image
  122.     {
  123.         return $this->image;
  124.     }
  125.     public function setImage(?Image $image): self
  126.     {
  127.         if(!empty($image))
  128.             $this->image $image;
  129.         return $this;
  130.     }
  131.     public function getDateSince(){
  132.         $time time() - $this->getPublicationDate()->getTimestamp(); // to get the time since that moment
  133.         $time = ($time<1)? $time;
  134.         $tokens = array (
  135.             31536000 => 'ans',
  136.             2592000 => 'mois',
  137.             604800 => 'semaine',
  138.             86400 => 'jour',
  139.             3600 => 'heure',
  140.             60 => 'minute',
  141.             => 'seconde'
  142.         );
  143.         foreach ($tokens as $unit => $text) {
  144.             if ($time $unit) continue;
  145.             $numberOfUnits floor($time $unit);
  146.             return $numberOfUnits.' '.$text.(($numberOfUnits>&& $text != 'ans' && $text != 'mois')?'s':'');
  147.         }
  148.     }
  149.     public function getUrlTitle(): ?string
  150.     {
  151.         $unwanted_array = array(    'Š'=>'S''š'=>'s''Ž'=>'Z''ž'=>'z''À'=>'A''Á'=>'A''Â'=>'A''Ã'=>'A''Ä'=>'A''Å'=>'A''Æ'=>'A''Ç'=>'C''È'=>'E''É'=>'E',
  152.             'Ê'=>'E''Ë'=>'E''Ì'=>'I''Í'=>'I''Î'=>'I''Ï'=>'I''Ñ'=>'N''Ò'=>'O''Ó'=>'O''Ô'=>'O''Õ'=>'O''Ö'=>'O''Ø'=>'O''Ù'=>'U',
  153.             'Ú'=>'U''Û'=>'U''Ü'=>'U''Ý'=>'Y''Þ'=>'B''ß'=>'Ss''à'=>'a''á'=>'a''â'=>'a''ã'=>'a''ä'=>'a''å'=>'a''æ'=>'a''ç'=>'c',
  154.             'è'=>'e''é'=>'e''ê'=>'e''ë'=>'e''ì'=>'i''í'=>'i''î'=>'i''ï'=>'i''ð'=>'o''ñ'=>'n''ò'=>'o''ó'=>'o''ô'=>'o''õ'=>'o',
  155.             'ö'=>'o''ø'=>'o''ù'=>'u''ú'=>'u''û'=>'u''ý'=>'y''þ'=>'b''ÿ'=>'y' );
  156.         $str strtr$this->title$unwanted_array );
  157.         return urlencode(str_replace(' ''-'strtolower($str)));
  158.     }
  159.     public function getActive(): ?bool
  160.     {
  161.         return $this->active;
  162.     }
  163.     public function setActive(bool $active): self
  164.     {
  165.         $this->active $active;
  166.         return $this;
  167.     }
  168.     public function getMetaTitle(): ?string
  169.     {
  170.         return $this->metaTitle;
  171.     }
  172.     public function setMetaTitle(string $metaTitle): self
  173.     {
  174.         $this->metaTitle $metaTitle;
  175.         return $this;
  176.     }
  177.     public function getMetaDescription(): ?string
  178.     {
  179.         return $this->metaDescription;
  180.     }
  181.     public function setMetaDescription(?string $metaDescription): self
  182.     {
  183.         $this->metaDescription $metaDescription;
  184.         return $this;
  185.     }
  186.     public function getAuthor(): ?string
  187.     {
  188.         //For legacy keeping the old ways
  189.         if(empty($this->author) && !empty($this->image)){
  190.             return $this->getImage()->getUser()->getDisplayName();
  191.         }
  192.         return $this->author;
  193.     }
  194.     public function setAuthor(?string $author): self
  195.     {
  196.         $this->author $author;
  197.         return $this;
  198.     }
  199. }