src/Entity/News.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Traits\Actions;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Symfony\Component\HttpFoundation\File\UploadedFile;
  7. #[ORM\Table(name'hs_training_center_news')]
  8. #[ORM\Entity(repositoryClass"App\Repository\NewsRepository")]
  9. class News
  10. {
  11.     use Actions;
  12.     #[ORM\Column(name'title'type'string'length255)]
  13.     private string $title;
  14.     #[ORM\Column(name'sub_title'type'string'length255nullabletrue)]
  15.     private ?string $subTitle;
  16.     #[ORM\Column(name'slug'type'string'length255)]
  17.     private string $slug;
  18.     #[ORM\Column(name'link'type'string'length255nullabletrue)]
  19.     private string $link;
  20.     #[ORM\Column(name'image1_name'type'string'length255nullabletrue)]
  21.     protected string $image1Name;
  22.     protected UploadedFile $image1File;
  23.     #[ORM\Column(name'image2_name'type'string'length255nullabletrue)]
  24.     protected string $image2Name;
  25.     protected UploadedFile $image2File;
  26.     #[ORM\Column(name'featured'type'boolean')]
  27.     private bool $featured;
  28.     #[ORM\Column(name'start_at'type'datetime'nullabletrue)]
  29.     private \DateTime $startAt;
  30.     #[ORM\Column(name'end_at'type'datetime'nullabletrue)]
  31.     private \DateTime $endAt;
  32.     #[ORM\Column(name'abstract'type'text'nullabletrue)]
  33.     private ?string $abstract;
  34.     public function __construct()
  35.     {
  36.         // date_default_timezone_set('Africa/Casablanca');
  37.         $this->createAt=new \DateTime('now');
  38.         $this->published=true;
  39.         $this->featured=false;
  40.         $this->image1Name='news.png';
  41.         $this->image2Name='news.png';
  42.     }
  43.     /**
  44.      * Get id
  45.      *
  46.      * @return integer 
  47.      */
  48.     public function getId()
  49.     {
  50.         return $this->id;
  51.     }
  52.     /**
  53.      * @return string
  54.      */
  55.     public function getTitle()
  56.     {
  57.         return $this->title;
  58.     }
  59.     /**
  60.      * @param string $title
  61.      * @return News
  62.      */
  63.     public function setTitle($title)
  64.     {
  65.         $this->title $title;
  66.         $this->setSlug($this->slugify($title));
  67.         return $this;
  68.     }
  69.     /**
  70.      * @return string
  71.      */
  72.     public function getSubTitle()
  73.     {
  74.         return $this->subTitle;
  75.     }
  76.     /**
  77.      * @param string $subTitle
  78.      * @return News
  79.      */
  80.     public function setSubTitle($subTitle)
  81.     {
  82.         $this->subTitle $subTitle;
  83.         return $this;
  84.     }
  85.     /**
  86.      * @return string
  87.      */
  88.     public function getImage1Name()
  89.     {
  90.         return $this->image1Name;
  91.     }
  92.     /**
  93.      * @param string $image1Name
  94.      * @return News
  95.      */
  96.     public function setImage1Name($image1Name)
  97.     {
  98.         $this->image1Name $image1Name;
  99.         return $this;
  100.     }
  101.     /**
  102.      * @return mixed
  103.      */
  104.     public function getImage1File()
  105.     {
  106.         return $this->image1File;
  107.     }
  108.     /**
  109.      * @param mixed $image1File
  110.      * @return News
  111.      */
  112.     public function setImage1File(UploadedFile $image1File=null)
  113.     {
  114.         $this->image1File $image1File;
  115.         return $this;
  116.     }
  117.     /**
  118.      * @return string
  119.      */
  120.     public function getImage2Name()
  121.     {
  122.         return $this->image2Name;
  123.     }
  124.     /**
  125.      * @param string $image2Name
  126.      * @return News
  127.      */
  128.     public function setImage2Name($image2Name)
  129.     {
  130.         $this->image2Name $image2Name;
  131.         return $this;
  132.     }
  133.     /**
  134.      * @return mixed
  135.      */
  136.     public function getImage2File()
  137.     {
  138.         return $this->image2File;
  139.     }
  140.     /**
  141.      * @param mixed $image2File
  142.      * @return News
  143.      */
  144.     public function setImage2File(UploadedFile $image2File=null)
  145.     {
  146.         $this->image2File $image2File;
  147.         return $this;
  148.     }
  149.     /**
  150.      * @return string
  151.      */
  152.     public function getLink()
  153.     {
  154.         return $this->link;
  155.     }
  156.     /**
  157.      * @param string $link
  158.      * @return News
  159.      */
  160.     public function setLink($link)
  161.     {
  162.         $this->link $link;
  163.         return $this;
  164.     }
  165.     /**
  166.      * @return bool
  167.      */
  168.     public function isFeatured()
  169.     {
  170.         return $this->featured;
  171.     }
  172.     /**
  173.      * @return bool
  174.      */
  175.     public function getFeatured()
  176.     {
  177.         return $this->featured;
  178.     }
  179.     /**
  180.      * @param bool $featured
  181.      * @return News
  182.      */
  183.     public function setFeatured($featured)
  184.     {
  185.         $this->featured $featured;
  186.         return $this;
  187.     }
  188.     /**
  189.      * @return \DateTime
  190.      */
  191.     public function getStartAt()
  192.     {
  193.         return $this->startAt;
  194.     }
  195.     /**
  196.      * @param \DateTime $startAt
  197.      * @return News
  198.      */
  199.     public function setStartAt($startAt)
  200.     {
  201.         $this->startAt $startAt;
  202.         return $this;
  203.     }
  204.     /**
  205.      * @return \DateTime
  206.      */
  207.     public function getEndAt()
  208.     {
  209.         return $this->endAt;
  210.     }
  211.     /**
  212.      * @param \DateTime $endAt
  213.      * @return News
  214.      */
  215.     public function setEndAt($endAt)
  216.     {
  217.         $this->endAt $endAt;
  218.         return $this;
  219.     }
  220.     /**
  221.      * @return string
  222.      */
  223.     public function getSlug()
  224.     {
  225.         return $this->slug;
  226.     }
  227.     /**
  228.      * @param string $slug
  229.      * @return News
  230.      */
  231.     public function setSlug($slug)
  232.     {
  233.         $this->slug $slug;
  234.         return $this;
  235.     }
  236.     /**
  237.      * @return string
  238.      */
  239.     public function getAbstract()
  240.     {
  241.         return $this->abstract;
  242.     }
  243.     /**
  244.      * @param string $abstract
  245.      * @return News
  246.      */
  247.     public function setAbstract($abstract)
  248.     {
  249.         $this->abstract $abstract;
  250.         return $this;
  251.     }
  252.     function __toString()
  253.     {
  254.         return $this->title;
  255.     }
  256.     public function slugify($title)
  257.     {
  258.         // replace non letter or digits by -
  259.         $text preg_replace('~[^\pL\d]+~u''-'$title);
  260.         // transliterate
  261.         $text iconv('utf-8''us-ascii//TRANSLIT'$text);
  262.         // remove unwanted characters
  263.         $text preg_replace('~[^-\w]+~'''$text);
  264.         // trim
  265.         $text trim($text'-');
  266.         // remove duplicate -
  267.         $text preg_replace('~-+~''-'$text);
  268.         // lowercase
  269.         $text strtolower($text);
  270.         if (empty($text)) {
  271.             return uniqid();
  272.         }
  273.         return $text;
  274.     }
  275.     public function getButtonFeatured()
  276.     {
  277.         $confirm="data-toggle='confirmation'
  278.                 data-btn-ok-label='Oui' 
  279.                 data-btn-ok-icon='glyphicon glyphicon-ok'
  280.                 data-btn-ok-class='btn-success'
  281.                 data-btn-cancel-label='Non' 
  282.                 data-btn-cancel-icon='glyphicon glyphicon-remove'
  283.                 data-btn-cancel-class='btn-danger'
  284.                 data-title='Changer statut ?'
  285.                 data-popout='true'
  286.                 data-content='Voulez-vous vraiment changer le statut de cet élément ?' ";
  287.         if($this->featured)
  288.             $icon"<i class=\"text-green fa fa-toggle-on\"> Oui</i>";
  289.         else
  290.             $icon"<i class=\"text-red fa fa-toggle-off\"> Non</i>";
  291.         $btn="<a ".$confirm." href='javascript:void(0)' class='boledit' data-boledit-id='".$this->id."' data-boledit-route='".$this->getRoute('featured')."'>".$icon."</a> </td>";
  292.         return $btn;
  293.     }
  294. }