<?php
namespace App\Entity;
use App\Traits\Actions;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\UploadedFile;
#[ORM\Table(name: 'hs_training_center_news')]
#[ORM\Entity(repositoryClass: "App\Repository\NewsRepository")]
class News
{
use Actions;
#[ORM\Column(name: 'title', type: 'string', length: 255)]
private string $title;
#[ORM\Column(name: 'sub_title', type: 'string', length: 255, nullable: true)]
private ?string $subTitle;
#[ORM\Column(name: 'slug', type: 'string', length: 255)]
private string $slug;
#[ORM\Column(name: 'link', type: 'string', length: 255, nullable: true)]
private string $link;
#[ORM\Column(name: 'image1_name', type: 'string', length: 255, nullable: true)]
protected string $image1Name;
protected UploadedFile $image1File;
#[ORM\Column(name: 'image2_name', type: 'string', length: 255, nullable: true)]
protected string $image2Name;
protected UploadedFile $image2File;
#[ORM\Column(name: 'featured', type: 'boolean')]
private bool $featured;
#[ORM\Column(name: 'start_at', type: 'datetime', nullable: true)]
private \DateTime $startAt;
#[ORM\Column(name: 'end_at', type: 'datetime', nullable: true)]
private \DateTime $endAt;
#[ORM\Column(name: 'abstract', type: 'text', nullable: true)]
private ?string $abstract;
public function __construct()
{
// date_default_timezone_set('Africa/Casablanca');
$this->createAt=new \DateTime('now');
$this->published=true;
$this->featured=false;
$this->image1Name='news.png';
$this->image2Name='news.png';
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* @param string $title
* @return News
*/
public function setTitle($title)
{
$this->title = $title;
$this->setSlug($this->slugify($title));
return $this;
}
/**
* @return string
*/
public function getSubTitle()
{
return $this->subTitle;
}
/**
* @param string $subTitle
* @return News
*/
public function setSubTitle($subTitle)
{
$this->subTitle = $subTitle;
return $this;
}
/**
* @return string
*/
public function getImage1Name()
{
return $this->image1Name;
}
/**
* @param string $image1Name
* @return News
*/
public function setImage1Name($image1Name)
{
$this->image1Name = $image1Name;
return $this;
}
/**
* @return mixed
*/
public function getImage1File()
{
return $this->image1File;
}
/**
* @param mixed $image1File
* @return News
*/
public function setImage1File(UploadedFile $image1File=null)
{
$this->image1File = $image1File;
return $this;
}
/**
* @return string
*/
public function getImage2Name()
{
return $this->image2Name;
}
/**
* @param string $image2Name
* @return News
*/
public function setImage2Name($image2Name)
{
$this->image2Name = $image2Name;
return $this;
}
/**
* @return mixed
*/
public function getImage2File()
{
return $this->image2File;
}
/**
* @param mixed $image2File
* @return News
*/
public function setImage2File(UploadedFile $image2File=null)
{
$this->image2File = $image2File;
return $this;
}
/**
* @return string
*/
public function getLink()
{
return $this->link;
}
/**
* @param string $link
* @return News
*/
public function setLink($link)
{
$this->link = $link;
return $this;
}
/**
* @return bool
*/
public function isFeatured()
{
return $this->featured;
}
/**
* @return bool
*/
public function getFeatured()
{
return $this->featured;
}
/**
* @param bool $featured
* @return News
*/
public function setFeatured($featured)
{
$this->featured = $featured;
return $this;
}
/**
* @return \DateTime
*/
public function getStartAt()
{
return $this->startAt;
}
/**
* @param \DateTime $startAt
* @return News
*/
public function setStartAt($startAt)
{
$this->startAt = $startAt;
return $this;
}
/**
* @return \DateTime
*/
public function getEndAt()
{
return $this->endAt;
}
/**
* @param \DateTime $endAt
* @return News
*/
public function setEndAt($endAt)
{
$this->endAt = $endAt;
return $this;
}
/**
* @return string
*/
public function getSlug()
{
return $this->slug;
}
/**
* @param string $slug
* @return News
*/
public function setSlug($slug)
{
$this->slug = $slug;
return $this;
}
/**
* @return string
*/
public function getAbstract()
{
return $this->abstract;
}
/**
* @param string $abstract
* @return News
*/
public function setAbstract($abstract)
{
$this->abstract = $abstract;
return $this;
}
function __toString()
{
return $this->title;
}
public function slugify($title)
{
// replace non letter or digits by -
$text = preg_replace('~[^\pL\d]+~u', '-', $title);
// transliterate
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
// remove unwanted characters
$text = preg_replace('~[^-\w]+~', '', $text);
// trim
$text = trim($text, '-');
// remove duplicate -
$text = preg_replace('~-+~', '-', $text);
// lowercase
$text = strtolower($text);
if (empty($text)) {
return uniqid();
}
return $text;
}
public function getButtonFeatured()
{
$confirm="data-toggle='confirmation'
data-btn-ok-label='Oui'
data-btn-ok-icon='glyphicon glyphicon-ok'
data-btn-ok-class='btn-success'
data-btn-cancel-label='Non'
data-btn-cancel-icon='glyphicon glyphicon-remove'
data-btn-cancel-class='btn-danger'
data-title='Changer statut ?'
data-popout='true'
data-content='Voulez-vous vraiment changer le statut de cet élément ?' ";
if($this->featured)
$icon= "<i class=\"text-green fa fa-toggle-on\"> Oui</i>";
else
$icon= "<i class=\"text-red fa fa-toggle-off\"> Non</i>";
$btn="<a ".$confirm." href='javascript:void(0)' class='boledit' data-boledit-id='".$this->id."' data-boledit-route='".$this->getRoute('featured')."'>".$icon."</a> </td>";
return $btn;
}
}