svg
This commit is contained in:
@ -2,6 +2,9 @@
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use App\Entity\Company;
|
||||
use App\Entity\User;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
@ -9,41 +12,63 @@ use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||||
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasher;
|
||||
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
|
||||
|
||||
#[AsCommand(
|
||||
name: 'app:init',
|
||||
description: 'Add a short description for your command',
|
||||
description: 'Initialisation of the app',
|
||||
)]
|
||||
class InitCommand extends Command
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
private EntityManagerInterface $em;
|
||||
private ParameterBagInterface $params;
|
||||
private UserPasswordHasherInterface $passwordHasher;
|
||||
|
||||
protected function configure(): void
|
||||
public function __construct(EntityManagerInterface $em,ParameterBagInterface $params,UserPasswordHasherInterface $passwordHasher)
|
||||
{
|
||||
$this
|
||||
->addArgument('arg1', InputArgument::OPTIONAL, 'Argument description')
|
||||
->addOption('option1', null, InputOption::VALUE_NONE, 'Option description')
|
||||
;
|
||||
$this->em = $em;
|
||||
$this->params = $params;
|
||||
$this->passwordHasher = $passwordHasher;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
$arg1 = $input->getArgument('arg1');
|
||||
$io->title("APP:INIT");
|
||||
$io->text("Initialisation of the app");
|
||||
$io->text("");
|
||||
|
||||
// Création du compte admin
|
||||
$io->text("> Création du compte admin");
|
||||
$user = $this->em->getRepository("App\Entity\User")->findOneBy(["username"=>"admin"]);
|
||||
if(!$user) {
|
||||
$user=new User;
|
||||
|
||||
if ($arg1) {
|
||||
$io->note(sprintf('You passed an argument: %s', $arg1));
|
||||
$hashedPassword = $this->passwordHasher->hashPassword(
|
||||
$user,
|
||||
$this->params->get("appSecret")
|
||||
);
|
||||
|
||||
$user->setUsername("admin");
|
||||
$user->setPassword($hashedPassword);
|
||||
$this->em->persist($user);
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
if ($input->getOption('option1')) {
|
||||
// ...
|
||||
// Création d'un company par defaut
|
||||
$io->text("> Création d'un company par defaut");
|
||||
$nbcompanys = $this->em->getRepository("App\Entity\Company")->count([]);
|
||||
if($nbcompanys==0) {
|
||||
$company=new Company;
|
||||
$company->setTitle($this->params->get("appName"));
|
||||
$company->setLogo("logo.png");
|
||||
$this->em->persist($company);
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
$io->success('You have a new command! Now make it your own! Pass --help to see your options.');
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
|
18
src/Controller/CompanyController.php
Normal file
18
src/Controller/CompanyController.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
class CompanyController extends AbstractController
|
||||
{
|
||||
#[Route('/admin/company', name: 'app_company')]
|
||||
public function index(): Response
|
||||
{
|
||||
return $this->render('company/index.html.twig', [
|
||||
'controller_name' => 'CompanyController',
|
||||
]);
|
||||
}
|
||||
}
|
32
src/Controller/SecurityController.php
Normal file
32
src/Controller/SecurityController.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
|
||||
|
||||
class SecurityController extends AbstractController
|
||||
{
|
||||
#[Route(path: '/login', name: 'app_login')]
|
||||
public function login(AuthenticationUtils $authenticationUtils): Response
|
||||
{
|
||||
// get the login error if there is one
|
||||
$error = $authenticationUtils->getLastAuthenticationError();
|
||||
|
||||
// last username entered by the user
|
||||
$lastUsername = $authenticationUtils->getLastUsername();
|
||||
|
||||
return $this->render('security/login.html.twig', [
|
||||
'last_username' => $lastUsername,
|
||||
'error' => $error,
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route(path: '/logout', name: 'app_logout')]
|
||||
public function logout(): void
|
||||
{
|
||||
throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
|
||||
}
|
||||
}
|
@ -24,6 +24,9 @@ class Accounting
|
||||
#[ORM\Column(length: 255)]
|
||||
private ?string $title = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
private ?string $icon = null;
|
||||
|
||||
#[ORM\Column]
|
||||
private ?bool $actif = null;
|
||||
|
||||
@ -90,6 +93,18 @@ class Accounting
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getIcon(): ?string
|
||||
{
|
||||
return $this->icon;
|
||||
}
|
||||
|
||||
public function setIcon(string $icon): static
|
||||
{
|
||||
$this->icon = $icon;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isActif(): ?bool
|
||||
{
|
||||
return $this->actif;
|
||||
|
54
src/EventSubscriber/CompanySubscriber.php
Normal file
54
src/EventSubscriber/CompanySubscriber.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\EventSubscriber;
|
||||
|
||||
use App\Entity\Accounting;
|
||||
use App\Entity\Company;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\Event\PostPersistEventArgs;
|
||||
use Doctrine\ORM\Events;
|
||||
|
||||
class CompanySubscriber
|
||||
{
|
||||
private EntityManagerInterface $em;
|
||||
|
||||
public function __construct(EntityManagerInterface $em)
|
||||
{
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
public function postPersist(PostPersistEventArgs $args): void
|
||||
{
|
||||
$company = $args->getObject();
|
||||
if (!$company instanceof Company) {
|
||||
return;
|
||||
}
|
||||
|
||||
$entityManager = $args->getObjectManager();
|
||||
|
||||
// Génération des accounting par défaut
|
||||
$this->insertAccounting($company,"512","000","Banque",true);
|
||||
$this->insertAccounting($company,"530","000","Caisse",true);
|
||||
$this->insertAccounting($company,"600","000","Charge",false);
|
||||
$this->insertAccounting($company,"700","000","Produit",false);
|
||||
|
||||
// Génération du year par
|
||||
}
|
||||
|
||||
private function insertAccounting(Company $company,string $num01, string $num02, string $title, bool $isactif): void
|
||||
{
|
||||
$accounting=$this->em->getRepository("App\Entity\Accounting")->findOneBy(["company"=>$company,"num01"=>$num01,"num02"=>$num02]);
|
||||
if(!$accounting) {
|
||||
$accounting = new Accounting;
|
||||
$accounting->setCompany($company);
|
||||
$accounting->setNum01($num01);
|
||||
$accounting->setNum02($num02);
|
||||
$accounting->setTitle($title);
|
||||
$accounting->SetActif($isactif);
|
||||
$this->em->persist($accounting);
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user