<?php
namespace App\Entity;
use App\Repository\GeneralRepository;
use Doctrine\ORM\Mapping as ORM;
use ScssPhp\ScssPhp\Compiler;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process;
/**
* @ORM\Entity(repositoryClass=GeneralRepository::class)
*/
class General
{
const PARAMETER_KEYS = [
'footer_theme' => [
'Clair' => 'light',
'Sombre' => 'dark'
]
];
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $logoSombre;
/**
* @ORM\Column(type="string", length=255)
*/
private $logoClair;
/**
* @ORM\Column(type="string", length=255)
*/
private $logoPetit;
/**
* @ORM\Column(type="string", length=255)
*/
private $adresseEmail;
/**
* @ORM\Column(type="string", length=255)
*/
private $nomEntreprise;
/**
* @ORM\Column(type="string", length=10000)
*/
private $slogan;
/**
* @ORM\Column(type="string", length=255)
*/
private $imageAccueil;
/**
* @ORM\Column(type="string", length=255)
*/
private $telephone;
/**
* @ORM\Column(type="text")
*/
private $entrepriseDescription;
/**
* @ORM\Column(type="string", length=255)
*/
private $questionFooter;
/**
* @ORM\Column(type="text")
*/
private $descriptionQuestionFooter;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $positionSloganAccueil;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $sousTexteSlogan;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $couleurSlogan;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $policeGeneral;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $policeTitres;
/**
* @ORM\Column(type="boolean")
*/
private $hidePhoneOnMobile;
/**
* @ORM\Column(type="string", length=255, nullable="true")
*/
private $fixe;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $couleurPrincipale;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $couleurBoutons;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $googleAnalyticsId;
/**
* @ORM\Column(type="boolean")
*/
private $sliderFullscreen;
/**
* @ORM\Column(type="array")
*/
private $parametres = [];
const PAGES = [
"Réalisations" => 'realisations',
"Blogs" => 'blogs',
"Actualités" => 'actualites',
"Tarifs" => 'tarifs',
"Services" => 'services',
"L'entreprise" => 'entreprise'
];
public function getId(): ?int
{
return $this->id;
}
public function getLogoSombre(): ?string
{
return $this->logoSombre;
}
public function setLogoSombre(string $logoSombre): self
{
$this->logoSombre = $logoSombre;
return $this;
}
public function getLogoClair(): ?string
{
return $this->logoClair;
}
public function setLogoClair(string $logoClair): self
{
$this->logoClair = $logoClair;
return $this;
}
public function getLogoPetit(): ?string
{
return $this->logoPetit;
}
public function setLogoPetit(string $logoPetit): self
{
$this->logoPetit = $logoPetit;
return $this;
}
public function getAdresseEmail(): ?string
{
return $this->adresseEmail;
}
public function setAdresseEmail(string $adresseEmail): self
{
$this->adresseEmail = $adresseEmail;
return $this;
}
public function getNomEntreprise(): ?string
{
return $this->nomEntreprise;
}
public function setNomEntreprise(string $nomEntreprise): self
{
$this->nomEntreprise = $nomEntreprise;
return $this;
}
public function getSlogan(): ?string
{
return $this->slogan;
}
public function setSlogan(string $slogan): self
{
$this->slogan = $slogan;
return $this;
}
public function getImageAccueil(): ?string
{
return $this->imageAccueil;
}
public function setImageAccueil(?string $imageAccueil): self
{
$this->imageAccueil = $imageAccueil;
return $this;
}
public function getTelephone(): ?string
{
return $this->telephone;
}
public function setTelephone(string $telephone): self
{
$this->telephone = $telephone;
return $this;
}
public function getEntrepriseDescription(): ?string
{
return $this->entrepriseDescription;
}
public function setEntrepriseDescription(string $entrepriseDescription): self
{
$this->entrepriseDescription = $entrepriseDescription;
return $this;
}
public function getQuestionFooter(): ?string
{
return $this->questionFooter;
}
public function setQuestionFooter(string $questionFooter): self
{
$this->questionFooter = $questionFooter;
return $this;
}
public function getDescriptionQuestionFooter(): ?string
{
return $this->descriptionQuestionFooter;
}
public function setDescriptionQuestionFooter(string $descriptionQuestionFooter): self
{
$this->descriptionQuestionFooter = $descriptionQuestionFooter;
return $this;
}
public function getPositionSloganAccueil(): ?string
{
return $this->positionSloganAccueil;
}
public function setPositionSloganAccueil(string $positionSloganAccueil): self
{
$this->positionSloganAccueil = $positionSloganAccueil;
return $this;
}
public function getSousTexteSlogan(): ?string
{
return $this->sousTexteSlogan;
}
public function setSousTexteSlogan(?string $sousTexteSlogan): self
{
$this->sousTexteSlogan = $sousTexteSlogan;
return $this;
}
public function getCouleurSlogan(): ?string
{
return $this->couleurSlogan;
}
public function setCouleurSlogan(?string $couleurSlogan): self
{
$this->couleurSlogan = $couleurSlogan;
return $this;
}
public function getPoliceGeneral(): ?string
{
return $this->policeGeneral;
}
public function setPoliceGeneral(?string $policeGeneral): self
{
$this->policeGeneral = $policeGeneral;
return $this;
}
public function getPoliceTitres(): ?string
{
return $this->policeTitres;
}
public function setPoliceTitres(?string $policeTitres): self
{
$this->policeTitres = $policeTitres;
return $this;
}
public function getHidePhoneOnMobile(): ?bool
{
return $this->hidePhoneOnMobile;
}
public function setHidePhoneOnMobile(bool $hidePhoneOnMobile): self
{
$this->hidePhoneOnMobile = $hidePhoneOnMobile;
return $this;
}
public function getFixe(): ?string
{
return $this->fixe;
}
public function setFixe(?string $fixe): self
{
$this->fixe = $fixe;
return $this;
}
public function getCouleurPrincipale(): ?string
{
return $this->couleurPrincipale;
}
public function setCouleurPrincipale(?string $couleurPrincipale): self
{
$this->couleurPrincipale = $couleurPrincipale;
$this->changeColor('color-theme',$couleurPrincipale);
return $this;
}
public function getCouleurBoutons(): ?string
{
return $this->couleurBoutons;
}
public function setCouleurBoutons(?string $couleurBoutons): self
{
$this->couleurBoutons = $couleurBoutons;
$this->changeColor('color-success',$couleurBoutons);
return $this;
}
public static function changeColor($key,$color){
$scss = file_get_contents('./scss/_variables.scss');
$matches = null;
preg_match_all('/\$([a-z0-9-| ]+):(.+);/',$scss,$matches);
$maxlength = count($matches[0]);
$scssResult = "";
for($i = 0; $i < $maxlength ; $i++){
if($matches[1][$i] == $key){
$matches[2][$i] = $color;
}
}
for($i = 0; $i < $maxlength ; $i++){
$scssResult .= "$" . $matches[1][$i] . ":" . $matches[2][$i] . ";\n";
}
file_put_contents('./scss/_variables.scss',$scssResult);
self::refreshColor();
}
public static function refreshColor(){
$process = new Process(['yarn','build']);
$process->setWorkingDirectory(realpath('../'));
$process->run();
// executes after the command finishes
if (!$process->isSuccessful()) {
$process = new Process(['npm','run','build']);
$process->setWorkingDirectory(realpath('../'));
$process->run();
// executes after the command finishes
if (!$process->isSuccessful()) {
throw new ProcessFailedException($process);
}
}
}
public function getGoogleAnalyticsId(): ?string
{
return $this->googleAnalyticsId;
}
public function setGoogleAnalyticsId(?string $googleAnalyticsId): self
{
$this->googleAnalyticsId = $googleAnalyticsId;
return $this;
}
public function getParametres(): ?array
{
return $this->parametres ?: [];
}
public function setParametres(array $parametres): self
{
$this->parametres = $parametres;
return $this;
}
public function getFooterTheme() : string
{
return $this->parametres['footer_theme'] ?? 'light';
}
public function setFooterTheme(?string $theme) : self
{
$this->parametres['footer_theme'] = $theme;
return $this;
}
/**
* @return mixed
*/
public function getSliderFullscreen()
{
return $this->sliderFullscreen;
}
/**
* @param mixed $sliderFullscreen
* @return General
*/
public function setSliderFullscreen($sliderFullscreen)
{
$this->sliderFullscreen = $sliderFullscreen;
return $this;
}
public function getAbsoluteLogoSombre() : ?string
{
if(!empty($this->logoSombre)){
return sprintf("https://%s/images/upload/%s",$_SERVER['HTTP_HOST'],$this->logoSombre);
}
return null;
}
public function getAbsoluteLogoClair() : ?string
{
if(!empty($this->logoClair)){
return sprintf("https://%s/images/upload/%s",$_SERVER['HTTP_HOST'],$this->logoClair);
}
return null;
}
public function getAbsoluteLogoPetit() : ?string
{
if(!empty($this->logoPetit)){
return sprintf("https://%s/images/upload/%s",$_SERVER['HTTP_HOST'],$this->logoPetit);
}
return null;
}
public function getAbsoluteAccueilImage() : ?string
{
if(!empty($this->imageAccueil)){
return sprintf("https://%s/images/upload/%s",$_SERVER['HTTP_HOST'],$this->imageAccueil);
}
return null;
}
public function getHeaderScript() : ?string
{
return $this->getParametres()['headerScript'] ?? null;
}
public function setHeaderScript(?string $headerScript) : self
{
$parametres = $this->getParametres();
$parametres['headerScript'] = $headerScript;
$this->setParametres($parametres);
return $this;
}
public function getFooterScript() : ?string
{
return $this->getParametres()['footerScript'] ?? null;
}
public function setFooterScript(?string $footerScript) : self
{
$parametres = $this->getParametres();
$parametres['footerScript'] = $footerScript;
$this->setParametres($parametres);
return $this;
}
}