fix(manager): cs fixer
Cadoles/nineskeletor/pipeline/pr-master This commit looks good Details

This commit is contained in:
Arnaud Fornerot 2022-10-04 11:55:50 +02:00
parent 58518ec70d
commit 681b2f6547
6 changed files with 200 additions and 197 deletions

View File

@ -15,7 +15,7 @@ class HomeController extends AbstractController
}
if (!$this->getUser()) {
dump("here");
dump('here');
return $this->render('Home/home.html.twig', [
'useheader' => true,
@ -24,22 +24,25 @@ class HomeController extends AbstractController
'maxsize' => 1000,
]);
}
if ($this->getUser()->hasRole("ROLE_USER"))
if ($this->getUser()->hasRole('ROLE_USER')) {
return $this->redirectToRoute('app_user_home');
}
if ($this->getUser()->hasRole("ROLE_MANAGER"))
if ($this->getUser()->hasRole('ROLE_MANAGER')) {
return $this->redirectToRoute('app_manager_home');
}
if ($this->getUser()->hasRole("ROLE_MASTER"))
if ($this->getUser()->hasRole('ROLE_MASTER')) {
return $this->redirectToRoute('app_master_home');
}
if ($this->getUser()->hasRole("ROLE_MODO"))
if ($this->getUser()->hasRole('ROLE_MODO')) {
return $this->redirectToRoute('app_modo_home');
}
if ($this->getUser()->hasRole("ROLE_ADMIN"))
if ($this->getUser()->hasRole('ROLE_ADMIN')) {
return $this->redirectToRoute('app_admin_home');
}
}
public function homeuser($access): Response
@ -77,7 +80,6 @@ class HomeController extends AbstractController
return $this->redirectToRoute('app_admin_config');
}
public function docrest(): Response
{
return $this->render('Home/docrest.html.twig', [

View File

@ -79,7 +79,7 @@ class UserController extends AbstractController
break;
default:
$isactive = ($access=="manager"?$em->getRepository($this->entity)->getPreference($this->getUser(), 'userisactive', true):true);
$isactive = ('manager' == $access ? $em->getRepository($this->entity)->getPreference($this->getUser(), 'userisactive', true) : true);
$niveau01 = $this->getUser()->getNiveau01();
$niveau02 = $this->getUser()->getNiveau02();
@ -302,11 +302,9 @@ class UserController extends AbstractController
case 'manager':
if ($this->getUser()->getNiveau03() && $this->getUser()->getNiveau03() == $data->getNiveau03()) {
$action .= "<a href='".$this->generateUrl(str_replace('_admin_', '_manager_', $this->route).'_update', ['id' => $data->getId()])."'><i class='fa fa-file fa-fw fa-2x'></i></a>";
}
elseif(!$this->getUser()->getNiveau03()&&$this->getUser()->getNiveau02()&&$this->getUser()->getNiveau02()==$data->getNiveau02()) {
} elseif (!$this->getUser()->getNiveau03() && $this->getUser()->getNiveau02() && $this->getUser()->getNiveau02() == $data->getNiveau02()) {
$action .= "<a href='".$this->generateUrl(str_replace('_admin_', '_manager_', $this->route).'_update', ['id' => $data->getId()])."'><i class='fa fa-file fa-fw fa-2x'></i></a>";
}
elseif(!$this->getUser()->getNiveau02()&&$this->getUser()->getNiveau01()&&$this->getUser()->getNiveau01()==$data->getNiveau01()) {
} elseif (!$this->getUser()->getNiveau02() && $this->getUser()->getNiveau01() && $this->getUser()->getNiveau01() == $data->getNiveau01()) {
$action .= "<a href='".$this->generateUrl(str_replace('_admin_', '_manager_', $this->route).'_update', ['id' => $data->getId()])."'><i class='fa fa-file fa-fw fa-2x'></i></a>";
}
break;
@ -394,11 +392,11 @@ class UserController extends AbstractController
$data->setApikey(Uuid::uuid4());
// If manager set same niveau to usertosubmit
if($access=="manager") {
if ('manager' == $access) {
$data->setNiveau01($this->getUser()->getNiveau01());
$data->setNiveau02($this->getUser()->getNiveau02());
$data->setNiveau03($this->getUser()->getNiveau03());
$data->setRoles(["ROLE_USER"]);
$data->setRoles(['ROLE_USER']);
}
// Création du formulaire
@ -724,11 +722,9 @@ class UserController extends AbstractController
case 'manager':
if ($this->getUser()->getNiveau03() && $this->getUser()->getNiveau03() == $entity->getNiveau03()) {
return true;
}
elseif($this->getUser()->getNiveau02()&&$this->getUser()->getNiveau02()==$entity->getNiveau02()) {
} elseif ($this->getUser()->getNiveau02() && $this->getUser()->getNiveau02() == $entity->getNiveau02()) {
return true;
}
elseif($this->getUser()->getNiveau01()&&$this->getUser()->getNiveau01()==$entity->getNiveau01()) {
} elseif ($this->getUser()->getNiveau01() && $this->getUser()->getNiveau01() == $entity->getNiveau01()) {
return true;
}

View File

@ -2,22 +2,21 @@
namespace App\DataFixtures;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\Console\Output\ConsoleOutput;
use Doctrine\ORM\Id\AssignedGenerator;
use Doctrine\ORM\Mapping\ClassMetadata;
use App\Entity\Niveau01;
use App\Entity\Niveau02;
use App\Entity\Niveau03;
use App\Entity\Niveau04;
use App\Entity\User;
use App\Entity\UserModo;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\ORM\Id\AssignedGenerator;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\Persistence\ObjectManager;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\HttpKernel\KernelInterface;
class AppFixtures extends Fixture
{
@ -33,7 +32,7 @@ class AppFixtures extends Fixture
public function load(ObjectManager $manager): void
{
// app:Init
$this->writeln("app:Init");
$this->writeln('app:Init');
$application = new Application($this->kernel);
$application->setAutoExit(false);
$input = new ArrayInput(['command' => 'app:Init']);
@ -43,7 +42,7 @@ class AppFixtures extends Fixture
// app:Synchro
$manager->clear();
$this->writeln("app:Synchro");
$this->writeln('app:Synchro');
$input = new ArrayInput(['command' => 'app:Synchro']);
$boutput = new BufferedOutput();
$application->run($input, $boutput);
@ -66,113 +65,116 @@ class AppFixtures extends Fixture
$metadata->setIdGenerator(new AssignedGenerator());
// Niveau 01
$this->writeln("Niveau01");
$this->writeln('Niveau01');
$csv = file_get_contents($this->kernel->getProjectDir().'/src/DataFixtures/niveau01.csv');
$tab = $this->csv_to_array($csv);
foreach ($tab as $lig) {
$niveau01 = $manager->getRepository('App\Entity\Niveau01')->find($lig['id']);
if (!$niveau01) {
$niveau01 = new Niveau01();
$niveau01->setId($lig["id"]);
$niveau01->setId($lig['id']);
$manager->persist($niveau01);
}
$niveau01->setLabel($lig["label"]);
$niveau01->setCode($lig["code"]);
$niveau01->setPostaladress($lig["postaladress"]);
$niveau01->setTelephonenumber($lig["telephonenumber"]);
$niveau01->setEmail($lig["email"]);
$niveau01->setApikey($lig["apikey"]);
$niveau01->setLabel($lig['label']);
$niveau01->setCode($lig['code']);
$niveau01->setPostaladress($lig['postaladress']);
$niveau01->setTelephonenumber($lig['telephonenumber']);
$niveau01->setEmail($lig['email']);
$niveau01->setApikey($lig['apikey']);
$manager->flush();
}
// Niveau 02
$this->writeln("Niveau02");
$this->writeln('Niveau02');
$csv = file_get_contents($this->kernel->getProjectDir().'/src/DataFixtures/niveau02.csv');
$tab = $this->csv_to_array($csv);
foreach ($tab as $lig) {
$niveau01=$manager->getRepository('App\Entity\Niveau01')->findOneBy(["code"=>$lig['codenv1']]);
if(!$niveau01) continue;
$niveau01 = $manager->getRepository('App\Entity\Niveau01')->findOneBy(['code' => $lig['codenv1']]);
if (!$niveau01) {
continue;
}
$niveau02 = $manager->getRepository('App\Entity\Niveau02')->find($lig['id']);
if (!$niveau02) {
$niveau02 = new Niveau02();
$niveau02->setId($lig["id"]);
$niveau02->setId($lig['id']);
$manager->persist($niveau02);
}
$niveau02->setLabel($lig["label"]);
$niveau02->setCode($lig["code"]);
$niveau02->setPostaladress($lig["postaladress"]);
$niveau02->setTelephonenumber($lig["telephonenumber"]);
$niveau02->setEmail($lig["email"]);
$niveau02->setApikey($lig["apikey"]);
$niveau02->setLabel($lig['label']);
$niveau02->setCode($lig['code']);
$niveau02->setPostaladress($lig['postaladress']);
$niveau02->setTelephonenumber($lig['telephonenumber']);
$niveau02->setEmail($lig['email']);
$niveau02->setApikey($lig['apikey']);
$niveau02->setNiveau01($niveau01);
$manager->flush();
}
// Niveau 03
$this->writeln("Niveau03");
$this->writeln('Niveau03');
$csv = file_get_contents($this->kernel->getProjectDir().'/src/DataFixtures/niveau03.csv');
$tab = $this->csv_to_array($csv);
foreach ($tab as $lig) {
$niveau02=$manager->getRepository('App\Entity\Niveau02')->findOneBy(["code"=>$lig['codenv2']]);
if(!$niveau02) continue;
$niveau02 = $manager->getRepository('App\Entity\Niveau02')->findOneBy(['code' => $lig['codenv2']]);
if (!$niveau02) {
continue;
}
$niveau03 = $manager->getRepository('App\Entity\Niveau03')->find($lig['id']);
if (!$niveau03) {
$niveau03 = new Niveau03();
$niveau03->setId($lig["id"]);
$niveau03->setId($lig['id']);
$manager->persist($niveau03);
}
$niveau03->setLabel($lig["label"]);
$niveau03->setCode($lig["code"]);
$niveau03->setPostaladress($lig["postaladress"]);
$niveau03->setTelephonenumber($lig["telephonenumber"]);
$niveau03->setEmail($lig["email"]);
$niveau03->setApikey($lig["apikey"]);
$niveau03->setLabel($lig['label']);
$niveau03->setCode($lig['code']);
$niveau03->setPostaladress($lig['postaladress']);
$niveau03->setTelephonenumber($lig['telephonenumber']);
$niveau03->setEmail($lig['email']);
$niveau03->setApikey($lig['apikey']);
$niveau03->setNiveau02($niveau02);
$manager->flush();
}
// Niveau 04
$this->writeln("Niveau04");
$this->writeln('Niveau04');
$csv = file_get_contents($this->kernel->getProjectDir().'/src/DataFixtures/niveau04.csv');
$tab = $this->csv_to_array($csv);
foreach ($tab as $lig) {
$niveau03=$manager->getRepository('App\Entity\Niveau03')->findOneBy(["code"=>$lig['codenv3']]);
if(!$niveau03) continue;
$niveau03 = $manager->getRepository('App\Entity\Niveau03')->findOneBy(['code' => $lig['codenv3']]);
if (!$niveau03) {
continue;
}
$niveau04 = $manager->getRepository('App\Entity\Niveau04')->find($lig['id']);
if (!$niveau04) {
$niveau04 = new Niveau04();
$niveau04->setId($lig["id"]);
$niveau04->setId($lig['id']);
$manager->persist($niveau04);
}
$niveau04->setLabel($lig["label"]);
$niveau04->setCode($lig["code"]);
$niveau04->setPostaladress($lig["postaladress"]);
$niveau04->setTelephonenumber($lig["telephonenumber"]);
$niveau04->setEmail($lig["email"]);
$niveau04->setApikey($lig["apikey"]);
$niveau04->setLabel($lig['label']);
$niveau04->setCode($lig['code']);
$niveau04->setPostaladress($lig['postaladress']);
$niveau04->setTelephonenumber($lig['telephonenumber']);
$niveau04->setEmail($lig['email']);
$niveau04->setApikey($lig['apikey']);
$niveau04->setNiveau03($niveau03);
$manager->flush();
}
// User MODO
$this->writeln("User Modo");
$this->writeln('User Modo');
$userid = -99;
$usercpt = 0;
$niveau01s = $manager->getRepository('App\Entity\Niveau01')->findAll();
foreach ($niveau01s as $niveau01) {
$userid = $userid - 1;
$usercpt = $usercpt + 1;
$username="modo".str_pad($usercpt,3,"0", STR_PAD_LEFT);
$username = 'modo'.str_pad($usercpt, 3, '0', STR_PAD_LEFT);
$user = $manager->getRepository('App\Entity\User')->find($userid);
if (!$user) {
@ -188,13 +190,13 @@ class AppFixtures extends Fixture
$user->setUsername($username);
$user->setPassword($username);
$user->setRoles(["ROLE_MODO"]);
$user->setFirstname(str_pad($usercpt,3,"0", STR_PAD_LEFT));
$user->setLastname("Modo");
$user->setEmail($username."@noreply.fr");
$user->setRoles(['ROLE_MODO']);
$user->setFirstname(str_pad($usercpt, 3, '0', STR_PAD_LEFT));
$user->setLastname('Modo');
$user->setEmail($username.'@noreply.fr');
$user->setIsvisible(true);
$user->setIsactive(true);
$user->setAvatar("noavatar.png");
$user->setAvatar('noavatar.png');
$user->setApikey($username);
$user->setNiveau01($niveau01);
@ -202,14 +204,14 @@ class AppFixtures extends Fixture
}
// User MASTER
$this->writeln("User Master");
$this->writeln('User Master');
$userid = -199;
$usercpt = 0;
$niveau02s = $manager->getRepository('App\Entity\Niveau02')->findAll();
foreach ($niveau02s as $niveau02) {
$userid = $userid - 1;
$usercpt = $usercpt + 1;
$username="master".str_pad($usercpt,3,"0", STR_PAD_LEFT);
$username = 'master'.str_pad($usercpt, 3, '0', STR_PAD_LEFT);
$user = $manager->getRepository('App\Entity\User')->find($userid);
if (!$user) {
@ -220,13 +222,13 @@ class AppFixtures extends Fixture
$user->setUsername($username);
$user->setPassword($username);
$user->setRoles(["ROLE_MASTER"]);
$user->setFirstname(str_pad($usercpt,3,"0", STR_PAD_LEFT));
$user->setLastname("Master");
$user->setEmail($username."@noreply.fr");
$user->setRoles(['ROLE_MASTER']);
$user->setFirstname(str_pad($usercpt, 3, '0', STR_PAD_LEFT));
$user->setLastname('Master');
$user->setEmail($username.'@noreply.fr');
$user->setIsvisible(true);
$user->setIsactive(true);
$user->setAvatar("noavatar.png");
$user->setAvatar('noavatar.png');
$user->setApikey($username);
$user->setNiveau01($niveau02->getNiveau01());
$user->setNiveau02($niveau02);
@ -235,14 +237,14 @@ class AppFixtures extends Fixture
}
// User MANAGER
$this->writeln("User Manager");
$this->writeln('User Manager');
$userid = -299;
$usercpt = 0;
$niveau03s = $manager->getRepository('App\Entity\Niveau03')->findAll();
foreach ($niveau03s as $niveau03) {
$userid = $userid - 1;
$usercpt = $usercpt + 1;
$username="manager".str_pad($usercpt,3,"0", STR_PAD_LEFT);
$username = 'manager'.str_pad($usercpt, 3, '0', STR_PAD_LEFT);
$user = $manager->getRepository('App\Entity\User')->find($userid);
if (!$user) {
@ -253,13 +255,13 @@ class AppFixtures extends Fixture
$user->setUsername($username);
$user->setPassword($username);
$user->setRoles(["ROLE_MANAGER"]);
$user->setFirstname(str_pad($usercpt,3,"0", STR_PAD_LEFT));
$user->setLastname("Manager");
$user->setEmail($username."@noreply.fr");
$user->setRoles(['ROLE_MANAGER']);
$user->setFirstname(str_pad($usercpt, 3, '0', STR_PAD_LEFT));
$user->setLastname('Manager');
$user->setEmail($username.'@noreply.fr');
$user->setIsvisible(true);
$user->setIsactive(true);
$user->setAvatar("noavatar.png");
$user->setAvatar('noavatar.png');
$user->setApikey($username);
$user->setNiveau01($niveau03->getNiveau02()->getNiveau01());
$user->setNiveau02($niveau03->getNiveau02());
@ -269,14 +271,14 @@ class AppFixtures extends Fixture
}
// User USER
$this->writeln("User User");
$this->writeln('User User');
$userid = -399;
$usercpt = 0;
$niveau03s = $manager->getRepository('App\Entity\Niveau03')->findAll();
foreach ($niveau03s as $niveau03) {
$userid = $userid - 1;
$usercpt = $usercpt + 1;
$username="user".str_pad($usercpt,3,"0", STR_PAD_LEFT);
$username = 'user'.str_pad($usercpt, 3, '0', STR_PAD_LEFT);
$user = $manager->getRepository('App\Entity\User')->find($userid);
if (!$user) {
@ -287,13 +289,13 @@ class AppFixtures extends Fixture
$user->setUsername($username);
$user->setPassword($username);
$user->setRoles(["ROLE_USER"]);
$user->setFirstname(str_pad($usercpt,3,"0", STR_PAD_LEFT));
$user->setLastname("User");
$user->setEmail($username."@noreply.fr");
$user->setRoles(['ROLE_USER']);
$user->setFirstname(str_pad($usercpt, 3, '0', STR_PAD_LEFT));
$user->setLastname('User');
$user->setEmail($username.'@noreply.fr');
$user->setIsvisible(true);
$user->setIsactive(true);
$user->setAvatar("noavatar.png");
$user->setAvatar('noavatar.png');
$user->setApikey($username);
$user->setNiveau01($niveau03->getNiveau02()->getNiveau01());
$user->setNiveau02($niveau03->getNiveau02());
@ -304,19 +306,20 @@ class AppFixtures extends Fixture
// app:Synchro
$manager->clear();
$this->writeln("app:Synchro");
$this->writeln('app:Synchro');
$input = new ArrayInput(['command' => 'app:Synchro']);
$boutput = new BufferedOutput();
$application->run($input, $boutput);
}
private function writeln($string) {
private function writeln($string)
{
$this->output->writeln(' <fg=yellow>></> <info>'.$string.'</info>');
}
private function csv_to_array($csv, $delimiter = ';', $enclosure = '', $escape = '\\', $terminator = "\n") {
$r = array();
private function csv_to_array($csv, $delimiter = ';', $enclosure = '', $escape = '\\', $terminator = "\n")
{
$r = [];
$rows = explode($terminator, trim($csv));
$names = array_shift($rows);
@ -325,10 +328,13 @@ class AppFixtures extends Fixture
foreach ($rows as $row) {
if (trim($row)) {
$values = str_getcsv($row, $delimiter, $enclosure, $escape);
if (!$values) $values = array_fill(0,$nc,null);
if (!$values) {
$values = array_fill(0, $nc, null);
}
@$r[] = array_combine($names, $values);
}
}
return $r;
}
}

View File

@ -181,7 +181,7 @@ class UserType extends AbstractType
);
}
if(($access!="all"&&$access!="manager")||$options["appUserviewisvisible"]) {
if (('all' != $access && 'manager' != $access) || $options['appUserviewisvisible']) {
$choices = ['oui' => '1', 'non' => '0'];
$builder->add('isvisible',
ChoiceType::class, [

View File

@ -48,7 +48,6 @@ class AppSession
$session->set('fgheader', true);
$session->set('fgaudit', false);
// Current user
$token = $this->token->getToken();
if (!$token) {