V-Beta-1.0.0

Vision is out of alpha !
This commit is contained in:
Xbird
2022-02-02 17:46:29 +01:00
parent 797bf35b47
commit 9f22f5b1ee
2297 changed files with 278438 additions and 76 deletions

View File

@@ -0,0 +1,85 @@
<?php
namespace App\Command;
use App\Entity\Group;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Question\Question;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
#[AsCommand(name: 'vision:addgroup', description: 'Add a group to vision')]
class AddGroupCommand extends Command
{
private $entityManager;
public function __construct(EntityManagerInterface $entityManager)
{
parent::__construct();
$this->entityManager = $entityManager;
}
protected function configure(): void
{
$this
->addArgument('name', InputArgument::OPTIONAL, 'Name of the group')
->addArgument('shortname', InputArgument::OPTIONAL, 'Shortname of the group')
;
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$helper = $this->getHelper('question');
$groupName = $input->getArgument('name');
if (!$groupName) {
$questionName = new Question('Please enter the name of the group : ', '');
$questionName->setValidator(function ($answer) {
if (!is_string($answer) || empty($answer)) {
throw new \RuntimeException(
'The name c\'ant be empty'
);
}
return $answer;
});
$groupName = $helper->ask($input, $output, $questionName);
}
$groupShortName = $input->getArgument('shortname');
if (!$groupShortName) {
$questionShortName = new Question('Please enter the short name of the group : ', '');
$questionShortName->setValidator(function ($answer) {
if (!is_string($answer) || empty($answer)) {
throw new \RuntimeException(
'The shortname c\'ant be empty'
);
}
return $answer;
});
$groupShortName = $helper->ask($input, $output, $questionShortName);
}
$Group = new Group();
$Group->setName($groupName);
$Group->setShortName($groupShortName);
$this->entityManager->persist($Group);
try {
$this->entityManager->flush();
$io->success('Group ' . $Group->getName() . ' created');
return Command::SUCCESS ;
} catch (\Throwable $th) {
$io->error('Error while creating ' . $Group->getName() . ' group');
return Command::FAILURE;
}
}
}

View File

@@ -0,0 +1,127 @@
<?php
namespace App\Command;
use App\Entity\Group;
use App\Entity\Rank;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Question\Question;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
#[AsCommand(name: 'vision:addrank', description: 'Add a rank to a vision\'s group')]
class AddRankCommand extends Command
{
private $entityManager;
public function __construct(EntityManagerInterface $entityManager)
{
parent::__construct();
$this->entityManager = $entityManager;
}
protected function configure(): void
{
$this
->addArgument('groupid', InputArgument::OPTIONAL, 'Id of the main group of the user')
->addArgument('name', InputArgument::OPTIONAL, 'Name of the Rank')
->addArgument('shortname', InputArgument::OPTIONAL, 'Short name of the Rank')
;
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$helper = $this->getHelper('question');
$groupid = $input->getArgument('groupid');
/**
* @var GroupRepository $groupRepository
*/
$groupRepository = $this->entityManager->getRepository("App:Group");
if ($groupid && null === $groupRepository->find($groupid)) {
$groupid = '';
}
if (!$groupid) {
foreach ($groupRepository->findAll() as $key => $g) {
$io->info('"' . $g->getName() . '" id: ' . $g->getId());
}
$questionGroup = new Question('Please enter the rank\'s group ID: ', '');
$questionGroup->setValidator(function ($answer) {
if (!is_numeric($answer) || empty($answer)) {
throw new \RuntimeException(
'The group id c\'ant be empty'
);
}
global $groupRepository;
if (null === $this->entityManager->getRepository("App:Group")->find($answer)) {
throw new \RuntimeException(
'No group find for this id'
);
}
return $answer;
});
$groupid = $helper->ask($input, $output, $questionGroup);
}
$group = $groupRepository->find($groupid);
$rankName = $input->getArgument('name');
if (!$rankName) {
$questionName = new Question('Please enter the name of the rank : ', '');
$questionName->setValidator(function ($answer) {
if (!is_string($answer) || empty($answer)) {
throw new \RuntimeException(
'The name c\'ant be empty'
);
}
return $answer;
});
$rankName = $helper->ask($input, $output, $questionName);
}
$groupShortName = $input->getArgument('shortname');
if (!$groupShortName) {
$questionShortName = new Question('Please enter the short name of the rank : ', '');
$questionShortName->setValidator(function ($answer) {
if (!is_string($answer) || empty($answer)) {
throw new \RuntimeException(
'The shortname c\'ant be empty'
);
}
return $answer;
});
$groupShortName = $helper->ask($input, $output, $questionShortName);
}
$Rank = new Rank();
$Rank->setName($rankName);
$Rank->setShortname($groupShortName);
$Rank->setMainGroup($group);
$Rank->setPower(0);
$this->entityManager->persist($Rank);
try {
$this->entityManager->flush();
$io->success('Group ' . $Rank->getName() . ' created');
return Command::SUCCESS ;
} catch (\Throwable $th) {
throw $th;
$io->error('Error while creating ' . $Rank->getName() . ' group');
return Command::FAILURE;
}
}
}

View File

@@ -0,0 +1,211 @@
<?php
namespace App\Command;
use App\Entity\User;
use Doctrine\ORM\Query;
use App\Repository\GroupRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Question\Question;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ChoiceQuestion;
use Symfony\Component\Console\Question\ConfirmationQuestion;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
#[AsCommand(name: 'vision:adduser', description: 'Add a user to vision')]
class AddUserCommand extends Command
{
private EntityManagerInterface $entityManager;
private ParameterBagInterface $params;
public function __construct(EntityManagerInterface $entityManager, ParameterBagInterface $params)
{
parent::__construct();
$this->entityManager = $entityManager;
$this->params = $params;
}
protected function configure(): void
{
$this
->addArgument('email', InputArgument::OPTIONAL, 'Email of the user')
->addArgument('firstname', InputArgument::OPTIONAL, 'Firstname of the user')
->addArgument('lastname', InputArgument::OPTIONAL, 'Lastname of the user')
->addArgument('groupid', InputArgument::OPTIONAL, 'Id of the main group of the user')
->addArgument('rankid', InputArgument::OPTIONAL, 'Id of user\'s main rank (need to be part of group)')
->addArgument('isadmin', InputArgument::OPTIONAL, 'is the user an admin ? (yes/no)')
;
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$helper = $this->getHelper('question');
$email = $input->getArgument('email');
//todo: check if the mail is ok
if (!$email) {
$questionEmail = new Question('Please enter the user\'s email : ', '');
$questionEmail->setValidator(function ($answer) {
if (!is_string($answer) || empty($answer)) {
throw new \RuntimeException(
'The email c\'ant be empty'
);
}
return $answer;
});
$email = $helper->ask($input, $output, $questionEmail);
}
$firstname = $input->getArgument('firstname');
if (!$firstname) {
$questionFirstname = new Question('Please enter the user\'s firstname : ', '');
$questionFirstname->setValidator(function ($answer) {
if (!is_string($answer) || empty($answer)) {
throw new \RuntimeException(
'The firstname c\'ant be empty'
);
}
return $answer;
});
$firstname = $helper->ask($input, $output, $questionFirstname);
}
$lastname = $input->getArgument('lastname');
if (!$lastname) {
$questionLastname = new Question('Please enter the user\'s lastname : ', '');
$questionLastname->setValidator(function ($answer) {
if (!is_string($answer) || empty($answer)) {
throw new \RuntimeException(
'The lastname c\'ant be empty'
);
}
return $answer;
});
$lastname = $helper->ask($input, $output, $questionLastname);
}
//GROUP
$groupid = $input->getArgument('groupid');
/**
* @var GroupRepository $groupRepository
*/
$groupRepository = $this->entityManager->getRepository("App:Group");
if ($groupid && null === $groupRepository->find($groupid)) {
$groupid = '';
}
if (!$groupid) {
foreach ($groupRepository->findAll() as $key => $g) {
$gList[$g->getId()] = $g->getName();
}
$questionGroup = new ChoiceQuestion('Please choose the user\'s group: ', $gList);
$questionGroup->setValidator(function ($answer) {
if (!is_numeric($answer) || empty($answer)) {
throw new \RuntimeException(
'The group id c\'ant be empty'
);
}
global $groupRepository;
if (null === $this->entityManager->getRepository("App:Group")->find($answer)) {
throw new \RuntimeException(
'No group find for this id'
);
}
return $answer;
});
$groupid = $helper->ask($input, $output, $questionGroup);
}
$group = $groupRepository->find($groupid);
//RANK
$rankid = $input->getArgument('rankid');
/**
* @var RankRepository $rankRepository
*/
$rankRepository = $this->entityManager->getRepository("App:Rank");
if ($rankid && null === $rankRepository->find($rankid)) {
$rankid = '';
}
if (!$rankid) {
foreach ($rankRepository->findByMainGroup($groupid) as $key => $r) {
$rList[$r->getId()] = $r->getName();
}
$questionRank = new ChoiceQuestion('Please choose the user\'s rank: ', $rList);
$questionRank->setValidator(function ($answer) {
if (!is_numeric($answer) || empty($answer)) {
throw new \RuntimeException(
'The rank id c\'ant be empty'
);
}
global $groupRepository;
if (null === $this->entityManager->getRepository("App:Rank")->find($answer)) {
throw new \RuntimeException(
'No rank find for this id'
);
}
return $answer;
});
$rankid = $helper->ask($input, $output, $questionRank);
}
$rank = $rankRepository->find($rankid);
$isAdmin = $input->getArgument('isadmin');
if (!$isAdmin || !in_array(\strtolower($isAdmin), ['yes', 'no'])) {
$questionFirstname = new ConfirmationQuestion('Is this user an Admin ? (yes/no, default to no): ', false);
$isAdmin = $helper->ask($input, $output, $questionFirstname);
}
$user = new User();
$user->setEmail($email);
$user->setFirstname($firstname);
$user->setLastname($lastname);
$user->setMainGroup($group);
$user->setMainRank($rank);
$user->setPassword(uniqid() . uniqid() . uniqid());
$user->setIsVerified(1);
$user->setLocale($this->params->get('kernel.default_locale'));
if ($isAdmin === true) {
$user->setRoles(['ROLE_ADMIN']);
}
$this->entityManager->persist($user);
try {
$this->entityManager->flush();
$io->success('User ' . $user->getLastname() . ' ' . $user->getFirstname() . ' created');
return Command::SUCCESS ;
} catch (\Throwable $th) {
throw $th;
$io->error('Error while creating user ' . $user->getLastname() . ' ' . $user->getFirstname());
return Command::FAILURE;
}
}
}