fix(continuous-integration): correction php-cs-fixer
All checks were successful
Cadoles/nineskeletor/pipeline/pr-master This commit looks good

This commit is contained in:
2022-09-23 16:14:15 +02:00
parent 5f3cc51f5c
commit b78f54b76c
70 changed files with 5943 additions and 5549 deletions

View File

@ -1,14 +1,15 @@
<?php
namespace App\Service;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\Event\RequestEvent;
namespace App\Service;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
class AppSession {
class AppSession
{
private $container;
protected $em;
protected $requeststack;
@ -22,141 +23,144 @@
$this->token = $token;
}
public function onDomainParse(RequestEvent $event) {
public function onDomainParse(RequestEvent $event)
{
$session = $this->requeststack->getSession();
$configs = $this->em->getRepository("App\Entity\Config")->findAll();
foreach($configs as $config) {
foreach ($configs as $config) {
$session->set($config->getId(), strval($config->getValue()));
}
$session->set("headerimage","header/".$session->get("headerimage"));
$session->set('headerimage', 'header/'.$session->get('headerimage'));
// Calcul couleur
$session->set("colorbgbodylight-darker", $this->adjustBrightness($session->get("colorbgbodylight"),-10));
$session->set("colorfttitlelight-darker", $this->adjustBrightness($session->get("colorfttitlelight"),-50));
$session->set('colorbgbodylight-darker', $this->adjustBrightness($session->get('colorbgbodylight'), -10));
$session->set('colorfttitlelight-darker', $this->adjustBrightness($session->get('colorfttitlelight'), -50));
$session->set("colorbgbodydark-darker", $this->adjustBrightness($session->get("colorbgbodydark"),-50));
$session->set("colorbgbodydark-lighter", $this->adjustBrightness($session->get("colorbgbodydark"),+50));
$session->set('colorbgbodydark-darker', $this->adjustBrightness($session->get('colorbgbodydark'), -50));
$session->set('colorbgbodydark-lighter', $this->adjustBrightness($session->get('colorbgbodydark'), +50));
$session->set('colorbgbodydark-rgb', $this->hexToRgb($session->get('colorbgbodydark')));
$session->set('colorbgbodydark-darkrgb', $this->hexToRgb($session->get('colorbgbodydark-darker')));
$session->set('colorbgbodydark-lightrgb', $this->hexToRgb($session->get('colorbgbodydark-lighter')));
$session->set("colorbgbodydark-rgb", $this->hexToRgb($session->get("colorbgbodydark")));
$session->set("colorbgbodydark-darkrgb", $this->hexToRgb($session->get("colorbgbodydark-darker")));
$session->set("colorbgbodydark-lightrgb", $this->hexToRgb($session->get("colorbgbodydark-lighter")));
// Current user
$token = $this->token->getToken();
if(!$token) return;
$curentuser=$token->getUser();
// Préférence par défaut
$session->set("fgheader", true);
$session->set("fgaudit", false);
if (!$token) {
return;
}
$curentuser = $token->getUser();
// Préférence par défaut
$session->set('fgheader', true);
$session->set('fgaudit', false);
// Préférence
if($curentuser!="anon.") {
$preference=$curentuser->getPreference();
if(is_array($preference)) {
if ('anon.' != $curentuser) {
$preference = $curentuser->getPreference();
if (is_array($preference)) {
// Préférence header
if(array_key_exists("fgheader",$preference)) {
$fgheader=($preference["fgheader"][0]=="true");
$session->set("fgheader", $fgheader);
if (array_key_exists('fgheader', $preference)) {
$fgheader = ('true' == $preference['fgheader'][0]);
$session->set('fgheader', $fgheader);
}
// Préférence audit
if(array_key_exists("fgaudit",$preference)) {
$fgaudit=($preference["fgaudit"][0]=="true");
$session->set("fgaudit", $fgaudit);
}
if (array_key_exists('fgaudit', $preference)) {
$fgaudit = ('true' == $preference['fgaudit'][0]);
$session->set('fgaudit', $fgaudit);
}
}
}
// Permissions
$showannuaire=false;
$submitgroup=false;
if($curentuser!="anon.") {
switch($session->get("permannu")) {
case "ROLE_USER" :
$showannuaire=($curentuser->hasRole("ROLE_ADMIN")||$curentuser->hasRole("ROLE_MODO")||$curentuser->hasRole("ROLE_MASTER")||$curentuser->hasRole("ROLE_USER"));
break;
$showannuaire = false;
$submitgroup = false;
if ('anon.' != $curentuser) {
switch ($session->get('permannu')) {
case 'ROLE_USER':
$showannuaire = ($curentuser->hasRole('ROLE_ADMIN') || $curentuser->hasRole('ROLE_MODO') || $curentuser->hasRole('ROLE_MASTER') || $curentuser->hasRole('ROLE_USER'));
break;
case "ROLE_MASTER" :
$showannuaire=($curentuser->hasRole("ROLE_ADMIN")||$curentuser->hasRole("ROLE_MODO")||$curentuser->hasRole("ROLE_MASTER"));
break;
case 'ROLE_MASTER':
$showannuaire = ($curentuser->hasRole('ROLE_ADMIN') || $curentuser->hasRole('ROLE_MODO') || $curentuser->hasRole('ROLE_MASTER'));
break;
case "ROLE_MODO" :
$showannuaire=($curentuser->hasRole("ROLE_ADMIN")||$curentuser->hasRole("ROLE_MODO"));
break;
case 'ROLE_MODO':
$showannuaire = ($curentuser->hasRole('ROLE_ADMIN') || $curentuser->hasRole('ROLE_MODO'));
break;
}
switch($session->get("permgroup")) {
case "ROLE_USER" :
$submitgroup=($curentuser->hasRole("ROLE_ADMIN")||$curentuser->hasRole("ROLE_MODO")||$curentuser->hasRole("ROLE_MASTER")||$curentuser->hasRole("ROLE_USER"));
break;
switch ($session->get('permgroup')) {
case 'ROLE_USER':
$submitgroup = ($curentuser->hasRole('ROLE_ADMIN') || $curentuser->hasRole('ROLE_MODO') || $curentuser->hasRole('ROLE_MASTER') || $curentuser->hasRole('ROLE_USER'));
break;
case "ROLE_MASTER" :
$submitgroup=($curentuser->hasRole("ROLE_ADMIN")||$curentuser->hasRole("ROLE_MODO")||$curentuser->hasRole("ROLE_MASTER"));
break;
case 'ROLE_MASTER':
$submitgroup = ($curentuser->hasRole('ROLE_ADMIN') || $curentuser->hasRole('ROLE_MODO') || $curentuser->hasRole('ROLE_MASTER'));
break;
case "ROLE_MODO" :
$submitgroup=($curentuser->hasRole("ROLE_ADMIN")||$curentuser->hasRole("ROLE_MODO"));
break;
case 'ROLE_MODO':
$submitgroup = ($curentuser->hasRole('ROLE_ADMIN') || $curentuser->hasRole('ROLE_MODO'));
break;
}
}
$session->set("showannuaire", $showannuaire);
$session->set("submitgroup", $submitgroup);
$session->set('showannuaire', $showannuaire);
$session->set('submitgroup', $submitgroup);
// Visite
if($curentuser!="anon.") {
$now=new \DateTime();
if(!$curentuser->getVisitedate()) {
// Visite
if ('anon.' != $curentuser) {
$now = new \DateTime();
if (!$curentuser->getVisitedate()) {
$curentuser->setVisitedate($now);
$curentuser->setVisitecpt($curentuser->getVisitecpt()+1);
$curentuser->setVisitecpt($curentuser->getVisitecpt() + 1);
$this->em->persist($curentuser);
$this->em->flush();
}
else {
$visitedate=clone $curentuser->getVisitedate();
$visitedate->add(new \DateInterval("PT1H"));
if($visitedate<$now) {
$this->em->flush();
} else {
$visitedate = clone $curentuser->getVisitedate();
$visitedate->add(new \DateInterval('PT1H'));
if ($visitedate < $now) {
$curentuser->setVisitedate($now);
$curentuser->setVisitecpt($curentuser->getVisitecpt()+1);
$curentuser->setVisitecpt($curentuser->getVisitecpt() + 1);
$this->em->persist($curentuser);
$this->em->flush();
$this->em->flush();
}
}
}
}
private function adjustBrightness($hex, $steps) {
private function adjustBrightness($hex, $steps)
{
// Steps should be between -255 and 255. Negative = darker, positive = lighter
$steps = max(-255, min(255, $steps));
// Normalize into a six character long hex string
$hex = str_replace('#', '', $hex);
if (strlen($hex) == 3) {
$hex = str_repeat(substr($hex,0,1), 2).str_repeat(substr($hex,1,1), 2).str_repeat(substr($hex,2,1), 2);
if (3 == strlen($hex)) {
$hex = str_repeat(substr($hex, 0, 1), 2).str_repeat(substr($hex, 1, 1), 2).str_repeat(substr($hex, 2, 1), 2);
}
// Split into three parts: R, G and B
$color_parts = str_split($hex, 2);
$return = '';
foreach ($color_parts as $color) {
$color = hexdec($color); // Convert to decimal
$color = max(0,min(255,$color + $steps)); // Adjust color
$color = hexdec($color); // Convert to decimal
$color = max(0, min(255, $color + $steps)); // Adjust color
$return .= str_pad(dechex($color), 2, '0', STR_PAD_LEFT); // Make two char hex code
}
return '#'.$return;
}
public function hexToRgb($hex) {
$hex = str_replace('#', '', $hex);
$length = strlen($hex);
$rgb['r'] = hexdec($length == 6 ? substr($hex, 0, 2) : ($length == 3 ? str_repeat(substr($hex, 0, 1), 2) : 0));
$rgb['g'] = hexdec($length == 6 ? substr($hex, 2, 2) : ($length == 3 ? str_repeat(substr($hex, 1, 1), 2) : 0));
$rgb['b'] = hexdec($length == 6 ? substr($hex, 4, 2) : ($length == 3 ? str_repeat(substr($hex, 2, 1), 2) : 0));
return $rgb['r'].",".$rgb['g'].",".$rgb['b'];
}
}
public function hexToRgb($hex)
{
$hex = str_replace('#', '', $hex);
$length = strlen($hex);
$rgb['r'] = hexdec(6 == $length ? substr($hex, 0, 2) : (3 == $length ? str_repeat(substr($hex, 0, 1), 2) : 0));
$rgb['g'] = hexdec(6 == $length ? substr($hex, 2, 2) : (3 == $length ? str_repeat(substr($hex, 1, 1), 2) : 0));
$rgb['b'] = hexdec(6 == $length ? substr($hex, 4, 2) : (3 == $length ? str_repeat(substr($hex, 2, 1), 2) : 0));
return $rgb['r'].','.$rgb['g'].','.$rgb['b'];
}
}