<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Repository\InformationRepository;
use App\Repository\UserRepository;
use App\Traits\Actions;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: InformationRepository::class)]
#[ORM\Table(name: 'hs_tc_information')]
#[ApiResource]
class Information
{
use Actions;
#[ORM\Column(name: "name", type: "string", length: 255)]
private string $name;
#[ORM\Column(name: "slug", type: "string", length: 255)]
private string $slug;
#[ORM\Column(name: "type", type: "string", length: 255)]
private string $type;
#[ORM\Column(name: "val", type: "string", length: 255, nullable: true)]
private ?string $val = null;
#[ORM\Column(name: "category", type: "string", length: 255, nullable: true)]
private ?string $category = null;
#[ORM\Column(name: "show_in_home", type: "boolean")]
private bool $showInHome = false;
#[ORM\Column(name: "show_in_contact", type: "boolean")]
private bool $showInContact = false;
public function __construct()
{
// date_default_timezone_set('Africa/Casablanca');
$this->createAt = new \DateTime('now');
$this->published = true;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getName(): string
{
return $this->name;
}
public function getSlug(): string
{
return $this->slug;
}
public function setSlug(string $slug): self
{
$this->slug = $slug;
return $this;
}
public function getType(): string
{
return $this->type;
}
public function setType(string $type): self
{
$this->type = $type;
return $this;
}
public function getVal(): ?string
{
return $this->val;
}
public function setVal(?string $val): self
{
$this->val = $val;
return $this;
}
public function getCategory(): ?string
{
return $this->category;
}
public function setCategory(?string $category): self
{
$this->category = $category;
return $this;
}
public function isShowInHome(): bool
{
return $this->showInHome;
}
public function setShowInHome(bool $showInHome): self
{
$this->showInHome = $showInHome;
return $this;
}
public function isShowInContact(): bool
{
return $this->showInContact;
}
public function setShowInContact(bool $showInContact): self
{
$this->showInContact = $showInContact;
return $this;
}
// Autres méthodes...
public function getNextNumber(){
if($this->val==null){
return 1;
}
return preg_replace_callback('/(\d+)\/(\d+)/', function ($matches) {
$numberBeforeSlash = intval($matches[1]); // Convertit la chaîne en nombre entier
$numberBeforeSlash++; // Incrémente le nombre
return $numberBeforeSlash . '/' . $matches[2]; // Retourne la chaîne mise à jour
}, $this->val);
}
}