src/Entity/General.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\GeneralRepository;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use ScssPhp\ScssPhp\Compiler;
  6. use Symfony\Component\Process\Exception\ProcessFailedException;
  7. use Symfony\Component\Process\Process;
  8. /**
  9. * @ORM\Entity(repositoryClass=GeneralRepository::class)
  10. */
  11. class General
  12. {
  13. const PARAMETER_KEYS = [
  14. 'footer_theme' => [
  15. 'Clair' => 'light',
  16. 'Sombre' => 'dark'
  17. ]
  18. ];
  19. /**
  20. * @ORM\Id
  21. * @ORM\GeneratedValue
  22. * @ORM\Column(type="integer")
  23. */
  24. private $id;
  25. /**
  26. * @ORM\Column(type="string", length=255)
  27. */
  28. private $logoSombre;
  29. /**
  30. * @ORM\Column(type="string", length=255)
  31. */
  32. private $logoClair;
  33. /**
  34. * @ORM\Column(type="string", length=255)
  35. */
  36. private $logoPetit;
  37. /**
  38. * @ORM\Column(type="string", length=255)
  39. */
  40. private $adresseEmail;
  41. /**
  42. * @ORM\Column(type="string", length=255)
  43. */
  44. private $nomEntreprise;
  45. /**
  46. * @ORM\Column(type="string", length=10000)
  47. */
  48. private $slogan;
  49. /**
  50. * @ORM\Column(type="string", length=255)
  51. */
  52. private $imageAccueil;
  53. /**
  54. * @ORM\Column(type="string", length=255)
  55. */
  56. private $telephone;
  57. /**
  58. * @ORM\Column(type="text")
  59. */
  60. private $entrepriseDescription;
  61. /**
  62. * @ORM\Column(type="string", length=255)
  63. */
  64. private $questionFooter;
  65. /**
  66. * @ORM\Column(type="text")
  67. */
  68. private $descriptionQuestionFooter;
  69. /**
  70. * @ORM\Column(type="string", length=255, nullable=true)
  71. */
  72. private $positionSloganAccueil;
  73. /**
  74. * @ORM\Column(type="text", nullable=true)
  75. */
  76. private $sousTexteSlogan;
  77. /**
  78. * @ORM\Column(type="string", length=255, nullable=true)
  79. */
  80. private $couleurSlogan;
  81. /**
  82. * @ORM\Column(type="string", length=255, nullable=true)
  83. */
  84. private $policeGeneral;
  85. /**
  86. * @ORM\Column(type="string", length=255, nullable=true)
  87. */
  88. private $policeTitres;
  89. /**
  90. * @ORM\Column(type="boolean")
  91. */
  92. private $hidePhoneOnMobile;
  93. /**
  94. * @ORM\Column(type="string", length=255, nullable="true")
  95. */
  96. private $fixe;
  97. /**
  98. * @ORM\Column(type="string", length=255, nullable=true)
  99. */
  100. private $couleurPrincipale;
  101. /**
  102. * @ORM\Column(type="string", length=255, nullable=true)
  103. */
  104. private $couleurBoutons;
  105. /**
  106. * @ORM\Column(type="string", length=255, nullable=true)
  107. */
  108. private $googleAnalyticsId;
  109. /**
  110. * @ORM\Column(type="boolean")
  111. */
  112. private $sliderFullscreen;
  113. /**
  114. * @ORM\Column(type="array")
  115. */
  116. private $parametres = [];
  117. const PAGES = [
  118. "Réalisations" => 'realisations',
  119. "Blogs" => 'blogs',
  120. "Actualités" => 'actualites',
  121. "Tarifs" => 'tarifs',
  122. "Services" => 'services',
  123. "L'entreprise" => 'entreprise'
  124. ];
  125. public function getId(): ?int
  126. {
  127. return $this->id;
  128. }
  129. public function getLogoSombre(): ?string
  130. {
  131. return $this->logoSombre;
  132. }
  133. public function setLogoSombre(string $logoSombre): self
  134. {
  135. $this->logoSombre = $logoSombre;
  136. return $this;
  137. }
  138. public function getLogoClair(): ?string
  139. {
  140. return $this->logoClair;
  141. }
  142. public function setLogoClair(string $logoClair): self
  143. {
  144. $this->logoClair = $logoClair;
  145. return $this;
  146. }
  147. public function getLogoPetit(): ?string
  148. {
  149. return $this->logoPetit;
  150. }
  151. public function setLogoPetit(string $logoPetit): self
  152. {
  153. $this->logoPetit = $logoPetit;
  154. return $this;
  155. }
  156. public function getAdresseEmail(): ?string
  157. {
  158. return $this->adresseEmail;
  159. }
  160. public function setAdresseEmail(string $adresseEmail): self
  161. {
  162. $this->adresseEmail = $adresseEmail;
  163. return $this;
  164. }
  165. public function getNomEntreprise(): ?string
  166. {
  167. return $this->nomEntreprise;
  168. }
  169. public function setNomEntreprise(string $nomEntreprise): self
  170. {
  171. $this->nomEntreprise = $nomEntreprise;
  172. return $this;
  173. }
  174. public function getSlogan(): ?string
  175. {
  176. return $this->slogan;
  177. }
  178. public function setSlogan(string $slogan): self
  179. {
  180. $this->slogan = $slogan;
  181. return $this;
  182. }
  183. public function getImageAccueil(): ?string
  184. {
  185. return $this->imageAccueil;
  186. }
  187. public function setImageAccueil(?string $imageAccueil): self
  188. {
  189. $this->imageAccueil = $imageAccueil;
  190. return $this;
  191. }
  192. public function getTelephone(): ?string
  193. {
  194. return $this->telephone;
  195. }
  196. public function setTelephone(string $telephone): self
  197. {
  198. $this->telephone = $telephone;
  199. return $this;
  200. }
  201. public function getEntrepriseDescription(): ?string
  202. {
  203. return $this->entrepriseDescription;
  204. }
  205. public function setEntrepriseDescription(string $entrepriseDescription): self
  206. {
  207. $this->entrepriseDescription = $entrepriseDescription;
  208. return $this;
  209. }
  210. public function getQuestionFooter(): ?string
  211. {
  212. return $this->questionFooter;
  213. }
  214. public function setQuestionFooter(string $questionFooter): self
  215. {
  216. $this->questionFooter = $questionFooter;
  217. return $this;
  218. }
  219. public function getDescriptionQuestionFooter(): ?string
  220. {
  221. return $this->descriptionQuestionFooter;
  222. }
  223. public function setDescriptionQuestionFooter(string $descriptionQuestionFooter): self
  224. {
  225. $this->descriptionQuestionFooter = $descriptionQuestionFooter;
  226. return $this;
  227. }
  228. public function getPositionSloganAccueil(): ?string
  229. {
  230. return $this->positionSloganAccueil;
  231. }
  232. public function setPositionSloganAccueil(string $positionSloganAccueil): self
  233. {
  234. $this->positionSloganAccueil = $positionSloganAccueil;
  235. return $this;
  236. }
  237. public function getSousTexteSlogan(): ?string
  238. {
  239. return $this->sousTexteSlogan;
  240. }
  241. public function setSousTexteSlogan(?string $sousTexteSlogan): self
  242. {
  243. $this->sousTexteSlogan = $sousTexteSlogan;
  244. return $this;
  245. }
  246. public function getCouleurSlogan(): ?string
  247. {
  248. return $this->couleurSlogan;
  249. }
  250. public function setCouleurSlogan(?string $couleurSlogan): self
  251. {
  252. $this->couleurSlogan = $couleurSlogan;
  253. return $this;
  254. }
  255. public function getPoliceGeneral(): ?string
  256. {
  257. return $this->policeGeneral;
  258. }
  259. public function setPoliceGeneral(?string $policeGeneral): self
  260. {
  261. $this->policeGeneral = $policeGeneral;
  262. return $this;
  263. }
  264. public function getPoliceTitres(): ?string
  265. {
  266. return $this->policeTitres;
  267. }
  268. public function setPoliceTitres(?string $policeTitres): self
  269. {
  270. $this->policeTitres = $policeTitres;
  271. return $this;
  272. }
  273. public function getHidePhoneOnMobile(): ?bool
  274. {
  275. return $this->hidePhoneOnMobile;
  276. }
  277. public function setHidePhoneOnMobile(bool $hidePhoneOnMobile): self
  278. {
  279. $this->hidePhoneOnMobile = $hidePhoneOnMobile;
  280. return $this;
  281. }
  282. public function getFixe(): ?string
  283. {
  284. return $this->fixe;
  285. }
  286. public function setFixe(?string $fixe): self
  287. {
  288. $this->fixe = $fixe;
  289. return $this;
  290. }
  291. public function getCouleurPrincipale(): ?string
  292. {
  293. return $this->couleurPrincipale;
  294. }
  295. public function setCouleurPrincipale(?string $couleurPrincipale): self
  296. {
  297. $this->couleurPrincipale = $couleurPrincipale;
  298. $this->changeColor('color-theme',$couleurPrincipale);
  299. return $this;
  300. }
  301. public function getCouleurBoutons(): ?string
  302. {
  303. return $this->couleurBoutons;
  304. }
  305. public function setCouleurBoutons(?string $couleurBoutons): self
  306. {
  307. $this->couleurBoutons = $couleurBoutons;
  308. $this->changeColor('color-success',$couleurBoutons);
  309. return $this;
  310. }
  311. public static function changeColor($key,$color){
  312. $scss = file_get_contents('./scss/_variables.scss');
  313. $matches = null;
  314. preg_match_all('/\$([a-z0-9-| ]+):(.+);/',$scss,$matches);
  315. $maxlength = count($matches[0]);
  316. $scssResult = "";
  317. for($i = 0; $i < $maxlength ; $i++){
  318. if($matches[1][$i] == $key){
  319. $matches[2][$i] = $color;
  320. }
  321. }
  322. for($i = 0; $i < $maxlength ; $i++){
  323. $scssResult .= "$" . $matches[1][$i] . ":" . $matches[2][$i] . ";\n";
  324. }
  325. file_put_contents('./scss/_variables.scss',$scssResult);
  326. self::refreshColor();
  327. }
  328. public static function refreshColor(){
  329. $process = new Process(['yarn','build']);
  330. $process->setWorkingDirectory(realpath('../'));
  331. $process->run();
  332. // executes after the command finishes
  333. if (!$process->isSuccessful()) {
  334. $process = new Process(['npm','run','build']);
  335. $process->setWorkingDirectory(realpath('../'));
  336. $process->run();
  337. // executes after the command finishes
  338. if (!$process->isSuccessful()) {
  339. throw new ProcessFailedException($process);
  340. }
  341. }
  342. }
  343. public function getGoogleAnalyticsId(): ?string
  344. {
  345. return $this->googleAnalyticsId;
  346. }
  347. public function setGoogleAnalyticsId(?string $googleAnalyticsId): self
  348. {
  349. $this->googleAnalyticsId = $googleAnalyticsId;
  350. return $this;
  351. }
  352. public function getParametres(): ?array
  353. {
  354. return $this->parametres ?: [];
  355. }
  356. public function setParametres(array $parametres): self
  357. {
  358. $this->parametres = $parametres;
  359. return $this;
  360. }
  361. public function getFooterTheme() : string
  362. {
  363. return $this->parametres['footer_theme'] ?? 'light';
  364. }
  365. public function setFooterTheme(?string $theme) : self
  366. {
  367. $this->parametres['footer_theme'] = $theme;
  368. return $this;
  369. }
  370. /**
  371. * @return mixed
  372. */
  373. public function getSliderFullscreen()
  374. {
  375. return $this->sliderFullscreen;
  376. }
  377. /**
  378. * @param mixed $sliderFullscreen
  379. * @return General
  380. */
  381. public function setSliderFullscreen($sliderFullscreen)
  382. {
  383. $this->sliderFullscreen = $sliderFullscreen;
  384. return $this;
  385. }
  386. public function getAbsoluteLogoSombre() : ?string
  387. {
  388. if(!empty($this->logoSombre)){
  389. return sprintf("https://%s/images/upload/%s",$_SERVER['HTTP_HOST'],$this->logoSombre);
  390. }
  391. return null;
  392. }
  393. public function getAbsoluteLogoClair() : ?string
  394. {
  395. if(!empty($this->logoClair)){
  396. return sprintf("https://%s/images/upload/%s",$_SERVER['HTTP_HOST'],$this->logoClair);
  397. }
  398. return null;
  399. }
  400. public function getAbsoluteLogoPetit() : ?string
  401. {
  402. if(!empty($this->logoPetit)){
  403. return sprintf("https://%s/images/upload/%s",$_SERVER['HTTP_HOST'],$this->logoPetit);
  404. }
  405. return null;
  406. }
  407. public function getAbsoluteAccueilImage() : ?string
  408. {
  409. if(!empty($this->imageAccueil)){
  410. return sprintf("https://%s/images/upload/%s",$_SERVER['HTTP_HOST'],$this->imageAccueil);
  411. }
  412. return null;
  413. }
  414. public function getHeaderScript() : ?string
  415. {
  416. return $this->getParametres()['headerScript'] ?? null;
  417. }
  418. public function setHeaderScript(?string $headerScript) : self
  419. {
  420. $parametres = $this->getParametres();
  421. $parametres['headerScript'] = $headerScript;
  422. $this->setParametres($parametres);
  423. return $this;
  424. }
  425. public function getFooterScript() : ?string
  426. {
  427. return $this->getParametres()['footerScript'] ?? null;
  428. }
  429. public function setFooterScript(?string $footerScript) : self
  430. {
  431. $parametres = $this->getParametres();
  432. $parametres['footerScript'] = $footerScript;
  433. $this->setParametres($parametres);
  434. return $this;
  435. }
  436. }