<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="App\Repository\OmeloPostRepository")
*/
class OmeloPost
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $title;
/**
* @ORM\Column(type="text")
*/
private $resume;
/**
* @ORM\Column(type="text")
*/
private $text;
/**
* @ORM\Column(type="string", length=3)
*/
private $lang;
/**
* @ORM\Column(type="datetime")
*/
private $creationDate;
/**
* @ORM\Column(type="datetime")
*/
private $publicationDate;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Image")
* @ORM\JoinColumn(onDelete="CASCADE")
*/
private $image;
/**
* @ORM\Column(type="boolean")
*/
private $active;
/**
* @ORM\Column(type="string", length=100, nullable=true)
*/
private $metaTitle;
/**
* @ORM\Column(type="string", length=200, nullable=true)
*/
private $metaDescription;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $author;
public function __construct(){
$this->creationDate = new \DateTime();
}
public function getId(): ?int
{
return $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): self
{
$this->title = $title;
return $this;
}
public function getResume(): ?string
{
return $this->resume;
}
public function setResume(string $resume): self
{
$this->resume= $resume;
return $this;
}
public function getText(): ?string
{
return $this->text;
}
public function setText(string $text): self
{
$this->text = $text;
return $this;
}
public function getLang(): ?string
{
return $this->lang;
}
public function setLang(string $lang): self
{
$this->lang = $lang;
return $this;
}
public function getCreationDate(): ?\DateTimeInterface
{
return $this->creationDate;
}
public function setCreationDate(\DateTimeInterface $creationDate): self
{
$this->creationDate = $creationDate;
return $this;
}
public function getPublicationDate(): ?\DateTimeInterface
{
return $this->publicationDate;
}
public function setPublicationDate(\DateTimeInterface $publicationDate): self
{
$this->publicationDate = $publicationDate;
return $this;
}
public function getImage(): ?Image
{
return $this->image;
}
public function setImage(?Image $image): self
{
if(!empty($image))
$this->image = $image;
return $this;
}
public function getDateSince(){
$time = time() - $this->getPublicationDate()->getTimestamp(); // to get the time since that moment
$time = ($time<1)? 1 : $time;
$tokens = array (
31536000 => 'ans',
2592000 => 'mois',
604800 => 'semaine',
86400 => 'jour',
3600 => 'heure',
60 => 'minute',
1 => 'seconde'
);
foreach ($tokens as $unit => $text) {
if ($time < $unit) continue;
$numberOfUnits = floor($time / $unit);
return $numberOfUnits.' '.$text.(($numberOfUnits>1 && $text != 'ans' && $text != 'mois')?'s':'');
}
}
public function getUrlTitle(): ?string
{
$unwanted_array = array( 'Š'=>'S', 'š'=>'s', 'Ž'=>'Z', 'ž'=>'z', 'À'=>'A', 'Á'=>'A', 'Â'=>'A', 'Ã'=>'A', 'Ä'=>'A', 'Å'=>'A', 'Æ'=>'A', 'Ç'=>'C', 'È'=>'E', 'É'=>'E',
'Ê'=>'E', 'Ë'=>'E', 'Ì'=>'I', 'Í'=>'I', 'Î'=>'I', 'Ï'=>'I', 'Ñ'=>'N', 'Ò'=>'O', 'Ó'=>'O', 'Ô'=>'O', 'Õ'=>'O', 'Ö'=>'O', 'Ø'=>'O', 'Ù'=>'U',
'Ú'=>'U', 'Û'=>'U', 'Ü'=>'U', 'Ý'=>'Y', 'Þ'=>'B', 'ß'=>'Ss', 'à'=>'a', 'á'=>'a', 'â'=>'a', 'ã'=>'a', 'ä'=>'a', 'å'=>'a', 'æ'=>'a', 'ç'=>'c',
'è'=>'e', 'é'=>'e', 'ê'=>'e', 'ë'=>'e', 'ì'=>'i', 'í'=>'i', 'î'=>'i', 'ï'=>'i', 'ð'=>'o', 'ñ'=>'n', 'ò'=>'o', 'ó'=>'o', 'ô'=>'o', 'õ'=>'o',
'ö'=>'o', 'ø'=>'o', 'ù'=>'u', 'ú'=>'u', 'û'=>'u', 'ý'=>'y', 'þ'=>'b', 'ÿ'=>'y' );
$str = strtr( $this->title, $unwanted_array );
return urlencode(str_replace(' ', '-', strtolower($str)));
}
public function getActive(): ?bool
{
return $this->active;
}
public function setActive(bool $active): self
{
$this->active = $active;
return $this;
}
public function getMetaTitle(): ?string
{
return $this->metaTitle;
}
public function setMetaTitle(string $metaTitle): self
{
$this->metaTitle = $metaTitle;
return $this;
}
public function getMetaDescription(): ?string
{
return $this->metaDescription;
}
public function setMetaDescription(?string $metaDescription): self
{
$this->metaDescription = $metaDescription;
return $this;
}
public function getAuthor(): ?string
{
//For legacy keeping the old ways
if(empty($this->author) && !empty($this->image)){
return $this->getImage()->getUser()->getDisplayName();
}
return $this->author;
}
public function setAuthor(?string $author): self
{
$this->author = $author;
return $this;
}
}