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;
}
}
}

0
src/Controller/.gitignore vendored Normal file
View File

View File

@@ -0,0 +1,696 @@
<?php
namespace App\Controller;
use App\Entity\Rank;
use App\Entity\User;
use App\Entity\Group;
use App\Entity\SubGroup;
use App\Form\AdminRankType;
use App\Form\AdminUserType;
use App\Form\SearchBarType;
use App\Form\AdminGroupType;
use App\Form\AdminSubGroupType;
use App\Repository\UserRepository;
use App\Repository\GroupRepository;
use Symfony\Component\Finder\Finder;
use App\Repository\DocumentRepository;
use App\Repository\DirectoryRepository;
use Doctrine\ORM\EntityManagerInterface;
use Knp\Component\Pager\PaginatorInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Mime\FileinfoMimeTypeGuesser;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
#[Route('/admin', name: 'admin_')]
class AdminController extends AbstractController
{
private Security $security;
public function __construct(Security $security)
{
$this->security = $security;
}
#[Route('/', name: 'index')]
public function index(
DocumentRepository $DocumentRepository,
UserRepository $UserRepository,
DirectoryRepository $DirectoryRepository,
GroupRepository $GroupRepository
): Response {
return $this->render('admin/index.html.twig', [
'controller_name' => 'AdminController',
'documents' => $DocumentRepository->findAll(),
'users' => $UserRepository->findAll(),
'directories' => $DirectoryRepository->findAll(),
'folders' => $DocumentRepository->list()->limitType("Folder")->getResult(),
'gangs' => $DocumentRepository->list()->limitType("Gang")->getResult(),
'groups' => $GroupRepository->findAll(),
]);
}
//-- users
#[Route('/user', name: 'user_list')]
public function user(PaginatorInterface $paginator, Request $request, UserRepository $UserRepository): Response
{
$searchForm = $this->createForm(SearchBarType::class);
$searchForm->handleRequest($request);
$pagination = $paginator->paginate(
$UserRepository->getAll()
->search(
(
$searchForm->isSubmitted()
&& $searchForm->isValid()
&& $searchForm->getData()['subject'] !== null
) ? $searchForm->getData()['subject'] : null,
true
)
->getResult(),
$request->query->getInt('page', 1)
);
return $this->render('admin/user.html.twig', [
'controller_name' => 'AdminController',
'searchForm' => $searchForm->createView(),
'pagination' => $pagination,
]);
}
#[Route('/user/view/{id}', name: 'user_view')]
public function userView(PaginatorInterface $paginator, User $User): Response
{
$pagination = $paginator->paginate($User->getDocuments());
return $this->render('admin/user_view.html.twig', [
'controller_name' => 'AdminController',
'user' => $User,
'pagination' => $pagination
]);
}
#[Route('/user/disable/{id}', name: 'user_disable')]
public function userDisable(Request $Request, User $User): Response
{
$User->setIsDesactivated(($User->getIsDesactivated() ? false : true));
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($User);
try {
$entityManager->flush();
if ($User->getIsDesactivated()) {
$this->addFlash('success', 'alert_success_desactivating_user');
} else {
$this->addFlash('success', 'alert_success_activating_user');
}
} catch (\Throwable $th) {
if ($_ENV['APP_ENV'] === 'dev') {
throw $th; //DEBUG
}
$this->addFlash('danger', 'alert_error_saving_user');
}
if (null != $Request->headers->get('referer')) {
return $this->redirect($Request->headers->get('referer'));
}
return $this->redirectToRoute('admin_user_view', ['id' => $User->getId()]);
}
#[Route('/user/edit/{id}', name: 'user_edit')]
public function userEdit(Request $request, User $User): Response
{
$currentUserGroup = $User->getMainGroup();
$form = $this->createForm(AdminUserType::class, $User);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
if ($currentUserGroup != $User->getMainGroup()) {
//if a user change group, he lost his SubGroups
$User->getSubGroups()->clear();
}
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($User);
try {
$entityManager->flush();
$this->addFlash('success', 'alert_success_saving_user');
return $this->redirectToRoute('admin_user_edit', ['id' => $User->getId()]);
} catch (\Throwable $th) {
if ($_ENV['APP_ENV'] === 'dev') {
throw $th; //DEBUG
}
$this->addFlash('danger', 'alert_error_saving_user');
return $this->redirectToRoute('admin_user_edit', ['id' => $User->getId()]);
}
}
return $this->render('admin/user_edit.html.twig', [
'controller_name' => 'AdminController',
'user' => $User,
'form' => $form->createView()
]);
}
//-- groups
#[Route('/group', name: 'group_list')]
public function group(PaginatorInterface $paginator, Request $request, GroupRepository $GroupRepository): Response
{
$searchForm = $this->createForm(SearchBarType::class);
$searchForm->handleRequest($request);
$pagination = $paginator->paginate(
$GroupRepository->getAll()
->search(
(
$searchForm->isSubmitted()
&& $searchForm->isValid()
&& $searchForm->getData()['subject'] !== null
) ? $searchForm->getData()['subject'] : null
)->getResult(),
$request->query->getInt('page', 1)
);
return $this->render('admin/group.html.twig', [
'controller_name' => 'AdminController',
'searchForm' => $searchForm->createView(),
'pagination' => $pagination,
]);
}
#[Route('/group/view/{id}', name: 'group_view')]
public function groupView(Group $Group): Response
{
return $this->render('admin/group_view.html.twig', [
'controller_name' => 'AdminController',
'group' => $Group,
]);
}
#[Route('/group/documents/{id}', name: 'group_documents')]
public function groupDocuments(
PaginatorInterface $paginator,
Request $request,
DocumentRepository $DocumentRepository,
Group $Group
): Response {
$searchForm = $this->createForm(SearchBarType::class);
$searchForm->handleRequest($request);
$pagination = $paginator->paginate(
$DocumentRepository ->list()
->limitGroup($Group)
->search(
(
$searchForm->isSubmitted()
&& $searchForm->isValid()
&& $searchForm->getData()['subject'] !== null
) ? $searchForm->getData()['subject'] : null
)
->order(['createdAt' => 'DESC'])
->getResult(),
$request->query->getInt('page', 1)
);
return $this->render('admin/group_documents.html.twig', [
'controller_name' => 'AdminController',
'pagination' => $pagination,
'group' => $Group,
'searchForm' => $searchForm->createView(),
]);
}
#[Route('/group/add', name: 'group_add')]
public function groupAdd(Request $request): Response
{
$Group = new Group();
$form = $this->createForm(AdminGroupType::class, $Group);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($Group);
try {
$entityManager->flush();
$this->addFlash('success', 'alert_success_creating_group');
return $this->redirectToRoute('admin_group_view', ['id' => $Group->getId()]);
} catch (\Throwable $th) {
if ($_ENV['APP_ENV'] === 'dev') {
throw $th; //DEBUG
}
$this->addFlash('danger', 'alert_error_creating_group');
}
}
return $this->render('admin/group_add.html.twig', [
'controller_name' => 'AdminController',
'group' => $Group,
'form' => $form->createView()
]);
}
#[Route('/group/edit/{id}', name: 'group_edit')]
public function groupEdit(Request $request, Group $Group): Response
{
$form = $this->createForm(AdminGroupType::class, $Group);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($Group);
try {
$entityManager->flush();
$this->addFlash('success', 'alert_success_editing_group');
return $this->redirectToRoute('admin_group_view', ['id' => $Group->getId()]);
} catch (\Throwable $th) {
if ($_ENV['APP_ENV'] === 'dev') {
throw $th; //DEBUG
}
$this->addFlash('danger', 'alert_error_editing_group');
}
}
return $this->render('admin/group_edit.html.twig', [
'controller_name' => 'AdminController',
'group' => $Group,
'form' => $form->createView()
]);
}
#[Route('/group/delete/{id}', name: 'group_delete')]
public function groupDelete(Group $Group): Response
{
$entityManager = $this->getDoctrine()->getManager();
$entityManager->remove($Group);
try {
$entityManager->flush();
$this->addFlash('success', 'alert_success_deleting_group');
return $this->redirectToRoute('admin_group_list');
} catch (\Throwable $th) {
if ($_ENV['APP_ENV'] === 'dev') {
throw $th; //DEBUG
}
$this->addFlash('danger', 'alert_error_deleting_group');
return $this->redirectToRoute('admin_group_view', ['id' => $Group->getId()]);
}
}
//-- Groups Ranks
#[Route('/group/rank/view/{id}', name: 'group_rank_view')]
public function groupRankView(Rank $Rank): Response
{
return $this->render('admin/group_rank_view.html.twig', [
'controller_name' => 'AdminController',
'rank' => $Rank,
'group' => $Rank->getMainGroup(),
]);
}
#[Route('/group/rank/edit/{id}', name: 'group_rank_edit')]
public function groupRankEdit(Request $request, Rank $Rank): Response
{
$form = $this->createForm(AdminRankType::class, $Rank);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($Rank);
try {
$entityManager->flush();
$this->addFlash('success', 'alert_success_editing_rank');
return $this->redirectToRoute('admin_group_rank_view', ['id' => $Rank->getId()]);
} catch (\Throwable $th) {
if ($_ENV['APP_ENV'] === 'dev') {
throw $th; //DEBUG
}
$this->addFlash('danger', 'alert_error_editing_rank');
}
}
return $this->render('admin/group_rank_edit.html.twig', [
'controller_name' => 'AdminController',
'rank' => $Rank,
'group' => $Rank->getMainGroup(),
'form' => $form->createView()
]);
}
#[Route('/group/rank/add/{id}', name: 'group_rank_add')]
public function groupRankAdd(Request $request, Group $Group): Response
{
$Rank = new Rank();
$Rank->setMainGroup($Group);
$form = $this->createForm(AdminRankType::class, $Rank);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($Rank);
try {
$entityManager->flush();
$this->addFlash('success', 'alert_success_creating_rank');
return $this->redirectToRoute('admin_group_rank_view', ['id' => $Rank->getId()]);
} catch (\Throwable $th) {
if ($_ENV['APP_ENV'] === 'dev') {
throw $th; //DEBUG
}
$this->addFlash('danger', 'alert_error_creating_rank');
}
}
return $this->render('admin/group_rank_add.html.twig', [
'controller_name' => 'AdminController',
'rank' => $Rank,
'group' => $Rank->getMainGroup(),
'form' => $form->createView()
]);
}
#[Route('/rank/copy/{id}', name: 'group_rank_copy')]
public function rankCopy(Rank $Rank): Response
{
$entityManager = $this->getDoctrine()->getManager();
$newrank = clone $Rank;
$newrank->setName($newrank->getName() . ' - copy');
$entityManager->persist($newrank);
try {
$entityManager->flush();
$this->addFlash('success', 'alert_success_copying_rank');
return $this->redirectToRoute('admin_group_rank_view', ['id' => $newrank->getId()]);
} catch (\Throwable $th) {
if ($_ENV['APP_ENV'] === 'dev') {
throw $th; //DEBUG
}
$this->addFlash('danger', 'alert_error_copying_rank');
return $this->redirectToRoute('admin_group_rank_view', ['id' => $Rank->getId()]);
}
}
#[Route('/rank/delete/{id}', name: 'group_rank_delete')]
public function rankDelete(Rank $Rank): Response
{
$entityManager = $this->getDoctrine()->getManager();
$entityManager->remove($Rank);
try {
$entityManager->flush();
$this->addFlash('success', 'alert_success_deleting_rank');
return $this->redirectToRoute('admin_group_view', ['id' => $Rank->getMainGroup()->getId()]);
} catch (\Throwable $th) {
if ($_ENV['APP_ENV'] === 'dev') {
throw $th; //DEBUG
}
$this->addFlash('danger', 'alert_error_deleting_rank');
return $this->redirectToRoute('admin_group_rank_view', ['id' => $Rank->getId()]);
}
}
//-- Groups SubGroups
#[Route('/group/subgroup/view/{id}', name: 'group_subgroup_view')]
public function groupSubGroupView(SubGroup $SubGroup): Response
{
return $this->render('admin/group_subgroup_view.html.twig', [
'controller_name' => 'AdminController',
'subgroup' => $SubGroup,
'group' => $SubGroup->getMainGroup(),
]);
}
#[Route('/group/subgroup/edit/{id}', name: 'group_subgroup_edit')]
public function groupSubGroupEdit(Request $request, SubGroup $SubGroup): Response
{
$form = $this->createForm(AdminSubGroupType::class, $SubGroup);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($SubGroup);
try {
$entityManager->flush();
$this->addFlash('success', 'alert_success_editing_subgroup');
return $this->redirectToRoute('admin_group_subgroup_view', ['id' => $SubGroup->getId()]);
} catch (\Throwable $th) {
if ($_ENV['APP_ENV'] === 'dev') {
throw $th; //DEBUG
}
$this->addFlash('danger', 'alert_error_editing_subgroup');
}
}
return $this->render('admin/group_subgroup_edit.html.twig', [
'controller_name' => 'AdminController',
'subgroup' => $SubGroup,
'group' => $SubGroup->getMainGroup(),
'form' => $form->createView()
]);
}
#[Route('/group/subgroup/add/{id}', name: 'group_subgroup_add')]
public function groupSubGroupAdd(Request $request, Group $Group): Response
{
$SubGroup = new SubGroup();
$SubGroup->setMainGroup($Group);
$form = $this->createForm(AdminSubGroupType::class, $SubGroup);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($SubGroup);
try {
$entityManager->flush();
$this->addFlash('success', 'alert_success_creating_subgroup');
return $this->redirectToRoute('admin_group_subgroup_view', ['id' => $SubGroup->getId()]);
} catch (\Throwable $th) {
if ($_ENV['APP_ENV'] === 'dev') {
throw $th; //DEBUG
}
$this->addFlash('danger', 'alert_error_creating_subgroup');
}
}
return $this->render('admin/group_subgroup_add.html.twig', [
'controller_name' => 'AdminController',
'subgroup' => $SubGroup,
'group' => $SubGroup->getMainGroup(),
'form' => $form->createView()
]);
}
#[Route('/subgroup/delete/{id}', name: 'group_subgroup_delete')]
public function subgroupDelete(SubGroup $SubGroup): Response
{
$entityManager = $this->getDoctrine()->getManager();
$entityManager->remove($SubGroup);
try {
$entityManager->flush();
$this->addFlash('success', 'alert_success_deleting_subgroup');
return $this->redirectToRoute('admin_group_view', ['id' => $SubGroup->getMainGroup()->getId()]);
} catch (\Throwable $th) {
if ($_ENV['APP_ENV'] === 'dev') {
throw $th; //DEBUG
}
$this->addFlash('danger', 'alert_error_deleting_subgroup');
return $this->redirectToRoute('admin_group_subgroup_view', ['id' => $SubGroup->getId()]);
}
}
//-- Logs
#[Route('/logs', name: 'logs')]
public function logs(Request $Request): Response
{
$finder = new Finder();
$finder->files()->in($this->getParameter('kernel.logs_dir'));
return $this->render('admin/logs.html.twig', [
'controller_name' => 'AdminController',
'files' => $finder
]);
}
#[Route('/logs/view/{filename}', name: 'logs_view')]
public function logsView(string $filename, Request $Request): Response
{
$filePath = $this->getParameter('kernel.logs_dir') . '/' . $filename;
$filesystem = new Filesystem();
if (!$filesystem->exists($filePath)) {
throw new NotFoundHttpException('error_log_file_not_found');
}
$content = preg_replace(
[
'/(?<=\[).+?(?=\])/'
],
[
"<span class=\"text-success\">$0</span>"
],
file_get_contents($filePath)
);
$content = str_replace(
['request.CRITICAL'],
["<span class=\"text-danger\">request.CRITICAL</span>"],
$content
);
return $this->render('admin/logs_view.html.twig', [
'controller_name' => 'AdminController',
'name' => $filename,
'path' => $filePath,
'content' => $content
]);
}
#[Route('/logs/delete/{filename}', name: 'logs_delete')]
public function logsDelete(string $filename, Request $Request): Response
{
$filePath = $this->getParameter('kernel.logs_dir') . '/' . $filename;
$filesystem = new Filesystem();
if (!$filesystem->exists($filePath)) {
throw new NotFoundHttpException('error_log_file_not_found');
}
try {
$filesystem->remove($filePath);
} catch (\Throwable $th) {
if ($_ENV['APP_ENV'] === 'dev') {
throw $th; //DEBUG
}
$this->addFlash('danger', 'alert_error_deleting_log');
$referer = $Request->headers->get('referer');
return $this->redirect($referer);
}
$this->addFlash('success', 'alert_success_deleting_log');
return $this->redirectToRoute('admin_logs');
}
#[Route('/logs/download/{filename}', name: 'logs_download')]
public function logsDownload(string $filename, Request $Request): Response
{
$filePath = $this->getParameter('kernel.logs_dir') . '/' . $filename;
$filesystem = new Filesystem();
if (!$filesystem->exists($filePath)) {
throw new NotFoundHttpException('error_log_file_not_found');
}
// This should return the file to the browser as response
$response = new BinaryFileResponse(
$filePath
);
// To generate a file download, you need the mimetype of the file
$mimeTypeGuesser = new FileinfoMimeTypeGuesser();
// Set the mimetype with the guesser or manually
if ($mimeTypeGuesser->isGuesserSupported()) {
// Guess the mimetype of the file according to the extension of the file
$response->headers->set(
'Content-Type',
$mimeTypeGuesser->guessMimeType(
$filePath
)
);
} else {
// Set the mimetype of the file manually, in this case for a text file is text/plain
$response->headers->set('Content-Type', 'text/plain');
}
// Set content disposition inline of the file
$response->setContentDisposition(
ResponseHeaderBag::DISPOSITION_ATTACHMENT,
$filename
);
return $response;
}
#[Route('/watchdog', name: 'watchdog')]
public function watchdog(
PaginatorInterface $paginator,
Request $Request,
EntityManagerInterface $EntityManagerInterface
): Response {
/**
* @var LogEntryRepository $logEntryRepository
*/
$logEntryRepository = $EntityManagerInterface->getRepository('Gedmo\Loggable\Entity\LogEntry');
$qb = $EntityManagerInterface->createQueryBuilder();
$qb->select('l')
->from('Gedmo\Loggable\Entity\LogEntry', 'l')
->orderBy('l.loggedAt', 'DESC');
$pagination = $paginator->paginate(
$qb->getQuery()->getResult(),
$Request->query->getInt('page', 1)
);
return $this->render('admin/watchdog.html.twig', [
'controller_name' => 'AdminController',
'pagination' => $pagination
]);
}
//-- Specials
#[Route('/adminmode', name: 'mode')]
public function adminMode(Request $Request): Response
{
/**
* @var User $user
* */
$user = $this->security->getUser();
$currentAdminMode = $user->getAdminmode();
$newAdminMode = !(is_null($currentAdminMode) || $currentAdminMode);
$user->setAdminmode($newAdminMode);
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($user);
try {
$entityManager->flush();
} catch (\Throwable $th) {
if ($_ENV['APP_ENV'] === 'dev') {
throw $th; //DEBUG
}
$this->addFlash('danger', 'alert_error_switching_adminmode');
}
$referer = $Request->headers->get('referer');
return $this->redirect($referer);
}
}

View File

@@ -0,0 +1,108 @@
<?php
namespace App\Controller;
use App\Entity\Comment;
use App\Entity\Document;
use App\Form\CommentType;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
#[Route('/comment', name: 'comment_')]
class CommentController extends AbstractController
{
#[Route('/create/{Document}', name: 'create')]
#[IsGranted('view', subject: 'Document', message: 'granted_not_allowed_comment')]
public function create(Document $Document, Request $request): Response
{
$Comment = new Comment($this->getUser());
$form = $this->createForm(CommentType::class, $Comment);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$Comment->setDocument($Document);
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($Comment);
try {
$entityManager->flush();
} catch (\Throwable $th) {
if ($_ENV['APP_ENV'] === 'dev') {
throw $th; //DEBUG
}
$this->addFlash('danger', 'alert_error_creating_comment');
return $this->redirectToRoute('document_view', ['id' => $Document->getId()]);
}
$this->addFlash('success', 'alert_success_creating_comment');
return $this->redirectToRoute('document_view', ['id' => $Document->getId()]);
}
return $this->redirectToRoute('document_view', ['id' => $Document->getId()]);
}
#[Route('/delete/{id}', name: 'delete')]
#[IsGranted('delete', subject: 'Comment', message: 'granted_not_allowed_deleting_comment')]
public function delete(Comment $Comment): Response
{
if (!$this->IsGranted('view', $Comment->getDocument())) {
throw new AccessDeniedHttpException('granted_not_allowed_delete_comment_on_unallowed_document');
}
$entityManager = $this->getDoctrine()->getManager();
$entityManager->remove($Comment);
try {
$entityManager->flush();
} catch (\Throwable $th) {
if ($_ENV['APP_ENV'] === 'dev') {
throw $th; //DEBUG
}
$this->addFlash('warning', 'alert_error_deleting_comment');
return $this->redirectToRoute('document_view', ['id' => $Comment->getDocument()->getId()]);
}
$this->addFlash('success', 'alert_success_deleting_comment');
return $this->redirectToRoute('document_view', ['id' => $Comment->getDocument()->getId()]);
}
#[Route('/edit/{id}', name: 'edit')]
#[IsGranted('edit', subject: 'Comment', message: 'granted_not_allowed_editing_comment')]
public function edit(Comment $Comment, Request $request): Response
{
if (!$this->IsGranted('view', $Comment->getDocument())) {
throw new AccessDeniedHttpException('granted_not_allowed_editing_comment_on_unallowed_document');
}
$form = $this->createForm(CommentType::class, $Comment);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($Comment);
try {
$entityManager->flush();
} catch (\Throwable $th) {
if ($_ENV['APP_ENV'] === 'dev') {
throw $th; //DEBUG
}
$this->addFlash('danger', 'alert_error_editing_comment');
return $this->redirectToRoute('document_view', ['id' => $Comment->getDocument()->getId()]);
}
$this->addFlash('success', 'alert_success_editing_comment');
return $this->redirectToRoute('document_view', ['id' => $Comment->getDocument()->getId()]);
}
return $this->render('comment/edit.html.twig', [
'controller_name' => 'CommentController',
'comment' => $Comment,
'form' => $form->createView()
]);
}
}

View File

@@ -0,0 +1,293 @@
<?php
namespace App\Controller;
use App\Entity\Directory;
use App\Form\DirectoryType;
use App\Form\SearchBarType;
use App\Repository\DocumentRepository;
use App\Repository\DirectoryRepository;
use Doctrine\ORM\EntityManagerInterface;
use App\Repository\CertificateRepository;
use Knp\Component\Pager\PaginatorInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
#[Route('/directory', name: 'directory_')]
class DirectoryController extends AbstractController
{
#[Route('/', name: 'list')]
#[Route('/wanted', name: 'list_wanted')]
#[Route('/dead', name: 'list_dead')]
public function list(
PaginatorInterface $paginator,
Request $request,
DirectoryRepository $DirectoryRepository
): Response {
$searchForm = $this->createForm(SearchBarType::class);
$searchForm->handleRequest($request);
$req = $DirectoryRepository->list()
->search(
(
$searchForm->isSubmitted()
&& $searchForm->isValid()
&& $searchForm->getData()['subject'] !== null
) ? $searchForm->getData()['subject'] : null
);
if ($request->attributes->get('_route') == 'directory_list_wanted') {
$req->wanted();
}
if ($request->attributes->get('_route') == 'directory_list_dead') {
$req->dead();
} else {
$req->notDead();
}
$pagination = $paginator->paginate(
$req->getResult()
);
return $this->render('directory/list.html.twig', [
'controller_name' => 'DirectoryController',
'pagination' => $pagination,
'searchForm' => $searchForm->createView(),
'wanted' => ($request->attributes->get('_route') == 'directory_list_wanted'),
'dead' => ($request->attributes->get('_route') == 'directory_list_dead')
]);
}
#[Route('/view/{id}', name: 'view')]
public function view(Directory $Directory): Response
{
$entityManager = $this->getDoctrine()->getManager();
$DocumentList = [
'Certificate',
'Complaint',
'LicenceWithdrawal',
'Infringement',
'Jail',
'Bracelet',
'Criminal',
'Stolenvehicle',
'Medical'
];
$RenderArray = [
'controller_name' => 'DirectoryController',
'directory' => $Directory,
];
foreach ($DocumentList as $key => $dType) {
/**
* Use Certificate as example for IDE
* @var CertificateRepository $repo
*/
$repo = $entityManager->getRepository('App\Entity\\' . $dType);
$RenderArray[$dType] = $repo->listForUser($this->getUser())->limitDirectory($Directory)->getResult();
}
return $this->render('directory/view.html.twig', $RenderArray);
}
#[Route('/create', name: 'create')]
public function create(Request $request): Response
{
$Directory = new Directory();
if (!$this->IsGranted('create', $Directory)) {
throw new AccessDeniedHttpException('granted_not_allowed_creating_directory');
}
$form = $this->createForm(DirectoryType::class, $Directory);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($Directory);
try {
$entityManager->flush();
} catch (\Throwable $th) {
if ($_ENV['APP_ENV'] === 'dev') {
throw $th; //DEBUG
}
$this->addFlash('danger', 'alert_error_creating_directory');
return $this->redirectToRoute($request->getRequestUri());
}
$this->addFlash('success', 'alert_success_creating_directory');
return $this->redirectToRoute('directory_view', ['id' => $Directory->getId()]);
}
return $this->render('directory/create.html.twig', [
'controller_name' => 'DirectoryController',
'directory' => $Directory,
'form' => $form->createView()
]);
}
#[Route('/edit/{id}', name: 'edit')]
#[IsGranted('edit', subject: 'Directory', message: 'granted_not_allowed_editing_directory')]
public function edit(Request $request, Directory $Directory): Response
{
$form = $this->createForm(DirectoryType::class, $Directory);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($Directory);
try {
$entityManager->flush();
} catch (\Throwable $th) {
if ($_ENV['APP_ENV'] === 'dev') {
throw $th; //DEBUG
}
$this->addFlash('danger', 'alert_error_editing_directory');
return $this->redirectToRoute($request->getRequestUri());
}
$this->addFlash('success', 'alert_success_editing_directory');
return $this->redirectToRoute('directory_view', ['id' => $Directory->getId()]);
}
return $this->render('directory/edit.html.twig', [
'controller_name' => 'DirectoryController',
'directory' => $Directory,
'form' => $form->createView()
]);
}
#[Route('/delete/{id}', name: 'delete')]
#[IsGranted('delete', subject: 'Directory', message: 'granted_not_allowed_deleting_directory')]
public function delete(Directory $Directory): Response
{
$entityManager = $this->getDoctrine()->getManager();
$entityManager->remove($Directory);
try {
$entityManager->flush();
} catch (\Throwable $th) {
if ($_ENV['APP_ENV'] === 'dev') {
throw $th; //DEBUG
}
$this->addFlash('warning', 'alert_error_deleting_directory');
return $this->redirectToRoute('directory_view', ['id' => $Directory->getId()]);
}
$this->addFlash('success', 'alert_success_deleting_directory');
return $this->redirectToRoute('directory_list');
}
#[Route('/merge/router', name: 'merge_router')]
public function directoryMergeRouter(Request $Request): Response
{
if (empty($Request->request->get('directory-main')) || is_null($Request->request->get('directory-main'))) {
return $this->redirectToRoute('directory_list'); //id not found = redirect to list
}
if (empty($Request->request->get('directory-child')) || is_null($Request->request->get('directory-child'))) {
return $this->redirectToRoute('directory_list'); //id not found = redirect to list
}
return $this->redirectToRoute(
'directory_merge',
[
'keeped' => $Request->request->get('directory-main'),
'deleted' => $Request->request->get('directory-child')
]
);
}
#[Route('/merge/{deleted}/{keeped}', name: 'merge')]
#[IsGranted('delete', subject: 'keeped', message: 'granted_not_allowed_merging_directory')]
public function merge(
Directory $deleted,
Directory $keeped,
Request $Request,
EntityManagerInterface $EntityManagerInterface
): Response {
$base = clone $keeped;
// 1 : merge info before validation for display
$classMetadata = $EntityManagerInterface->getClassMetadata(Directory::class);
foreach ($classMetadata->getFieldNames() as $key => $f) {
if (
is_null($classMetadata->getFieldValue($keeped, $f))
&& !is_null($classMetadata->getFieldValue($deleted, $f))
) {
$classMetadata->setFieldValue($keeped, $f, $classMetadata->getFieldValue($deleted, $f));
}
}
if (null != ($Request->request->get('validatemerge')) && !empty($Request->request->get('validatemerge'))) {
//after validation
// 2 : check foreing keys
$entityManager = $this->getDoctrine()->getManager();
foreach ($classMetadata->getAssociationMappings() as $key => $associationMapping) {
//get mappings of deleted entity
$mappings = $classMetadata->getFieldValue($deleted, $associationMapping['fieldName']);
if (is_a($mappings, 'Doctrine\ORM\PersistentCollection')) {
//if mapping is a Collection
foreach ($mappings as $mapping) {
if (is_object($mapping) && method_exists($mapping, 'setDirectory')) {
$mapping->setDirectory($keeped);
}
}
} else {
$entityManager->initializeObject($mappings);
if (is_object($mappings) && method_exists($mappings, 'addDirectory')) {
$mappings->addDirectory($keeped);
}
}
}
$entityManager->persist($keeped);
try {
$entityManager->flush();
} catch (\Throwable $th) {
if ($_ENV['APP_ENV'] === 'dev') {
throw $th; //DEBUG
}
$this->addFlash('danger', 'alert_error_merging_directory');
return $this->redirectToRoute('directory_view', ['id' => $deleted->getId()]);
}
$entityManager->refresh($deleted); //refresh entity after flushing, to avoid deleting mappings
$deletedId = $deleted->getId();
$entityManager->remove($deleted);
//dd($deleted);
try {
$entityManager->flush();
} catch (\Throwable $th) {
if ($_ENV['APP_ENV'] === 'dev') {
throw $th; //DEBUG
}
$this->addFlash('danger', 'alert_error_merging_directory');
return $this->redirectToRoute('directory_view', ['id' => $deletedId]);
}
$this->addFlash('success', 'alert_success_merging_directory');
return $this->redirectToRoute('directory_view', ['id' => $keeped->getId()]);
}
return $this->render('directory/merge.html.twig', [
'controller_name' => 'DirectoryController',
'baseDirectory' => $base,
'keepedDirectory' => $keeped,
'deletedDirectory' => $deleted
]);
}
}

View File

@@ -0,0 +1,361 @@
<?php
namespace App\Controller;
use App\Entity\User;
use App\Form\TestType;
use App\Entity\Comment;
use App\Entity\Document;
use App\Entity\Directory;
use App\Form\CommentType;
use App\Form\SearchBarType;
use App\Repository\DocumentRepository;
use Doctrine\ORM\EntityManagerInterface;
use Knp\Component\Pager\PaginatorInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Gedmo\Loggable\Entity\Repository\LogEntryRepository;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
#[Route('/document', name: 'document_')]
class DocumentController extends AbstractController
{
private TokenStorageInterface $TokenStorage;
public function __construct(TokenStorageInterface $TokenStorage)
{
$this->TokenStorage = $TokenStorage;
}
#[Route('/archive/{id}', name: 'archive')]
#[IsGranted('archive', subject: 'Document', message: 'granted_not_allowed_archiving_document')]
public function archive(Document $Document, Request $Request): Response
{
$entityManager = $this->getDoctrine()->getManager();
$Document->setArchive(($Document->getArchive()) ? false : true);
$entityManager->persist($Document);
try {
$entityManager->flush();
} catch (\Throwable $th) {
if ($_ENV['APP_ENV'] === 'dev') {
throw $th; //DEBUG
}
$this->addFlash(
'warning',
'alert_error_' . (($Document->getArchive()) ? 'archiving' : 'unarchiving') . '_document'
);
if (null != $Request->headers->get('referer')) {
return $this->redirect($Request->headers->get('referer'));
}
return $this->redirectToRoute('document_view', ['id' => $Document->getId()]);
}
$this->addFlash(
'success',
'alert_success_' . (($Document->getArchive()) ? 'archiving' : 'unarchiving') . '_document'
);
if (null != $Request->headers->get('referer')) {
return $this->redirect($Request->headers->get('referer'));
}
return $this->redirectToRoute('document_view', ['id' => $Document->getId()]);
}
#[Route('/view/{id}', name: 'view')]
#[IsGranted('view', subject: 'Document', message: 'granted_not_allowed_viewing_document')]
public function view(Document $Document, EntityManagerInterface $em): Response
{
$formComment = $this->createForm(
CommentType::class,
new Comment(),
[ 'action' => $this->generateUrl('comment_create', ['Document' => $Document->getId()])]
);
/**
* @var LogEntryRepository $logEntryRepository
*/
$logEntryRepository = $em->getRepository('Gedmo\Loggable\Entity\LogEntry');
$documentHistory = $logEntryRepository->getLogEntries($Document);
return $this->render('document/view.html.twig', [
'controller_name' => 'DocumentController',
'document' => $Document,
'history' => $documentHistory,
'formComment' => $formComment->createView()
]);
}
#[Route('/history/{id}', name: 'history')]
#[IsGranted('view', subject: 'Document', message: 'granted_not_allowed_viewing_document')]
public function history(Document $Document, EntityManagerInterface $em): Response
{
/**
* @var LogEntryRepository $logEntryRepository
*/
$logEntryRepository = $em->getRepository('Gedmo\Loggable\Entity\LogEntry');
$documentHistory = $logEntryRepository->getLogEntries($Document);
return $this->render('document/history.html.twig', [
'controller_name' => 'DocumentController',
'document' => $Document,
'history' => $documentHistory,
]);
}
#[Route('/create/{type}', name: 'create')]
#[Route('/create/{type}/directory/{directory?}', name: 'create_directory')]
#[Route('/create/{type}/user/{user?}', name: 'create_user')]
public function create(string $type, Request $request, Directory $directory = null, User $user = null): Response
{
$Document = $this->getDocumentByTypename($type);
if (!$this->IsGranted('create', $Document)) {
throw new AccessDeniedHttpException('granted_not_allowed_creating_document');
}
if (method_exists($Document, 'setDirectory')) {
if (is_null($directory)) {
throw new \Exception('exception_document_need_directory');
}
$Document->setDirectory($directory);
}
if (method_exists($Document, 'setUser')) {
if (is_null($user)) {
throw new \Exception('exception_document_need_user');
}
$Document->setUser($user);
}
$form = $this->getFormByDocumentType($Document);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
/**
* @var User $loggedUser
*/
$loggedUser = $this->getUser();
//check subGroups
//check for subGroups addition and user not in thoses subgroups
foreach ($Document->getAllowedSubGroups() as $key => $subGroup) {
if (
!$loggedUser->getSubGroups()->contains($subGroup)
&& !$loggedUser->hasPermission('group_ignore_subgroups')
) {
$this->addFlash('danger', 'alert_danger_adding_subgroup_document');
$Document->removeAllowedSubGroup($subGroup);
}
}
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($Document);
try {
$entityManager->flush();
} catch (\Throwable $th) {
if ($_ENV['APP_ENV'] === 'dev') {
throw $th; //DEBUG
}
$this->addFlash('danger', 'alert_error_creating_document');
return $this->redirectToRoute($request->getRequestUri());
}
$this->addFlash('success', 'alert_success_creating_document');
return $this->redirectToRoute('document_view', ['id' => $Document->getId()]);
}
return $this->render('document/create.html.twig', [
'controller_name' => 'DocumentController',
'document' => $Document,
'directory' => $directory,
'form' => $form->createView(),
'type' => $type,
]);
}
#[Route('/edit/{id}', name: 'edit')]
#[IsGranted('edit', subject: 'Document', message: 'granted_not_allowed_editing_document')]
public function edit(Request $request, Document $Document): Response
{
$CurrentSubGroupsAlloweds = $Document->getAllowedSubGroups()->toArray();
$form = $this->getFormByDocumentType($Document);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
/**
* @var User $User
*/
$User = $this->getUser();
//check subGroups
//check for missing subGroups
foreach ($CurrentSubGroupsAlloweds as $key => $subGroup) {
if (
!in_array($subGroup, $Document->getAllowedSubGroups()->toArray())
&& !$User->getSubGroups()->contains($subGroup)
&& !$User->hasPermission('group_ignore_subgroups')
) {
$this->addFlash('danger', 'alert_danger_removing_subgroup_document');
$Document->addAllowedSubGroup($subGroup);
}
}
//check for subGroups addition and user not in thoses subgroups
foreach ($Document->getAllowedSubGroups() as $key => $subGroup) {
if (
!in_array($subGroup, $CurrentSubGroupsAlloweds)
&& !$User->getSubGroups()->contains($subGroup)
&& !$User->hasPermission('group_ignore_subgroups')
) {
$this->addFlash('danger', 'alert_danger_adding_subgroup_document');
$Document->removeAllowedSubGroup($subGroup);
}
}
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($Document);
try {
$entityManager->flush();
} catch (\Throwable $th) {
if ($_ENV['APP_ENV'] === 'dev') {
throw $th; //DEBUG
}
$this->addFlash('danger', 'alert_error_editing_document');
return $this->redirectToRoute($request->getRequestUri());
}
$this->addFlash('success', 'alert_success_editing_document');
return $this->redirectToRoute('document_view', ['id' => $Document->getId()]);
}
return $this->render('document/edit.html.twig', [
'controller_name' => 'DocumentController',
'document' => $Document,
'form' => $form->createView()
]);
}
#[Route('/delete/{id}', name: 'delete')]
#[IsGranted('delete', subject: 'Document', message: 'granted_not_allowed_deleting_document')]
public function delete(Document $Document, Request $Request): Response
{
$entityManager = $this->getDoctrine()->getManager();
$entityManager->remove($Document);
try {
$entityManager->flush();
} catch (\Throwable $th) {
if ($_ENV['APP_ENV'] === 'dev') {
throw $th; //DEBUG
}
$this->addFlash('warning', 'alert_error_deleting_document');
if (null != $Request->headers->get('referer')) {
return $this->redirect($Request->headers->get('referer'));
}
return $this->redirectToRoute('document_view', ['id' => $Document->getId()]);
}
$this->addFlash('success', 'alert_success_deleting_document');
/*if (null != $Request->headers->get('referer')) {
return $this->redirect($Request->headers->get('referer'));
}*/ //TODO: fix refere document when deleted (if path return view, send to list)
return $this->redirectToRoute('document_list', ['type' => $Document->getClassShort()]);
}
#[Route('/archives/{type}/{directory?}', name: 'list_archives')]
#[Route('/{type}/{directory?}', name: 'list')]
public function list(
PaginatorInterface $paginator,
Request $request,
DocumentRepository $DocumentRepository,
EntityManagerInterface $EntityManagerInterface,
Directory $directory = null,
string $type
): Response {
$searchForm = $this->createForm(SearchBarType::class);
$searchForm->handleRequest($request);
$documentTypeEntity = $this->getDocumentByTypename($type);
/**
* @var DocumentRepository $DocumentRepository
*/
$DocumentRepository = $EntityManagerInterface->getRepository(get_class($documentTypeEntity));
$archive = ($request->attributes->get('_route') == 'document_list_archives');
$pagination = $paginator->paginate(
$DocumentRepository ->listForUser($this->getUser(), $documentTypeEntity->getIsPublic())
->search((
$searchForm->isSubmitted()
&& $searchForm->isValid()
&& $searchForm->getData()['subject'] !== null
) ? $searchForm->getData()['subject'] : null)
->limitType($type)
->archive($archive)
->order(['createdAt' => 'DESC'])
->limitDirectory($directory)
->getResult(),
$request->query->getInt('page', 1)
);
return $this->render('document/list.html.twig', [
'controller_name' => 'DocumentController',
'pagination' => $pagination,
'count' => $pagination->getTotalItemCount(),
'searchForm' => $searchForm->createView(),
'documentTypeEntity' => $documentTypeEntity,
'type' => $documentTypeEntity->getClassShort(),
'archive' => $archive,
'directory' => $directory
]);
}
private function getFormByDocumentType(Document $Document)
{
if (!is_subclass_of($Document, 'App\Entity\Document')) {
throw new \Exception('exception_invalid_document_type');
}
$type = 'App\Form\\' . ucfirst(strtolower($Document->getClassShort())) . 'Type';
if (!class_exists($type)) {
throw new \Exception('exception_invalid_document_type');
return null;
}
$formtype = new $type($this->TokenStorage);
return $this->createForm(get_class($formtype), $Document);
}
private function getDocumentByTypename(string $type)
{
$type = 'App\Entity\\' . ucfirst(strtolower($type));
if (!class_exists($type)) {
throw new \Exception('exception_invalid_document_type');
return null;
}
$Document = new $type($this->getUser());
if (!is_subclass_of($Document, 'App\Entity\Document')) {
throw new \Exception('exception_invalid_document_type');
}
return $Document ;
}
}

View File

@@ -0,0 +1,205 @@
<?php
namespace App\Controller;
use App\Entity\Folder;
use App\Entity\Document;
use App\Entity\Directory;
use App\Form\SearchBarType;
use App\Repository\DocumentRepository;
use App\Repository\DirectoryRepository;
use Knp\Component\Pager\PaginatorInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
#[Route('/folder/{id}', name: 'folder_')]
class FolderController extends AbstractController
{
#[Route('/directory', name: 'directory')]
#[Route('/directory/wanted', name: 'directory_wanted')]
#[Route('/directory/dead', name: 'directory_dead')]
public function directory(
PaginatorInterface $paginator,
Request $request,
Folder $Folder,
DirectoryRepository $DirectoryRepository
): Response {
$searchForm = $this->createForm(SearchBarType::class);
$searchForm->handleRequest($request);
$req = $DirectoryRepository->list()
->search(
(
$searchForm->isSubmitted()
&& $searchForm->isValid()
&& $searchForm->getData()['subject'] !== null
) ? $searchForm->getData()['subject'] : null
);
if ($request->attributes->get('_route') == 'folder_directory_wanted') {
$req->wanted();
}
if ($request->attributes->get('_route') == 'folder_directory_dead') {
$req->dead();
} else {
$req->notDead();
}
$pagination = $paginator->paginate(
$req->getResult()
);
return $this->render('folder/directory.html.twig', [
'controller_name' => 'FolderController',
'folder' => $Folder,
'pagination' => $pagination,
'searchForm' => $searchForm->createView(),
'wanted' => ($request->attributes->get('_route') == 'folder_directory_wanted'),
'dead' => ($request->attributes->get('_route') == 'folder_directory_dead')
]);
}
#[Route('/directory/add/{Directory}', name: 'directory_add')]
public function directoryAdd(
Request $request,
Folder $Folder,
Directory $Directory
): Response {
$Folder->addDirectory($Directory);
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($Folder);
try {
$entityManager->flush();
} catch (\Throwable $th) {
if ($_ENV['APP_ENV'] === 'dev') {
throw $th; //DEBUG
}
$this->addFlash('danger', 'alert_error_adding_to_folder');
return $this->redirectToRoute($request->getRequestUri());
}
$this->addFlash('success', 'alert_success_adding_to_folder');
return $this->redirectToRoute('document_view', ['id' => $Folder->getId()]);
}
#[Route('/directory/remove/{Directory}', name: 'directory_remove')]
public function directoryRemove(
Request $request,
Folder $Folder,
Directory $Directory
): Response {
$Folder->removeDirectory($Directory);
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($Folder);
try {
$entityManager->flush();
} catch (\Throwable $th) {
if ($_ENV['APP_ENV'] === 'dev') {
throw $th; //DEBUG
}
$this->addFlash('danger', 'alert_error_removing_from_folder');
return $this->redirectToRoute($request->getRequestUri());
}
$this->addFlash('success', 'alert_success_removing_from_folder');
return $this->redirectToRoute('document_view', ['id' => $Folder->getId()]);
}
// Documents
#[Route('/document', name: 'document')]
#[Route('/document/archive', name: 'document_archive')]
public function document(
PaginatorInterface $paginator,
Request $request,
Folder $Folder,
DocumentRepository $DocumentRepository
): Response {
$searchForm = $this->createForm(SearchBarType::class);
$searchForm->handleRequest($request);
$req = $DocumentRepository->list()
->search(
(
$searchForm->isSubmitted()
&& $searchForm->isValid()
&& $searchForm->getData()['subject'] !== null
) ? $searchForm->getData()['subject'] : null
);
if ($request->attributes->get('_route') == 'folder_document_archive') {
$req->archive();
}
$pagination = $paginator->paginate(
$req->getResult()
);
return $this->render('folder/document.html.twig', [
'controller_name' => 'FolderController',
'folder' => $Folder,
'pagination' => $pagination,
'searchForm' => $searchForm->createView(),
'archive' => ($request->attributes->get('_route') == 'folder_document_archive'),
]);
}
#[Route('/document/add/{Document}', name: 'document_add')]
public function documentAdd(
Request $request,
Folder $Folder,
Document $Document
): Response {
$Folder->addDocument($Document);
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($Folder);
try {
$entityManager->flush();
} catch (\Throwable $th) {
if ($_ENV['APP_ENV'] === 'dev') {
throw $th; //DEBUG
}
$this->addFlash('danger', 'alert_error_adding_to_folder');
return $this->redirectToRoute($request->getRequestUri());
}
$this->addFlash('success', 'alert_success_adding_to_folder');
return $this->redirectToRoute('document_view', ['id' => $Folder->getId()]);
}
#[Route('/document/remove/{Document}', name: 'document_remove')]
public function documentRemove(
Request $request,
Folder $Folder,
Document $Document
): Response {
$Folder->removeDocument($Document);
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($Folder);
try {
$entityManager->flush();
} catch (\Throwable $th) {
if ($_ENV['APP_ENV'] === 'dev') {
throw $th; //DEBUG
}
$this->addFlash('danger', 'alert_error_removing_from_folder');
return $this->redirectToRoute($request->getRequestUri());
}
$this->addFlash('success', 'alert_success_removing_from_folder');
return $this->redirectToRoute('document_view', ['id' => $Folder->getId()]);
}
}

View File

@@ -0,0 +1,192 @@
<?php
namespace App\Controller;
use App\Entity\User;
use App\Form\MotdType;
use App\Form\EmployeeType;
use App\Repository\TemplateRepository;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
#[Route('/group', name: 'group_')]
class GroupController extends AbstractController
{
#[Route('/', name: 'index')]
public function index(Request $request, TemplateRepository $TemplateRepository): Response
{
$group = $this->getUser()->getMainGroup();
if (!$this->IsGranted('administrate', $group)) {
throw new AccessDeniedHttpException('granted_not_allowed_administrate_group');
}
$form = $this->createForm(MotdType::class, $group);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
if (!$this->IsGranted('motd', $group)) {
throw new AccessDeniedHttpException('granted_not_allowed_editing_motd_group');
}
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($group);
try {
$entityManager->flush();
$this->addFlash('success', 'alert_success_editing_motd');
} catch (\Throwable $th) {
if ($_ENV['APP_ENV'] === 'dev') {
throw $th; //DEBUG
}
$this->addFlash('danger', 'alert_error_editing_motd');
}
}
return $this->render('group/index.html.twig', [
'controller_name' => 'GroupController',
'formMOTD' => $form->createView(),
'group' => $group,
'templates' => $TemplateRepository->listForUser($this->getUser())->getResult()
]);
}
#[Route('/fire/{id}', name: 'fire')]
public function fire(User $User, Request $Request): Response
{
$group = $this->getUser()->getMainGroup();
if (!$this->IsGranted('fire', $group)) {
throw new AccessDeniedHttpException('granted_not_allowed_fire_employee');
}
/**
* @var User $currentUser
*/
$currentUser = $this->getUser();
if (
$User->getMainRank()->getPower() >= $currentUser->getMainRank()->getPower()
&& !$currentUser->getAdminMode()
) {
$this->addFlash('danger', 'alert_error_cant_fire_superior_or_same_rank');
return $this->redirectToRoute('group_index');
}
$entityManager = $this->getDoctrine()->getManager();
$User->setMainGroup(null);
$User->setMainRank(null);
$entityManager->persist($User);
try {
$entityManager->flush();
} catch (\Throwable $th) {
if ($_ENV['APP_ENV'] === 'dev') {
throw $th; //DEBUG
}
$this->addFlash('danger', 'alert_error_fire_employee');
if (null != $Request->headers->get('referer')) {
return $this->redirect($Request->headers->get('referer'));
}
return $this->redirectToRoute('group_index');
}
$this->addFlash('success', 'alert_success_fire_employee');
if (null != $Request->headers->get('referer')) {
return $this->redirect($Request->headers->get('referer'));
}
return $this->redirectToRoute('group_index');
}
#[Route('/employee/{id}', name: 'employee')]
public function employee(User $Employee, Request $Request): Response
{
$group = $this->getUser()->getMainGroup();
if (!$this->IsGranted('administrate', $group)) {
throw new AccessDeniedHttpException('granted_not_allowed_administrate_group');
}
//check if employee belong to user group
if ($Employee->getMainGroup() != $this->getUser()->getMainGroup()) {
throw new AccessDeniedHttpException('granted_not_allowed_administrate_other_group_employee');
}
$UserActualRank = $Employee->getMainRank();
/**
* @var User $currentUser
*/
$currentUser = $this->getUser();
$form = $this->createForm(EmployeeType::class, $Employee);
$form->handleRequest($Request);
if ($form->isSubmitted() && $form->isValid()) {
//check if rank is modified
if ($UserActualRank != $Employee->getMainRank()) {
if (!$this->IsGranted('rank', $group)) {
$this->addFlash('warning', 'alert_error_editing_employee_rank');
if (null != $Request->headers->get('referer')) {
return $this->redirect($Request->headers->get('referer'));
}
return $this->redirectToRoute('group_employee', ['id' => $Employee->getId()]);
}
if (
$Employee == $currentUser
) {
$this->addFlash('warning', 'alert_error_editing_employee_own_rank');
if (null != $Request->headers->get('referer')) {
return $this->redirect($Request->headers->get('referer'));
}
return $this->redirectToRoute('group_employee', ['id' => $Employee->getId()]);
}
if (
$UserActualRank != null
&& $UserActualRank->getPower() >= $currentUser->getMainRank()->getPower()
&& !$currentUser->getAdminMode()
) {
$this->addFlash('warning', 'alert_error_editing_employee_superior_or_same_rank');
if (null != $Request->headers->get('referer')) {
return $this->redirect($Request->headers->get('referer'));
}
return $this->redirectToRoute('group_employee', ['id' => $Employee->getId()]);
}
if (
$Employee->getMainRank()->getPower() >= $currentUser->getMainRank()->getPower()
&& !$currentUser->getAdminMode()
) {
$this->addFlash('warning', 'alert_error_setting_employee_superior_or_same_rank');
if (null != $Request->headers->get('referer')) {
return $this->redirect($Request->headers->get('referer'));
}
return $this->redirectToRoute('group_employee', ['id' => $Employee->getId()]);
}
}
//end check rank modified
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($Employee);
try {
$entityManager->flush();
$this->addFlash('success', 'alert_success_editing_employee');
} catch (\Throwable $th) {
if ($_ENV['APP_ENV'] === 'dev') {
throw $th; //DEBUG
}
$this->addFlash('danger', 'alert_error_editing_employee');
}
}
return $this->render('group/employee.html.twig', [
'controller_name' => 'GroupController',
'form' => $form->createView(),
'employee' => $Employee
]);
}
}

View File

@@ -0,0 +1,36 @@
<?php
namespace App\Controller;
use App\Repository\DocumentRepository;
use App\Repository\DirectoryRepository;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class HomeController extends AbstractController
{
#[Route('/', name: 'home')]
public function home(
DocumentRepository $DocumentRepository,
DirectoryRepository $DirectoryRepository
): Response {
return $this->render('home/home.html.twig', [
'documents' =>
$DocumentRepository ->listForUser($this->getUser())
->limit(10)
->order(['createdAt' => 'DESC'])
->getResult(),
'announces' =>
$DocumentRepository ->listForUser($this->getUser())
->limitType('announce')
->limit(3)
->order(['createdAt' => 'DESC'])
->getResult(),
'wanted' =>
$DirectoryRepository->list()->notDead()->wanted()->getResult(),
'controller_name' => 'HomeController',
]);
}
}

View File

@@ -0,0 +1,105 @@
<?php
namespace App\Controller;
use App\Form\MeType;
use App\Form\MePasswordType;
use Knp\Component\Pager\PaginatorInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
#[Route('/me', name: 'me_')]
class MeController extends AbstractController
{
private Security $security;
public function __construct(Security $security)
{
$this->security = $security;
}
#[Route('/', name: 'index')]
public function index(PaginatorInterface $paginator, Request $request): Response
{
/**
* @var User $user
*/
$user = $this->security->getUser();
$form = $this->createForm(MeType::class, $user);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($user);
try {
$entityManager->flush();
} catch (\Throwable $th) {
if ($_ENV['APP_ENV'] === 'dev') {
throw $th; //DEBUG
}
$this->addFlash('danger', 'alert_error_editing_profile');
return $this->redirectToRoute($request->getRequestUri());
}
$this->addFlash('success', 'alert_success_editing_profile');
$request->getSession()->set('_locale', $user->getLocale());
return $this->redirectToRoute('me_index');
}
return $this->render('me/index.html.twig', [
'controller_name' => 'MeController',
'form' => $form->createView(),
'pagination' => $paginator->paginate($user->getDocuments())
]);
}
#[Route('/password', name: 'password')]
public function password(Request $request, UserPasswordHasherInterface $passwordEncoder): Response
{
/**
* @var User $user
*/
$user = $this->security->getUser();
$form = $this->createForm(MePasswordType::class, $user);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
// encode the plain password
$user->setPassword(
$passwordEncoder->hashPassword(
$user,
$form->get('plainPassword')->getData()
)
);
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($user);
try {
$entityManager->flush();
} catch (\Throwable $th) {
if ($_ENV['APP_ENV'] === 'dev') {
throw $th; //DEBUG
}
$this->addFlash('danger', 'alert_error_editing_password');
return $this->redirectToRoute($request->getRequestUri());
}
$this->addFlash('success', 'alert_success_editing_password');
$request->getSession()->set('_locale', $user->getLocale());
return $this->redirectToRoute('me_index');
}
return $this->render('me/password.html.twig', [
'controller_name' => 'MeController',
'form' => $form->createView(),
]);
}
}

View File

@@ -0,0 +1,75 @@
<?php
namespace App\Controller;
use App\Entity\Notification;
use App\Repository\NotificationRepository;
use Knp\Component\Pager\PaginatorInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
#[Route('/notification', name: 'notification_')]
class NotificationController extends AbstractController
{
#[Route('/', name: 'list')]
public function list(
PaginatorInterface $paginator,
Request $request,
NotificationRepository $NotificationRepository
): Response {
return $this->render('notification/list.html.twig', [
'controller_name' => 'NotificationController',
'pagination' => $paginator->paginate(
$NotificationRepository->listForUser($this->getUser())
->order(['readed' => 'ASC', 'createdAt' => 'DESC'])
->getResult(),
$request->query->getInt('page', 1)
)
]);
}
#[Route('/delete/{id}', name: 'delete')]
#[IsGranted('delete', subject: 'Notification', message: 'granted_not_allowed_delete_notification')]
public function delete(Notification $Notification, Request $Request): Response
{
$entityManager = $this->getDoctrine()->getManager();
$entityManager->remove($Notification);
try {
$entityManager->flush();
} catch (\Throwable $th) {
if ($_ENV['APP_ENV'] === 'dev') {
throw $th; //DEBUG
}
$this->addFlash('warning', 'alert_error_deleting_notification');
}
if (null != $Request->headers->get('referer')) {
return $this->redirect($Request->headers->get('referer'));
}
return $this->redirectToRoute('notification_list');
}
#[Route('/markread/{id}', name: 'markread')]
#[IsGranted('markread', subject: 'Notification', message: 'granted_not_allowed_markread_notification')]
public function markread(Notification $Notification, Request $Request): Response
{
$entityManager = $this->getDoctrine()->getManager();
$Notification->setReaded(true);
try {
$entityManager->flush();
} catch (\Throwable $th) {
if ($_ENV['APP_ENV'] === 'dev') {
throw $th; //DEBUG
}
$this->addFlash('warning', 'alert_error_markread_notification');
}
if (null != $Request->headers->get('referer')) {
return $this->redirect($Request->headers->get('referer'));
}
return $this->redirectToRoute('notification_list');
}
}

View File

@@ -0,0 +1,176 @@
<?php
namespace App\Controller;
use App\Entity\User;
use App\Form\ChangePasswordFormType;
use App\Form\ResetPasswordRequestFormType;
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use SymfonyCasts\Bundle\ResetPassword\ResetPasswordHelperInterface;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
use SymfonyCasts\Bundle\ResetPassword\Controller\ResetPasswordControllerTrait;
use SymfonyCasts\Bundle\ResetPassword\Exception\ResetPasswordExceptionInterface;
#[Route('/reset-password')]
class ResetPasswordController extends AbstractController
{
use ResetPasswordControllerTrait;
private ResetPasswordHelperInterface $resetPasswordHelper;
private TranslatorInterface $translator;
public function __construct(ResetPasswordHelperInterface $resetPasswordHelper, TranslatorInterface $translator)
{
$this->resetPasswordHelper = $resetPasswordHelper;
$this->translator = $translator;
}
/**
* Display & process form to request a password reset.
*/
#[Route('', name: 'app_forgot_password_request')]
public function request(Request $request, MailerInterface $mailer): Response
{
$form = $this->createForm(ResetPasswordRequestFormType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
return $this->processSendingPasswordResetEmail(
$form->get('email')->getData(),
$mailer
);
}
return $this->render('reset_password/request.html.twig', [
'requestForm' => $form->createView(),
]);
}
/**
* Confirmation page after a user has requested a password reset.
*/
#[Route('/check-email', name: 'app_check_email')]
public function checkEmail(): Response
{
// Generate a fake token if the user does not exist or someone hit this page directly.
// This prevents exposing whether or not a user was found with the given email address or not
if (null === ($resetToken = $this->getTokenObjectFromSession())) {
$resetToken = $this->resetPasswordHelper->generateFakeResetToken();
}
return $this->render('reset_password/check_email.html.twig', [
'resetToken' => $resetToken,
]);
}
/**
* Validates and process the reset URL that the user clicked in their email.
*/
#[Route('/reset/{token}', name: 'app_reset_password')]
public function reset(Request $request, UserPasswordHasherInterface $passEncod, string $token = null): Response
{
if ($token) {
// We store the token in session and remove it from the URL, to avoid the URL being
// loaded in a browser and potentially leaking the token to 3rd party JavaScript.
$this->storeTokenInSession($token);
return $this->redirectToRoute('app_reset_password');
}
$token = $this->getTokenFromSession();
if (null === $token) {
//No reset password token found in the URL or in the session.
throw $this->createNotFoundException('exception_no_reset_token_found');
}
try {
$user = $this->resetPasswordHelper->validateTokenAndFetchUser($token);
} catch (ResetPasswordExceptionInterface $e) {
//There was a problem validating your reset request
$this->addFlash(
'reset_password_error',
'alert_error_problem_validating_reset_request'
);
return $this->redirectToRoute('app_forgot_password_request');
}
// The token is valid; allow the user to change their password.
$form = $this->createForm(ChangePasswordFormType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
// A password reset token should be used only once, remove it.
$this->resetPasswordHelper->removeResetRequest($token);
// Encode the plain password, and set it.
$encodedPassword = $passEncod->hashPassword(
$user,
$form->get('plainPassword')->getData()
);
$user->setPassword($encodedPassword);
$this->getDoctrine()->getManager()->flush();
// The session is cleaned up after the password has been changed.
$this->cleanSessionAfterReset();
$this->addFlash('success', 'alert_success_resetting_password');
return $this->redirectToRoute('home');
}
return $this->render('reset_password/reset.html.twig', [
'resetForm' => $form->createView(),
]);
}
private function processSendingPasswordResetEmail(string $emailFormData, MailerInterface $mailer): RedirectResponse
{
$user = $this->getDoctrine()->getRepository(User::class)->findOneBy([
'email' => $emailFormData,
]);
// Do not reveal whether a user account was found or not.
if (!$user) {
return $this->redirectToRoute('app_check_email');
}
try {
$resetToken = $this->resetPasswordHelper->generateResetToken($user);
} catch (ResetPasswordExceptionInterface $e) {
// If you want to tell the user why a reset email was not sent, uncomment
// the lines below and change the redirect to 'app_forgot_password_request'.
// Caution: This may reveal if a user is registered or not.
//
// $this->addFlash('reset_password_error', sprintf(
// 'There was a problem handling your password reset request - %s',
// $e->getReason()
// ));
return $this->redirectToRoute('app_check_email');
}
$email = (new TemplatedEmail())
//->from(new Address('noreply@vision.com', 'Vision'))
->to($user->getEmail())
->subject($this->translator->trans('email_title_password_reset_request'))
->htmlTemplate('_emails/resetpassword.html.twig')
->context([
'resetToken' => $resetToken,
])
;
$mailer->send($email);
// Store the token object in session for retrieval in check-email route.
$this->setTokenObjectInSession($resetToken);
return $this->redirectToRoute('app_check_email');
}
}

View File

@@ -0,0 +1,141 @@
<?php
namespace App\Controller;
use App\Entity\User;
use App\Form\AuthenticateType;
use App\Security\EmailVerifier;
use App\Form\RegistrationFormType;
use App\Repository\UserRepository;
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
use SymfonyCasts\Bundle\VerifyEmail\Exception\VerifyEmailExceptionInterface;
class SecurityController extends AbstractController
{
private EmailVerifier $emailVerifier;
private TranslatorInterface $translator;
public function __construct(EmailVerifier $emailVerifier, TranslatorInterface $translator)
{
$this->emailVerifier = $emailVerifier;
$this->translator = $translator;
}
#[Route('/register', name: 'app_register')]
public function register(Request $request, UserPasswordHasherInterface $passwordEncoder): Response
{
if ($this->getUser()) {
return $this->redirectToRoute('home');
}
$user = new User();
$user->setLocale($this->getParameter('kernel.default_locale'));
$form = $this->createForm(RegistrationFormType::class, $user);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
// encode the plain password
$user->setPassword(
$passwordEncoder->hashPassword(
$user,
$form->get('plainPassword')->getData()
)
);
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($user);
$entityManager->flush();
// generate a signed url and email it to the user
$this->emailVerifier->sendEmailConfirmation(
'app_verify_email',
$user,
(new TemplatedEmail())
//->from(new Address('noreply@vision.com', 'Vision'))
->to($user->getEmail())
->subject($this->translator->trans('email_title_confirm_email'))
->htmlTemplate('_emails/register.html.twig')
);
$this->addFlash('success', 'alert_success_check_mailbox_validate_account');
return $this->redirectToRoute('home');
}
return $this->render('security/register.html.twig', [
'form' => $form->createView(),
]);
}
#[Route('/verify/email', name: 'app_verify_email')]
public function verifyUserEmail(Request $request, UserRepository $userRepository): Response
{
$id = $request->get('id');
if (null === $id) {
return $this->redirectToRoute('app_register');
}
$user = $userRepository->find($id);
if (null === $user) {
return $this->redirectToRoute('app_register');
}
// validate email confirmation link, sets User::isVerified=true and persists
try {
$this->emailVerifier->handleEmailConfirmation($request, $user);
} catch (VerifyEmailExceptionInterface $exception) {
$this->addFlash('verify_email_error', $exception->getReason());
return $this->redirectToRoute('app_register');
}
$this->addFlash('success', 'alert_success_email_verified');
return $this->redirectToRoute('app_login');
}
/**
* @Route("/login", name="app_login")
*/
public function login(AuthenticationUtils $authenticationUtils): Response
{
if ($this->getUser()) {
return $this->redirectToRoute('home');
}
$form = $this->createForm(AuthenticateType::class);
// 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,
'form' => $form->createView()
]
);
}
/**
* @Route("/logout", name="app_logout")
*/
public function logout()
{
throw new \LogicException('Something goes wrong if you see this');
}
}

View File

@@ -0,0 +1,27 @@
<?php
namespace App\Controller;
use App\Entity\Document;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
class ShareController extends AbstractController
{
#[Route('/share/{share}', name: 'share')]
public function share(Document $Document): Response
{
if (!$Document->getAllowShare()) {
throw new AccessDeniedHttpException('granted_not_allowed_viewing_document');
}
return $this->render('document/view.html.twig', [
'controller_name' => 'DocumentController',
'document' => $Document,
'shared' => true
]);
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace App\Controller;
use App\Entity\Template;
use App\Repository\TemplateRepository;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
#[Route('/template', name: 'template_')]
class TemplateController extends AbstractController
{
/** Class by Aurel **/
#[Route('/json/list', name: 'json_list')]
public function templateJsonList(TemplateRepository $TemplateRepository): Response
{
/**
* @var Array $templates
*/
$templates = $TemplateRepository->listForUser($this->getUser())->getResult();
$json = [];
foreach ($templates as $template) {
array_push($json, [
'title' => $template->getTitle(),
'description' => '',
'url' => $this->generateUrl('template_json_get', ['id' => $template->getId()])
]);
}
return $this->json($json);
}
#[Route('/json/{id}', name: 'json_get')]
public function templateJsonGet(Template $template): Response
{
return new Response($template->getContent());
}
}

View File

@@ -0,0 +1,79 @@
<?php
namespace App\Controller;
use App\Entity\User;
use App\Form\SearchBarType;
use App\Repository\UserRepository;
use Knp\Component\Pager\PaginatorInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
#[Route('/user', name: 'user_')]
class UserController extends AbstractController
{
#[Route('/', name: 'list')]
public function list(PaginatorInterface $paginator, Request $request, UserRepository $UserRepository): Response
{
$searchForm = $this->createForm(SearchBarType::class);
$searchForm->handleRequest($request);
$pagination = $paginator->paginate(
$UserRepository->getAll()
->search(
(
$searchForm->isSubmitted()
&& $searchForm->isValid()
&& $searchForm->getData()['subject'] !== null
) ? $searchForm->getData()['subject'] : null
)
->onlyValid()
->getResult(),
$request->query->getInt('page', 1)
);
return $this->render('user/list.html.twig', [
'controller_name' => 'UserController',
'pagination' => $pagination,
'searchForm' => $searchForm->createView()
]);
}
#[Route('/view/{id}', name: 'view')]
public function view(User $User): Response
{
return $this->render('user/view.html.twig', [
'controller_name' => 'UserController',
'user' => $User
]);
}
#[Route('/view/{id}/sanctions', name: 'view_sanctions')]
public function viewSanctions(PaginatorInterface $paginator, User $User): Response
{
$group = $this->getUser()->getMainGroup();
if (!$this->IsGranted('sanction', $group)) {
throw new AccessDeniedHttpException("granted_not_allowed_to_view_sanctions");
}
$pagination = $paginator->paginate($User->getSanctions());
return $this->render('user/sanctions.html.twig', [
'controller_name' => 'UserController',
'user' => $User,
'pagination' => $pagination
]);
}
#[Route('/view/{id}/documents', name: 'view_documents')]
public function viewDocuments(PaginatorInterface $paginator, User $User): Response
{
$pagination = $paginator->paginate($User->getDocuments());
return $this->render('user/documents.html.twig', [
'controller_name' => 'UserController',
'user' => $User,
'pagination' => $pagination
]);
}
}

View File

@@ -0,0 +1,17 @@
<?php
namespace App\DataFixtures;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;
class AppFixtures extends Fixture
{
public function load(ObjectManager $manager): void
{
// $product = new Product();
// $manager->persist($product);
$manager->flush();
}
}

115
src/DataFixtures/Groups.php Normal file
View File

@@ -0,0 +1,115 @@
<?php
namespace App\DataFixtures;
use App\Entity\Group;
use App\Entity\Rank;
use App\Entity\SubGroup;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;
class Groups extends Fixture
{
public function load(ObjectManager $manager): void
{
$groups = [
[
'name' => 'Los Santos Police Department',
'shortname' => 'LSPD',
'ranks' => [
[
'name' => 'Captain',
'shortname' => 'Cpt',
'power' => 999
],
[
'name' => 'Officer',
'shortname' => 'Off',
'power' => 111
],
],
'subgroups' => [
[
'name' => 'Detective Unit',
'shortname' => 'DU'
],
[
'name' => 'Speed Unit',
'shortname' => 'SU'
],
],
],
[
'name' => 'Department of Justice',
'shortname' => 'DOJ',
'ranks' => [
[
'name' => 'Judge',
'shortname' => 'Judge',
'power' => 999
],
[
'name' => 'Attorney',
'shortname' => 'Att',
'power' => 888
],
],
],
[
'name' => 'Emergency Medical Services',
'shortname' => 'EMS',
'ranks' => [
[
'name' => 'Director',
'shortname' => 'Dir',
'power' => 999
],
[
'name' => 'Doctor',
'shortname' => 'Doc',
'power' => 888
],
],
'subgroups' => [
[
'name' => 'Psychology',
'shortname' => 'PSY'
],
[
'name' => 'legal unit',
'shortname' => 'LEG'
],
],
],
];
foreach ($groups as $key => $group) {
$NewGroup = new Group();
$NewGroup->setName($group['name']);
$NewGroup->setShortName($group['shortname']);
foreach ($group['ranks'] as $key => $rank) {
$newRank = new Rank();
$newRank->setName($rank['name']);
$newRank->setShortName($rank['shortname']);
$newRank->setPower($rank['power']);
$manager->persist($newRank);
$NewGroup->addRank($newRank);
}
foreach ($group['subgroups'] as $key => $subGroup) {
$newSubGroup = new SubGroup();
$newSubGroup->setName($subGroup['name']);
$newSubGroup->setShortName($subGroup['shortname']);
$manager->persist($newSubGroup);
$NewGroup->addSubGroup($newSubGroup);
}
$manager->persist($NewGroup);
}
$manager->flush();
}
}

0
src/Entity/.gitignore vendored Normal file
View File

32
src/Entity/Announce.php Normal file
View File

@@ -0,0 +1,32 @@
<?php
namespace App\Entity;
use App\Entity\Document;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\AnnounceRepository;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @ORM\Entity(repositoryClass=AnnounceRepository::class)
*/
class Announce extends Document
{
/**
* @ORM\Column(type="text")
* @Gedmo\Versioned
*/
private $content;
public function getContent(): ?string
{
return $this->content;
}
public function setContent(string $content): self
{
$this->content = $content;
return $this;
}
}

58
src/Entity/Bracelet.php Normal file
View File

@@ -0,0 +1,58 @@
<?php
namespace App\Entity;
use DateTimeImmutable;
use App\Entity\Document;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\BraceletRepository;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @ORM\Entity(repositoryClass=BraceletRepository::class)
*/
class Bracelet extends Document
{
/**
* @ORM\ManyToOne(targetEntity=Directory::class, inversedBy="bracelets")
* @ORM\JoinColumn(nullable=false)
*/
private $directory;
/**
* @ORM\Column(type="datetime_immutable")
* @Gedmo\Versioned
*/
private $removingDate;
public function __construct(User $user)
{
parent::__construct($user);
$this->setNeedLegalAccess(true);
$this->setRemovingDate(new DateTimeImmutable());
}
public function getDirectory(): ?Directory
{
return $this->directory;
}
public function setDirectory(?Directory $directory): self
{
$this->directory = $directory;
return $this;
}
public function getRemovingDate(): ?\DateTimeImmutable
{
return $this->removingDate;
}
public function setRemovingDate(\DateTimeImmutable $removingDate): self
{
$this->removingDate = $removingDate;
return $this;
}
}

View File

@@ -0,0 +1,49 @@
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use App\Repository\CertificateRepository;
/**
* @ORM\Entity(repositoryClass=CertificateRepository::class)
*/
class Certificate extends Document
{
/**
* @ORM\Column(type="text")
* @Gedmo\Versioned
*/
private $content;
/**
* @ORM\ManyToOne(targetEntity=Directory::class, inversedBy="certificates")
* @ORM\JoinColumn(nullable=false)
*/
private $directory;
public function getContent(): ?string
{
return $this->content;
}
public function setContent(string $content): self
{
$this->content = $content;
return $this;
}
public function getDirectory(): ?Directory
{
return $this->directory;
}
public function setDirectory(?Directory $directory): self
{
$this->directory = $directory;
return $this;
}
}

124
src/Entity/Comment.php Normal file
View File

@@ -0,0 +1,124 @@
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\CommentRepository;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @ORM\Entity(repositoryClass=CommentRepository::class)
* @Gedmo\Loggable
*/
class Comment
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="text")
* @Gedmo\Versioned
*/
private $content;
/**
* @ORM\ManyToOne(targetEntity=Document::class, inversedBy="comments")
* @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
*/
private $document;
/**
* @ORM\Column(type="datetime_immutable")
* @Gedmo\Timestampable(on="create")
*/
private $createdAt;
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="comments")
* @ORM\JoinColumn(nullable=false)
*/
private $creator;
/**
* @ORM\ManyToOne(targetEntity=Group::class, inversedBy="comments")
* @ORM\JoinColumn(nullable=false)
*/
private $mainGroup;
public function __construct(User $user = null)
{
if ($user != null) {
$this->setCreator($user);
$this->setMainGroup($user->getMainGroup());
}
}
public function getId(): ?int
{
return $this->id;
}
public function getContent(): ?string
{
return $this->content;
}
public function setContent(string $content): self
{
$this->content = $content;
return $this;
}
public function getDocument(): ?Document
{
return $this->document;
}
public function setDocument(?Document $document): self
{
$this->document = $document;
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeImmutable $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getCreator(): ?User
{
return $this->creator;
}
public function setCreator(?User $creator): self
{
$this->creator = $creator;
return $this;
}
public function getMainGroup(): ?Group
{
return $this->mainGroup;
}
public function setMainGroup(?Group $mainGroup): self
{
$this->mainGroup = $mainGroup;
return $this;
}
}

91
src/Entity/Complaint.php Normal file
View File

@@ -0,0 +1,91 @@
<?php
namespace App\Entity;
use App\Entity\Document;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use App\Repository\ComplaintRepository;
/**
* @ORM\Entity(repositoryClass=ComplaintRepository::class)
*/
class Complaint extends Document
{
/**
* @ORM\ManyToOne(targetEntity=Directory::class, inversedBy="complaints")
* @ORM\JoinColumn(nullable=false)
*/
private $directory;
/**
* @ORM\Column(type="text")
* @Gedmo\Versioned
*/
private $content;
/**
* @ORM\Column(type="string", length=255)
* @Gedmo\Versioned
*/
private $versus;
/**
* @ORM\Column(type="string", length=255)
* @Gedmo\Versioned
*/
private $status;
public function __construct(User $user)
{
parent::__construct($user);
$this->setNeedLegalAccess(true);
}
public function getDirectory(): ?Directory
{
return $this->directory;
}
public function setDirectory(?Directory $directory): self
{
$this->directory = $directory;
return $this;
}
public function getContent(): ?string
{
return $this->content;
}
public function setContent(string $content): self
{
$this->content = $content;
return $this;
}
public function getVersus(): ?string
{
return $this->versus;
}
public function setVersus(string $versus): self
{
$this->versus = $versus;
return $this;
}
public function getStatus(): ?string
{
return $this->status;
}
public function setStatus(string $status): self
{
$this->status = $status;
return $this;
}
}

128
src/Entity/Criminal.php Normal file
View File

@@ -0,0 +1,128 @@
<?php
namespace App\Entity;
use App\Entity\Document;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\CriminalRepository;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @ORM\Entity(repositoryClass=CriminalRepository::class)
*/
class Criminal extends Document
{
/**
* @ORM\ManyToOne(targetEntity=Directory::class, inversedBy="criminals")
* @ORM\JoinColumn(nullable=false)
*/
private $directory;
/**
* @ORM\Column(type="string", length=255)
* @Gedmo\Versioned
*/
private $article;
/**
* @ORM\Column(type="float", nullable=true)
* @Gedmo\Versioned
*/
private $amountMoney;
/**
* @ORM\Column(type="integer", nullable=true)
* @Gedmo\Versioned
*/
private $amountTime;
/**
* @ORM\Column(type="text", nullable=true)
* @Gedmo\Versioned
*/
private $content;
/**
* @ORM\Column(type="text", nullable=true)
* @Gedmo\Versioned
*/
private $accessorySentence;
public function __construct(User $user)
{
parent::__construct($user);
$this->setNeedLegalAccess(true);
}
public function getDirectory(): ?Directory
{
return $this->directory;
}
public function setDirectory(?Directory $directory): self
{
$this->directory = $directory;
return $this;
}
public function getArticle(): ?string
{
return $this->article;
}
public function setArticle(string $article): self
{
$this->article = $article;
return $this;
}
public function getAmountMoney(): ?float
{
return $this->amountMoney;
}
public function setAmountMoney(?float $amountMoney): self
{
$this->amountMoney = $amountMoney;
return $this;
}
public function getAmountTime(): ?int
{
return $this->amountTime;
}
public function setAmountTime(?int $amountTime): self
{
$this->amountTime = $amountTime;
return $this;
}
public function getContent(): ?string
{
return $this->content;
}
public function setContent(?string $content): self
{
$this->content = $content;
return $this;
}
public function getAccessorySentence(): ?string
{
return $this->accessorySentence;
}
public function setAccessorySentence(?string $accessorySentence): self
{
$this->accessorySentence = $accessorySentence;
return $this;
}
}

1441
src/Entity/Directory.php Normal file

File diff suppressed because it is too large Load Diff

385
src/Entity/Document.php Normal file
View File

@@ -0,0 +1,385 @@
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\DocumentRepository;
use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @ORM\Entity(repositoryClass=DocumentRepository::class)
* @ORM\InheritanceType("JOINED")
* @Gedmo\Loggable
*/
class Document
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="documents")
* @ORM\JoinColumn(nullable=false)
*/
private $creator;
/**
* @ORM\ManyToOne(targetEntity=Group::class, inversedBy="documents")
* @ORM\JoinColumn(nullable=false)
*/
private $mainGroup;
/**
* @ORM\Column(type="datetime_immutable")
* @Gedmo\Timestampable(on="create")
*/
private $createdAt;
/**
* @ORM\Column(type="string", length=255)
* @Gedmo\Versioned
*/
private $share;
/**
* @Gedmo\Versioned
* @ORM\Column(type="string", length=255)
*/
private $title;
/**
* @ORM\ManyToMany(targetEntity=Group::class, inversedBy="allowedDocuments")
*/
private $allowedGroups;
/**
* @Gedmo\Versioned
* @ORM\Column(type="boolean", options={"default":"0"})
*/
private $allowShare = false;
/**
* @ORM\OneToMany(targetEntity=Comment::class, mappedBy="document")
*/
private $comments;
/**
* @ORM\Column(type="boolean", options={"default":"0"})
* @Gedmo\Versioned
*/
private $archive = false;
/**
* True if legal Access is needed
* @ORM\Column(type="boolean", options={"default":"0"})
*/
private $needLegalAccess = false;
/**
* True if medical Access is needed
* @ORM\Column(type="boolean", options={"default":"0"})
*/
private $needMedicalAccess = false;
/**
* True if Group Administration Access is needed
* @ORM\Column(type="boolean", options={"default":"0"})
*/
private $needGroupAdministration = false;
/**
* True if document is public to all groups who have "gang" access
* @ORM\Column(type="boolean", options={"default":"0"})
*/
private $isPublic = false;
/**
* @ORM\ManyToMany(targetEntity=Folder::class, mappedBy="documents")
*/
private $folders;
/**
* @ORM\ManyToMany(targetEntity=SubGroup::class, inversedBy="documents")
*/
private $allowedSubGroups;
public function __construct(User $user)
{
$this->allowedGroups = new ArrayCollection();
$this->share = uniqid();
$this->setCreator($user);
$this->setMainGroup($user->getMainGroup());
$this->addAllowedGroup($this->getMainGroup());
$this->comments = new ArrayCollection();
$this->folders = new ArrayCollection();
$this->allowedSubGroups = new ArrayCollection();
}
public function getClass(): ?string
{
return get_class($this);
}
public function getClassShort(): ?string
{
if ($pos = strrpos($this->getClass(), '\\')) {
return substr($this->getClass(), $pos + 1);
}
return $pos;
}
public function getId(): ?int
{
return $this->id;
}
public function getCreator(): ?User
{
return $this->creator;
}
public function setCreator(?User $creator): self
{
$this->creator = $creator;
return $this;
}
public function getMainGroup(): ?Group
{
return $this->mainGroup;
}
public function setMainGroup(?Group $mainGroup): self
{
$this->mainGroup = $mainGroup;
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeImmutable $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getShare(): ?string
{
return $this->share;
}
public function setShare(string $share): self
{
$this->share = $share;
return $this;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): self
{
$this->title = $title;
return $this;
}
/**
* @return Collection|Group[]
*/
public function getAllowedGroups(): Collection
{
if (!$this->allowedGroups->contains($this->getMainGroup())) {
$this->allowedGroups[] = $this->getMainGroup();
}
return $this->allowedGroups;
}
public function addAllowedGroup(Group $allowedGroup): self
{
if (!$this->allowedGroups->contains($allowedGroup)) {
$this->allowedGroups[] = $allowedGroup;
}
return $this;
}
public function removeAllowedGroup(Group $allowedGroup): self
{
$this->allowedGroups->removeElement($allowedGroup);
return $this;
}
public function getAllowShare(): ?bool
{
return $this->allowShare;
}
public function setAllowShare(bool $allowShare): self
{
$this->allowShare = $allowShare;
return $this;
}
/**
* @return Collection|Comment[]
*/
public function getComments(): Collection
{
return $this->comments;
}
public function addComment(Comment $comment): self
{
if (!$this->comments->contains($comment)) {
$this->comments[] = $comment;
$comment->setDocument($this);
}
return $this;
}
public function removeComment(Comment $comment): self
{
if ($this->comments->removeElement($comment)) {
// set the owning side to null (unless already changed)
if ($comment->getDocument() === $this) {
$comment->setDocument(null);
}
}
return $this;
}
public function getArchive(): ?bool
{
return $this->archive;
}
public function setArchive(bool $archive): self
{
$this->archive = $archive;
return $this;
}
public function getNeedLegalAccess(): ?bool
{
return $this->needLegalAccess;
}
public function setNeedLegalAccess(bool $needLegalAccess): self
{
$this->needLegalAccess = $needLegalAccess;
return $this;
}
public function getNeedMedicalAccess(): ?bool
{
return $this->needMedicalAccess;
}
public function setNeedMedicalAccess(bool $needMedicalAccess): self
{
$this->needMedicalAccess = $needMedicalAccess;
return $this;
}
public function getNeedGroupAdministration(): ?bool
{
return $this->needGroupAdministration;
}
public function setNeedGroupAdministration(bool $needGroupAdministration): self
{
$this->needGroupAdministration = $needGroupAdministration;
return $this;
}
public function getIsPublic(): ?bool
{
return $this->isPublic;
}
public function setIsPublic(bool $isPublic): self
{
$this->isPublic = $isPublic;
return $this;
}
/**
* @return Collection|Folder[]
*/
public function getFolders(): Collection
{
return $this->folders;
}
public function addFolder(Folder $folder): self
{
if (!$this->folders->contains($folder)) {
$this->folders[] = $folder;
$folder->addDocument($this);
}
return $this;
}
public function removeFolder(Folder $folder): self
{
if ($this->folders->removeElement($folder)) {
$folder->removeDocument($this);
}
return $this;
}
/**
* @return Collection|SubGroup[]
*/
public function getAllowedSubGroups(): Collection
{
return $this->allowedSubGroups;
}
public function addAllowedSubGroup(SubGroup $allowedSubGroup): self
{
if (!$this->allowedSubGroups->contains($allowedSubGroup)) {
$this->allowedSubGroups[] = $allowedSubGroup;
}
return $this;
}
public function removeAllowedSubGroup(SubGroup $allowedSubGroup): self
{
$this->allowedSubGroups->removeElement($allowedSubGroup);
return $this;
}
}

99
src/Entity/Folder.php Normal file
View File

@@ -0,0 +1,99 @@
<?php
namespace App\Entity;
use App\Entity\Document;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\FolderRepository;
use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @ORM\Entity(repositoryClass=FolderRepository::class)
*/
class Folder extends Document
{
/**
* @ORM\Column(type="text", nullable=true)
* @Gedmo\Versioned
*/
private $content;
/**
* @ORM\ManyToMany(targetEntity=Directory::class, inversedBy="folders")
*/
private $directories;
/**
* @ORM\ManyToMany(targetEntity=Document::class, inversedBy="folders")
*/
private $documents;
public function __construct(User $user)
{
parent::__construct($user);
$this->directories = new ArrayCollection();
$this->documents = new ArrayCollection();
}
public function getContent(): ?string
{
return $this->content;
}
public function setContent(string $content): self
{
$this->content = $content;
return $this;
}
/**
* @return Collection|Directory[]
*/
public function getDirectories(): Collection
{
return $this->directories;
}
public function addDirectory(Directory $directory): self
{
if (!$this->directories->contains($directory)) {
$this->directories[] = $directory;
}
return $this;
}
public function removeDirectory(Directory $directory): self
{
$this->directories->removeElement($directory);
return $this;
}
/**
* @return Collection|Document[]
*/
public function getDocuments(): Collection
{
return $this->documents;
}
public function addDocument(Document $document): self
{
if (!$this->documents->contains($document)) {
$this->documents[] = $document;
}
return $this;
}
public function removeDocument(Document $document): self
{
$this->documents->removeElement($document);
return $this;
}
}

77
src/Entity/Gang.php Normal file
View File

@@ -0,0 +1,77 @@
<?php
namespace App\Entity;
use App\Entity\Document;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\GangRepository;
use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @ORM\Entity(repositoryClass=GangRepository::class)
*/
class Gang extends Document
{
public function __construct(User $user)
{
parent::__construct($user);
$this->setNeedLegalAccess(true);
$this->setIsPublic(true);
$this->directories = new ArrayCollection();
}
/**
* @ORM\Column(type="text", nullable=true)
* @Gedmo\Versioned
*/
private $content;
/**
* @ORM\OneToMany(targetEntity=Directory::class, mappedBy="gang")
*/
private $directories;
public function getContent(): ?string
{
return $this->content;
}
public function setContent(?string $content): self
{
$this->content = $content;
return $this;
}
/**
* @return Collection|Directory[]
*/
public function getDirectories(): Collection
{
return $this->directories;
}
public function addDirectory(Directory $directory): self
{
if (!$this->directories->contains($directory)) {
$this->directories[] = $directory;
$directory->setGang($this);
}
return $this;
}
public function removeDirectory(Directory $directory): self
{
if ($this->directories->removeElement($directory)) {
// set the owning side to null (unless already changed)
if ($directory->getGang() === $this) {
$directory->setGang(null);
}
}
return $this;
}
}

420
src/Entity/Group.php Normal file
View File

@@ -0,0 +1,420 @@
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\GroupRepository;
use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\Common\Collections\Collection;
use Symfony\Component\HttpFoundation\File\File;
use Doctrine\Common\Collections\ArrayCollection;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* @ORM\Entity(repositoryClass=GroupRepository::class)
* @ORM\Table(name="`group`")
* @Vich\Uploadable
* @Gedmo\Loggable
*/
class Group
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
* @Gedmo\Versioned
*/
private $name;
/**
* @ORM\Column(type="datetime_immutable")
* @Gedmo\Timestampable(on="create")
*/
private $createdAt;
/**
* @ORM\OneToMany(targetEntity=Document::class, mappedBy="mainGroup")
*/
private $documents;
/**
* @ORM\OneToMany(targetEntity=User::class, mappedBy="mainGroup")
*/
private $users;
/**
* @ORM\OneToMany(targetEntity=Rank::class, mappedBy="mainGroup")
*/
private $ranks;
/**
* @ORM\ManyToMany(targetEntity=Document::class, mappedBy="allowedGroups")
*/
private $allowedDocuments;
/**
* @ORM\Column(type="string", length=12)
* @Gedmo\Versioned
*/
private $shortName;
/**
* @ORM\OneToMany(targetEntity=Comment::class, mappedBy="mainGroup")
*/
private $comments;
/**
* @ORM\Column(type="text", nullable=true)
* @Gedmo\Versioned
*/
private $motd;
/**
* @ORM\Column(type="datetime_immutable", nullable=true)
* @Gedmo\Timestampable(on="change", field={"motd"})
*/
private $motdUpdatedAt;
/**
* @Vich\UploadableField(mapping="group_logo", fileNameProperty="imageName", size="imageSize")
*
* @var File|null
*
*/
private $imageFile;
/**
* @ORM\Column(type="string", nullable=true)
* @Gedmo\Versioned
*
* @var string|null
*/
private $imageName;
/**
* @ORM\Column(type="integer", nullable=true)
*
* @var int|null
*/
private $imageSize;
/**
* @ORM\Column(type="datetime_immutable")
* @Gedmo\Timestampable(on="update")
*/
private $updatedAt;
/**
* @ORM\OneToMany(targetEntity=SubGroup::class, mappedBy="mainGroup", orphanRemoval=true)
*/
private $subGroups;
public function __construct()
{
$this->documents = new ArrayCollection();
$this->users = new ArrayCollection();
$this->ranks = new ArrayCollection();
$this->allowedDocuments = new ArrayCollection();
$this->comments = new ArrayCollection();
$this->subGroups = new ArrayCollection();
}
/**
*
* @param File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $imageFile
*/
public function setImageFile(?File $imageFile = null): void
{
$this->imageFile = $imageFile;
if (null !== $imageFile) {
// It is required that at least one field changes if you are using doctrine
// otherwise the event listeners won't be called and the file is lost
$this->updatedAt = new \DateTimeImmutable();
}
}
public function getImageFile(): ?File
{
return $this->imageFile;
}
public function setImageName(?string $imageName): void
{
$this->imageName = $imageName;
}
public function getImageName(): ?string
{
return $this->imageName;
}
public function setImageSize(?int $imageSize): void
{
$this->imageSize = $imageSize;
}
public function getImageSize(): ?int
{
return $this->imageSize;
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeImmutable $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
/**
* @return Collection|Document[]
*/
public function getDocuments(): Collection
{
return $this->documents;
}
public function addDocument(Document $document): self
{
if (!$this->documents->contains($document)) {
$this->documents[] = $document;
$document->setMainGroup($this);
}
return $this;
}
public function removeDocument(Document $document): self
{
if ($this->documents->removeElement($document)) {
// set the owning side to null (unless already changed)
if ($document->getMainGroup() === $this) {
$document->setMainGroup(null);
}
}
return $this;
}
/**
* @return Collection|User[]
*/
public function getUsers(): Collection
{
return $this->users;
}
public function addUser(User $user): self
{
if (!$this->users->contains($user)) {
$this->users[] = $user;
$user->setMainGroup($this);
}
return $this;
}
public function removeUser(User $user): self
{
if ($this->users->removeElement($user)) {
// set the owning side to null (unless already changed)
if ($user->getMainGroup() === $this) {
$user->setMainGroup(null);
}
}
return $this;
}
/**
* @return Collection|Rank[]
*/
public function getRanks(): Collection
{
return $this->ranks;
}
public function addRank(Rank $rank): self
{
if (!$this->ranks->contains($rank)) {
$this->ranks[] = $rank;
$rank->setMainGroup($this);
}
return $this;
}
public function removeRank(Rank $rank): self
{
if ($this->ranks->removeElement($rank)) {
// set the owning side to null (unless already changed)
if ($rank->getMainGroup() === $this) {
$rank->setMainGroup(null);
}
}
return $this;
}
/**
* @return Collection|Document[]
*/
public function getAllowedDocuments(): Collection
{
return $this->allowedDocuments;
}
public function addAllowedDocument(Document $allowedDocument): self
{
if (!$this->allowedDocuments->contains($allowedDocument)) {
$this->allowedDocuments[] = $allowedDocument;
$allowedDocument->addAllowedGroup($this);
}
return $this;
}
public function removeAllowedDocument(Document $allowedDocument): self
{
if ($this->allowedDocuments->removeElement($allowedDocument)) {
$allowedDocument->removeAllowedGroup($this);
}
return $this;
}
public function getShortName(): ?string
{
return $this->shortName;
}
public function setShortName(?string $shortName): self
{
$this->shortName = $shortName;
return $this;
}
/**
* @return Collection|Comment[]
*/
public function getComments(): Collection
{
return $this->comments;
}
public function addComment(Comment $comment): self
{
if (!$this->comments->contains($comment)) {
$this->comments[] = $comment;
$comment->setMainGroup($this);
}
return $this;
}
public function removeComment(Comment $comment): self
{
if ($this->comments->removeElement($comment)) {
// set the owning side to null (unless already changed)
if ($comment->getMainGroup() === $this) {
$comment->setMainGroup(null);
}
}
return $this;
}
public function getMotd(): ?string
{
return $this->motd;
}
public function setMotd(?string $motd): self
{
$this->motd = $motd;
return $this;
}
public function getMotdUpdatedAt(): ?\DateTimeImmutable
{
return $this->motdUpdatedAt;
}
public function setMotdUpdatedAt(?\DateTimeImmutable $motdUpdatedAt): self
{
$this->motdUpdatedAt = $motdUpdatedAt;
return $this;
}
public function getUpdatedAt(): ?\DateTimeImmutable
{
return $this->updatedAt;
}
public function setUpdatedAt(\DateTimeImmutable $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* @return Collection|SubGroup[]
*/
public function getSubGroups(): Collection
{
return $this->subGroups;
}
public function addSubGroup(SubGroup $subGroup): self
{
if (!$this->subGroups->contains($subGroup)) {
$this->subGroups[] = $subGroup;
$subGroup->setMainGroup($this);
}
return $this;
}
public function removeSubGroup(SubGroup $subGroup): self
{
if ($this->subGroups->removeElement($subGroup)) {
// set the owning side to null (unless already changed)
if ($subGroup->getMainGroup() === $this) {
$subGroup->setMainGroup(null);
}
}
return $this;
}
}

View File

@@ -0,0 +1,55 @@
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use App\Repository\InfringementRepository;
/**
* @ORM\Entity(repositoryClass=InfringementRepository::class)
*/
class Infringement extends Document
{
/**
* @ORM\Column(type="text")
* @Gedmo\Versioned
*/
private $content;
/**
* @ORM\ManyToOne(targetEntity=Directory::class, inversedBy="infringements")
* @ORM\JoinColumn(nullable=false)
*/
private $directory;
public function __construct(User $user)
{
parent::__construct($user);
$this->setNeedLegalAccess(true);
}
public function getContent(): ?string
{
return $this->content;
}
public function setContent(string $content): self
{
$this->content = $content;
return $this;
}
public function getDirectory(): ?Directory
{
return $this->directory;
}
public function setDirectory(?Directory $directory): self
{
$this->directory = $directory;
return $this;
}
}

132
src/Entity/Jail.php Normal file
View File

@@ -0,0 +1,132 @@
<?php
namespace App\Entity;
use App\Entity\User;
use DateTimeImmutable;
use App\Entity\Document;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\JailRepository;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @ORM\Entity(repositoryClass=JailRepository::class)
*/
class Jail extends Document
{
/**
* @ORM\Column(type="datetime_immutable")
* @Gedmo\Versioned
*/
private $arrestedAt;
/**
* @ORM\Column(type="datetime_immutable")
* @Gedmo\Versioned
*/
private $jailedAt;
/**
* @ORM\ManyToOne(targetEntity=Directory::class, inversedBy="jails")
* @ORM\JoinColumn(nullable=false)
*/
private $directory;
/**
* @ORM\Column(type="text")
* @Gedmo\Versioned
*/
private $content;
/**
* @ORM\Column(type="boolean", options={"default":"0"})
* @Gedmo\Versioned
*/
private $lawyer = false;
/**
* @ORM\Column(type="boolean", options={"default":"0"})
* @Gedmo\Versioned
*/
private $medic = false;
public function __construct(User $user)
{
parent::__construct($user);
$this->setNeedLegalAccess(true);
$this->setArrestedAt(new DateTimeImmutable());
$this->setJailedAt(new DateTimeImmutable());
}
public function getArrestedAt(): ?\DateTimeImmutable
{
return $this->arrestedAt;
}
public function setArrestedAt(\DateTimeImmutable $arrestedAt): self
{
$this->arrestedAt = $arrestedAt;
return $this;
}
public function getJailedAt(): ?\DateTimeImmutable
{
return $this->jailedAt;
}
public function setJailedAt(\DateTimeImmutable $jailedAt): self
{
$this->jailedAt = $jailedAt;
return $this;
}
public function getDirectory(): ?Directory
{
return $this->directory;
}
public function setDirectory(?Directory $directory): self
{
$this->directory = $directory;
return $this;
}
public function getContent(): ?string
{
return $this->content;
}
public function setContent(string $content): self
{
$this->content = $content;
return $this;
}
public function getLawyer(): ?bool
{
return $this->lawyer;
}
public function setLawyer(bool $lawyer): self
{
$this->lawyer = $lawyer;
return $this;
}
public function getMedic(): ?bool
{
return $this->medic;
}
public function setMedic(bool $medic): self
{
$this->medic = $medic;
return $this;
}
}

View File

@@ -0,0 +1,76 @@
<?php
namespace App\Entity;
use DateTimeImmutable;
use App\Entity\Document;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use App\Repository\LicenceWithdrawalRepository;
/**
* @ORM\Entity(repositoryClass=LicenceWithdrawalRepository::class)
*/
class LicenceWithdrawal extends Document
{
/**
* @ORM\Column(type="string", length=255)
* @Gedmo\Versioned
*/
private $type;
/**
* @ORM\Column(type="datetime_immutable")
* @Gedmo\Versioned
*/
private $until;
/**
* @ORM\ManyToOne(targetEntity=Directory::class, inversedBy="licenceWithdrawals")
* @ORM\JoinColumn(nullable=false)
*/
private $directory;
public function __construct(User $user)
{
parent::__construct($user);
$this->setNeedLegalAccess(true);
$this->setUntil(new DateTimeImmutable());
}
public function getType(): ?string
{
return $this->type;
}
public function setType(string $type): self
{
$this->type = $type;
return $this;
}
public function getUntil(): ?\DateTimeImmutable
{
return $this->until;
}
public function setUntil(\DateTimeImmutable $until): self
{
$this->until = $until;
return $this;
}
public function getDirectory(): ?Directory
{
return $this->directory;
}
public function setDirectory(?Directory $directory): self
{
$this->directory = $directory;
return $this;
}
}

56
src/Entity/Medical.php Normal file
View File

@@ -0,0 +1,56 @@
<?php
namespace App\Entity;
use App\Entity\Document;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\MedicalRepository;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @ORM\Entity(repositoryClass=MedicalRepository::class)
*/
class Medical extends Document
{
/**
* @ORM\ManyToOne(targetEntity=Directory::class, inversedBy="medicals")
* @ORM\JoinColumn(nullable=false)
*/
private $directory;
/**
* @ORM\Column(type="text")
* @Gedmo\Versioned
*/
private $content;
public function __construct(User $user)
{
parent::__construct($user);
$this->setNeedMedicalAccess(true);
}
public function getDirectory(): ?Directory
{
return $this->directory;
}
public function setDirectory(?Directory $directory): self
{
$this->directory = $directory;
return $this;
}
public function getContent(): ?string
{
return $this->content;
}
public function setContent(string $content): self
{
$this->content = $content;
return $this;
}
}

141
src/Entity/Notification.php Normal file
View File

@@ -0,0 +1,141 @@
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use App\Repository\NotificationRepository;
/**
* @ORM\Entity(repositoryClass=NotificationRepository::class)
*/
class Notification
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="notificationsSent")
*/
private $sender;
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="notifications")
* @ORM\JoinColumn(nullable=false)
*/
private $receiver;
/**
* @ORM\Column(type="string", length=255)
*/
private $icon;
/**
* @ORM\Column(type="string", length=255)
*/
private $content;
/**
* @ORM\Column(type="datetime_immutable")
* @Gedmo\Timestampable(on="create")
*/
private $createdAt;
/**
* @ORM\Column(type="boolean", options={"default":"0"})
*/
private $readed = false;
public function __construct(User $Receiver, string $Content, ?User $Sender = null, ?string $Icon = null)
{
$this->setReceiver($Receiver);
$this->setContent($Content);
if (null != $Sender) {
$this->setSender($Sender);
}
if (null != $Icon) {
$this->setIcon($Icon);
}
}
public function getId(): ?int
{
return $this->id;
}
public function getSender(): ?User
{
return $this->sender;
}
public function setSender(?User $sender): self
{
$this->sender = $sender;
return $this;
}
public function getReceiver(): ?User
{
return $this->receiver;
}
public function setReceiver(?User $receiver): self
{
$this->receiver = $receiver;
return $this;
}
public function getIcon(): ?string
{
return $this->icon;
}
public function setIcon(string $icon): self
{
$this->icon = $icon;
return $this;
}
public function getContent(): ?string
{
return $this->content;
}
public function setContent(string $content): self
{
$this->content = $content;
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeImmutable $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getReaded(): ?bool
{
return $this->readed;
}
public function setReaded(bool $readed): self
{
$this->readed = $readed;
return $this;
}
}

180
src/Entity/Rank.php Normal file
View File

@@ -0,0 +1,180 @@
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\RankRepository;
use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @ORM\Entity(repositoryClass=RankRepository::class)
* @Gedmo\Loggable
*/
class Rank
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
* @Gedmo\Versioned
*/
private $name;
/**
* @ORM\ManyToOne(targetEntity=Group::class, inversedBy="ranks")
* @ORM\JoinColumn(nullable=false)
*/
private $mainGroup;
/**
* @ORM\Column(type="string", length=255)
* @Gedmo\Versioned
*/
private $shortname;
/**
* @ORM\Column(type="integer")
* @Gedmo\Versioned
*/
private $power;
/**
* @ORM\Column(type="datetime_immutable")
* @Gedmo\Timestampable(on="create")
*/
private $createdAt;
/**
* @ORM\Column(type="json", nullable=true)
* @Gedmo\Versioned
*/
private $permissions = [];
/**
* @ORM\OneToMany(targetEntity=User::class, mappedBy="mainRank")
*/
private $users;
public function __construct()
{
$this->users = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getMainGroup(): ?Group
{
return $this->mainGroup;
}
public function setMainGroup(?Group $MainGroup): self
{
$this->mainGroup = $MainGroup;
return $this;
}
public function getShortname(): ?string
{
return $this->shortname;
}
public function setShortname(string $shortname): self
{
$this->shortname = $shortname;
return $this;
}
public function getPower(): ?int
{
return $this->power;
}
public function setPower(int $power): self
{
$this->power = $power;
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeImmutable $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getPermissions(): ?array
{
$permissions = $this->permissions;
// guarantee every user can access directories
$permissions[] = 'directory_view';
return array_unique($permissions);
}
public function setPermissions(?array $permissions): self
{
$this->permissions = $permissions;
return $this;
}
/**
* @return Collection|User[]
*/
public function getUsers(): Collection
{
return $this->users;
}
public function addUser(User $user): self
{
if (!$this->users->contains($user)) {
$this->users[] = $user;
$user->setMainRank($this);
}
return $this;
}
public function removeUser(User $user): self
{
if ($this->users->removeElement($user)) {
// set the owning side to null (unless already changed)
if ($user->getMainRank() === $this) {
$user->setMainRank(null);
}
}
return $this;
}
}

32
src/Entity/Report.php Normal file
View File

@@ -0,0 +1,32 @@
<?php
namespace App\Entity;
use App\Entity\Document;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\ReportRepository;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @ORM\Entity(repositoryClass=ReportRepository::class)
*/
class Report extends Document
{
/**
* @ORM\Column(type="text")
* @Gedmo\Versioned
*/
private $content;
public function getContent(): ?string
{
return $this->content;
}
public function setContent(string $content): self
{
$this->content = $content;
return $this;
}
}

View File

@@ -0,0 +1,45 @@
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\ResetPasswordRequestRepository;
use SymfonyCasts\Bundle\ResetPassword\Model\ResetPasswordRequestTrait;
use SymfonyCasts\Bundle\ResetPassword\Model\ResetPasswordRequestInterface;
/**
* @ORM\Entity(repositoryClass=ResetPasswordRequestRepository::class)
*/
class ResetPasswordRequest implements ResetPasswordRequestInterface
{
use ResetPasswordRequestTrait;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity=User::class)
* @ORM\JoinColumn(nullable=false)
*/
private $user;
public function __construct(object $user, \DateTimeInterface $expiresAt, string $selector, string $hashedToken)
{
$this->user = $user;
$this->initialize($expiresAt, $selector, $hashedToken);
}
public function getId(): ?int
{
return $this->id;
}
public function getUser(): object
{
return $this->user;
}
}

55
src/Entity/Sanction.php Normal file
View File

@@ -0,0 +1,55 @@
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\SanctionRepository;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @ORM\Entity(repositoryClass=SanctionRepository::class)
*/
class Sanction extends Document
{
/**
* @ORM\Column(type="text")
* @Gedmo\Versioned
*/
private $content;
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="sanctions")
* @ORM\JoinColumn(nullable=false)
*/
private $user;
public function __construct(User $user)
{
parent::__construct($user);
$this->setNeedGroupAdministration(true);
}
public function getContent(): ?string
{
return $this->content;
}
public function setContent(string $content): self
{
$this->content = $content;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
}

View File

@@ -0,0 +1,128 @@
<?php
namespace App\Entity;
use App\Entity\Document;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use App\Repository\StolenvehicleRepository;
/**
* @ORM\Entity(repositoryClass=StolenvehicleRepository::class)
*/
class Stolenvehicle extends Document
{
/**
* @ORM\Column(type="string", length=255)
* @Gedmo\Versioned
*/
private $type;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Gedmo\Versioned
*/
private $numberplate;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Gedmo\Versioned
*/
private $model;
/**
* @ORM\Column(type="text", nullable=true)
* @Gedmo\Versioned
*/
private $content;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Gedmo\Versioned
*/
private $color;
/**
* @ORM\ManyToOne(targetEntity=Directory::class, inversedBy="stolenvehicles")
* @ORM\JoinColumn(nullable=false)
*/
private $directory;
public function __construct(User $user)
{
parent::__construct($user);
$this->setNeedLegalAccess(true);
}
public function getType(): ?string
{
return $this->type;
}
public function setType(string $type): self
{
$this->type = $type;
return $this;
}
public function getNumberplate(): ?string
{
return $this->numberplate;
}
public function setNumberplate(?string $numberplate): self
{
$this->numberplate = $numberplate;
return $this;
}
public function getModel(): ?string
{
return $this->model;
}
public function setModel(?string $model): self
{
$this->model = $model;
return $this;
}
public function getContent(): ?string
{
return $this->content;
}
public function setContent(?string $content): self
{
$this->content = $content;
return $this;
}
public function getColor(): ?string
{
return $this->color;
}
public function setColor(?string $color): self
{
$this->color = $color;
return $this;
}
public function getDirectory(): ?Directory
{
return $this->directory;
}
public function setDirectory(?Directory $directory): self
{
$this->directory = $directory;
return $this;
}
}

170
src/Entity/SubGroup.php Normal file
View File

@@ -0,0 +1,170 @@
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\SubGroupRepository;
use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @ORM\Entity(repositoryClass=SubGroupRepository::class)
* @Gedmo\Loggable
*/
class SubGroup
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity=Group::class, inversedBy="subGroups")
* @ORM\JoinColumn(nullable=false)
*/
private $mainGroup;
/**
* @ORM\Column(type="string", length=255)
* @Gedmo\Versioned
*/
private $name;
/**
* @ORM\ManyToMany(targetEntity=User::class, mappedBy="subGroups")
*/
private $users;
/**
* @ORM\ManyToMany(targetEntity=Document::class, mappedBy="allowedSubGroups")
*/
private $documents;
/**
* @ORM\Column(type="string", length=12, nullable=true)
* @Gedmo\Versioned
*/
private $shortName;
/**
* @ORM\Column(type="datetime_immutable")
* @Gedmo\Timestampable(on="create")
*/
private $createdAt;
public function __construct()
{
$this->users = new ArrayCollection();
$this->documents = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getMainGroup(): ?Group
{
return $this->mainGroup;
}
public function setMainGroup(?Group $mainGroup): self
{
$this->mainGroup = $mainGroup;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
/**
* @return Collection|User[]
*/
public function getUsers(): Collection
{
return $this->users;
}
public function addUser(User $user): self
{
if (!$this->users->contains($user)) {
$this->users[] = $user;
$user->addSubGroup($this);
}
return $this;
}
public function removeUser(User $user): self
{
if ($this->users->removeElement($user)) {
$user->removeSubGroup($this);
}
return $this;
}
/**
* @return Collection|Document[]
*/
public function getDocuments(): Collection
{
return $this->documents;
}
public function addDocument(Document $document): self
{
if (!$this->documents->contains($document)) {
$this->documents[] = $document;
$document->addAllowedSubGroup($this);
}
return $this;
}
public function removeDocument(Document $document): self
{
if ($this->documents->removeElement($document)) {
$document->removeAllowedSubGroup($this);
}
return $this;
}
public function getShortName(): ?string
{
return $this->shortName;
}
public function setShortName(?string $shortName): self
{
$this->shortName = $shortName;
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeImmutable $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
}

39
src/Entity/Template.php Normal file
View File

@@ -0,0 +1,39 @@
<?php
namespace App\Entity;
use App\Entity\Document;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\TemplateRepository;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @ORM\Entity(repositoryClass=TemplateRepository::class)
*/
class Template extends Document
{
public function __construct(User $user)
{
parent::__construct($user);
$this->setNeedGroupAdministration(true);
}
/**
* @ORM\Column(type="text")
* @Gedmo\Versioned
*/
private $content;
public function getContent(): ?string
{
return $this->content;
}
public function setContent(string $content): self
{
$this->content = $content;
return $this;
}
}

599
src/Entity/User.php Normal file
View File

@@ -0,0 +1,599 @@
<?php
namespace App\Entity;
use App\Entity\Comment;
use App\Entity\Document;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\UserRepository;
use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use function Symfony\Component\String\u;
/**
* @ORM\Entity(repositoryClass=UserRepository::class)
* @UniqueEntity(fields={"email"}, message="There is already an account with this email")
* @Gedmo\Loggable
*/
class User implements UserInterface, PasswordAuthenticatedUserInterface, \Serializable
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=180, unique=true)
* @Gedmo\Versioned
*/
private $email;
/**
* @ORM\Column(type="json")
* @Gedmo\Versioned
*/
private $roles = [];
/**
* @var string The hashed password
* @ORM\Column(type="string")
*/
private $password;
/**
* @ORM\Column(type="boolean", options={"default":"0"})
*/
private $isVerified = false;
/**
* @ORM\OneToMany(targetEntity=Document::class, mappedBy="creator")
*/
private $documents;
/**
* @ORM\ManyToOne(targetEntity=Group::class, inversedBy="users")
*/
private $mainGroup;
/**
* @ORM\Column(type="boolean", options={"default":"0"})
*/
private $adminMode = false;
/**
* @ORM\Column(type="string", length=255)
* @Gedmo\Versioned
*/
private $firstname;
/**
* @ORM\Column(type="string", length=255)
* @Gedmo\Versioned
*/
private $lastname;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $phone;
/**
* @ORM\Column(type="datetime_immutable")
* @Gedmo\Timestampable(on="create")
*/
private $createdAt;
/**
* @ORM\ManyToOne(targetEntity=Rank::class, inversedBy="users")
*/
private $mainRank;
/**
* @ORM\OneToMany(targetEntity=Comment::class, mappedBy="creator")
*/
private $comments;
/**
* @ORM\Column(type="boolean", options={"default":"0"})
* @Gedmo\Versioned
*/
private $isDesactivated = false;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Gedmo\Versioned
*/
private $locale;
/**
* @ORM\OneToMany(targetEntity=Sanction::class, mappedBy="user", orphanRemoval=true)
*/
private $sanctions;
/**
* @ORM\OneToMany(targetEntity=Notification::class, mappedBy="sender")
*/
private $notificationsSent;
/**
* @ORM\OneToMany(targetEntity=Notification::class, mappedBy="receiver", orphanRemoval=true)
*/
private $notifications;
/**
* @ORM\ManyToMany(targetEntity=SubGroup::class, inversedBy="users")
*/
private $subGroups;
public function __construct()
{
$this->documents = new ArrayCollection();
$this->adminMode = false;
$this->comments = new ArrayCollection();
$this->sanctions = new ArrayCollection();
$this->notificationsSent = new ArrayCollection();
$this->notifications = new ArrayCollection();
$this->subGroups = new ArrayCollection();
}
/** @see \Serializable::serialize() */
public function serialize()
{
return serialize(array(
$this->id,
$this->email,
$this->password,
));
}
/** @see \Serializable::unserialize() */
public function unserialize($serialized)
{
list (
$this->id,
$this->email,
$this->password,
) = unserialize($serialized);
}
public function getId(): ?int
{
return $this->id;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUserIdentifier(): string
{
return (string) $this->email;
}
/**
* @deprecated since Symfony 5.3, use getUserIdentifier instead
*/
public function getUsername(): string
{
return (string) $this->email;
}
/**
* @see UserInterface
*/
public function getRoles(): array
{
$roles = $this->roles;
// guarantee every user at least has ROLE_USER
$roles[] = 'ROLE_USER';
return array_unique($roles);
}
public function setRoles(array $roles): self
{
$this->roles = $roles;
return $this;
}
/**
* @see PasswordAuthenticatedUserInterface
*/
public function getPassword(): string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
/**
* Returning a salt is only needed, if you are not using a modern
* hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
*
* @see UserInterface
*/
public function getSalt(): ?string
{
return null;
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
public function isVerified(): bool
{
return $this->isVerified;
}
public function setIsVerified(bool $isVerified): self
{
$this->isVerified = $isVerified;
return $this;
}
/**
* @return Collection|Document[]
*/
public function getDocuments(): Collection
{
return $this->documents;
}
public function addDocument(Document $document): self
{
if (!$this->documents->contains($document)) {
$this->documents[] = $document;
$document->setCreator($this);
}
return $this;
}
public function removeDocument(Document $document): self
{
if ($this->documents->removeElement($document)) {
// set the owning side to null (unless already changed)
if ($document->getCreator() === $this) {
$document->setCreator(null);
}
}
return $this;
}
public function getMainGroup(): ?Group
{
return $this->mainGroup;
}
public function setMainGroup(?Group $mainGroup): self
{
$this->mainGroup = $mainGroup;
return $this;
}
public function getAdminMode(): ?bool
{
return $this->adminMode;
}
public function setAdminMode(bool $adminMode): self
{
if (!$this->hasRole('ROLE_ADMIN')) {
$adminMode = false;
}
$this->adminMode = $adminMode;
return $this;
}
public function getFirstname(): ?string
{
return $this->firstname;
}
public function setFirstname(string $firstname): self
{
$this->firstname = $firstname;
return $this;
}
public function getLastname(): ?string
{
return $this->lastname;
}
public function setLastname(string $lastname): self
{
$this->lastname = $lastname;
return $this;
}
public function getFullName(): string
{
return sprintf('%s %s', u($this->firstname)->title(true), u($this->lastname)->upper());
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(?string $phone): self
{
$this->phone = $phone;
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeImmutable $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getMainRank(): ?Rank
{
return $this->mainRank;
}
public function setMainRank(?Rank $mainRank): self
{
$this->mainRank = $mainRank;
$this->setMainGroup(($mainRank === null) ? null : $mainRank->getMainGroup());
return $this;
}
/**
* @return Collection|Comment[]
*/
public function getComments(): Collection
{
return $this->comments;
}
public function addComment(Comment $comment): self
{
if (!$this->comments->contains($comment)) {
$this->comments[] = $comment;
$comment->setCreator($this);
}
return $this;
}
public function removeComment(Comment $comment): self
{
if ($this->comments->removeElement($comment)) {
// set the owning side to null (unless already changed)
if ($comment->getCreator() === $this) {
$comment->setCreator(null);
}
}
return $this;
}
/**
* Custom function to check if user has permisssion
*
* @param String $permission
* @return boolean
*/
public function hasPermission(string $permission): bool
{
if ($this->getMainGroup() == null) {
return false;
}
if ($this->getMainRank() == null) {
return false;
}
if ($this->getAdminMode() == true) {
return true;
}
if (in_array(strtolower($permission), array_map('strtolower', $this->getMainRank()->getPermissions()))) {
return true;
}
return false;
}
/**
* Custom function to check if user has role
*
* @param String $permission
* @return boolean
*/
public function hasRole(string $role): bool
{
if (in_array(strtolower($role), array_map('strtolower', $this->getRoles()))) {
return true;
}
return false;
}
public function getIsDesactivated(): ?bool
{
return $this->isDesactivated;
}
public function setIsDesactivated(bool $isDesactivated): self
{
$this->isDesactivated = $isDesactivated;
return $this;
}
public function getLocale(): string
{
return ($this->locale != null) ? $this->locale : 'en';
}
public function setLocale(?string $locale): self
{
$this->locale = $locale;
return $this;
}
/**
* @return Collection|Sanction[]
*/
public function getSanctions(): Collection
{
return $this->sanctions;
}
public function addSanction(Sanction $sanction): self
{
if (!$this->sanctions->contains($sanction)) {
$this->sanctions[] = $sanction;
$sanction->setUser($this);
}
return $this;
}
public function removeSanction(Sanction $sanction): self
{
if ($this->sanctions->removeElement($sanction)) {
// set the owning side to null (unless already changed)
if ($sanction->getUser() === $this) {
$sanction->setUser(null);
}
}
return $this;
}
/**
* @return Collection|Notification[]
*/
public function getNotificationsSent(): Collection
{
return $this->notificationsSent;
}
public function addNotificationsSent(Notification $notificationsSent): self
{
if (!$this->notificationsSent->contains($notificationsSent)) {
$this->notificationsSent[] = $notificationsSent;
$notificationsSent->setSender($this);
}
return $this;
}
public function removeNotificationsSent(Notification $notificationsSent): self
{
if ($this->notificationsSent->removeElement($notificationsSent)) {
// set the owning side to null (unless already changed)
if ($notificationsSent->getSender() === $this) {
$notificationsSent->setSender(null);
}
}
return $this;
}
/**
* @return Collection|Notification[]
*/
public function getNotifications(): Collection
{
return $this->notifications;
}
public function addNotification(Notification $notification): self
{
if (!$this->notifications->contains($notification)) {
$this->notifications[] = $notification;
$notification->setReceiver($this);
}
return $this;
}
public function removeNotification(Notification $notification): self
{
if ($this->notifications->removeElement($notification)) {
// set the owning side to null (unless already changed)
if ($notification->getReceiver() === $this) {
$notification->setReceiver(null);
}
}
return $this;
}
/**
* @return Collection|subGroup[]
*/
public function getSubGroups(): Collection
{
return $this->subGroups;
}
public function addSubGroup(subGroup $subGroup): self
{
if (!$this->subGroups->contains($subGroup)) {
if ($subGroup->getMainGroup != $this->mainGroup) {
return null;
}
$this->subGroups[] = $subGroup;
}
return $this;
}
public function removeSubGroup(subGroup $subGroup): self
{
$this->subGroups->removeElement($subGroup);
return $this;
}
}

View File

@@ -0,0 +1,56 @@
<?php
namespace App\EventListener;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
/**
* Symfony AccessDenied fixer
* When and "AccessDeniedException" is throw by symfony (ex: is granted)
* the throw happen before getting users informations, and so make tempalting full bugged
* and also as no user, security access_control look user as visitor (no access)
* so, intercepting those, to repalce with "AccessDeniedHttpException" work better
*/
class AccessDeniedListener implements EventSubscriberInterface
{
private $Security;
public function __construct(Security $Security)
{
$this->Security = $Security;
}
public static function getSubscribedEvents(): array
{
return [
// the priority must be greater than the Security HTTP
// ExceptionListener, to make sure it's called before
// the default exception listener
KernelEvents::EXCEPTION => ['onKernelException', 2],
];
}
public function onKernelException(ExceptionEvent $event): void
{
$exception = $event->getThrowable();
//if no user, don't replace "AccessDeniedException"
//this will just lock access_control out
if (!$this->Security->getUser()) {
return;
}
if (!$exception instanceof AccessDeniedException) {
return;
}
throw new AccessDeniedHttpException($exception->getMessage());
}
}

View File

@@ -0,0 +1,117 @@
<?php
namespace App\EventSubscriber;
use Twig\Environment;
use App\Entity\Comment;
use App\Entity\Notification;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\Event\LifecycleEventArgs;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
class DatabaseActivitySubscriber
{
protected TokenStorageInterface $tokenStorage;
protected EntityManagerInterface $entityManager;
protected Environment $twig;
public function __construct(
TokenStorageInterface $tokenStorage,
EntityManagerInterface $entityManager,
Environment $twig
) {
$this->tokenStorage = $tokenStorage;
$this->entityManager = $entityManager;
$this->twig = $twig;
}
/**
* @param LifecycleEventArgs $args
*/
public function postPersist(LifecycleEventArgs $args): void
{
$this->notify('postPersist', $args);
}
/**
* @param LifecycleEventArgs $args
*/
public function postRemove(LifecycleEventArgs $args): void
{
$this->notify('postRemove', $args);
}
/**
* @param LifecycleEventArgs $args
*/
public function postUpdate(LifecycleEventArgs $args): void
{
$this->notify('postUpdate', $args);
}
private function notify(string $action, LifecycleEventArgs $args): void
{
$entity = $args->getObject();
if (
is_subclass_of($entity, 'App\Entity\Document')
&& method_exists($entity, 'getCreator')
&& in_array($action, ['postUpdate', 'postRemove'])
) {
$sender = $this->tokenStorage->getToken()->getUser();
$receiver = $entity->getCreator();
if ($receiver != $sender) {
$htmlContents = $this->twig->render('_notifications/document_' . $action . '.html.twig', [
'sender' => $sender,
'document' => $entity
]);
$notification = new Notification(
$receiver,
$htmlContents,
$sender,
'notification_icon_document_' . $action
);
$this->entityManager->persist($notification);
try {
$this->entityManager->flush();
} catch (\Throwable $th) {
throw $th;
}
}
}
if (
$entity instanceof Comment
&& method_exists($entity, 'getDocument')
&& in_array($action, ['postUpdate', 'postRemove', 'postPersist'])
) {
$sender = $this->tokenStorage->getToken()->getUser();
$receiver = $entity->getDocument()->getCreator();
if ($receiver != $sender) {
$htmlContents = $this->twig->render('_notifications/comment_' . $action . '.html.twig', [
'sender' => $sender,
'document' => $entity->getDocument()
]);
$notification = new Notification(
$receiver,
$htmlContents,
$sender,
'notification_icon_comment_' . $action
);
$this->entityManager->persist($notification);
try {
$this->entityManager->flush();
} catch (\Throwable $th) {
throw $th;
}
}
}
}
}

View File

@@ -0,0 +1,54 @@
<?php
namespace App\EventSubscriber;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Security\Http\SecurityEvents;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
class LocaleSubscriber implements EventSubscriberInterface
{
private $defaultLocale;
private $requestStack;
public function __construct(RequestStack $requestStack, ParameterBagInterface $params)
{
$this->defaultLocale = $params->get('kernel.default_locale');
$this->requestStack = $requestStack;
}
public function onKernelRequest(RequestEvent $event)
{
$request = $event->getRequest();
if (!$request->hasPreviousSession()) {
return;
}
$request->setLocale($request->getSession()->get('_locale', $this->defaultLocale));
}
public function onInteractiveLogin(InteractiveLoginEvent $event)
{
/**
* @var user $user
*/
$user = $event->getAuthenticationToken()->getUser();
if (null !== $user->getLocale()) {
$this->requestStack->getSession()->set('_locale', $user->getLocale());
}
}
public static function getSubscribedEvents()
{
return [
KernelEvents::REQUEST => [['onKernelRequest', 20]],
SecurityEvents::INTERACTIVE_LOGIN => 'onInteractiveLogin',
];
}
}

View File

@@ -0,0 +1,83 @@
<?php
namespace App\EventSubscriber;
use App\Entity\User;
use Twig\Environment;
use Doctrine\ORM\EntityManagerInterface;
use App\Repository\NotificationRepository;
use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
class NotificationsSubscriber implements EventSubscriberInterface
{
private Environment $twig;
private TokenStorageInterface $tokenStorage;
private EntityManagerInterface $entityManager;
public function __construct(
Environment $twig,
TokenStorageInterface $tokenStorage = null,
EntityManagerInterface $entityManager
) {
$this->twig = $twig;
$this->tokenStorage = $tokenStorage;
$this->entityManager = $entityManager;
}
public function onKernelController(ControllerEvent $event)
{
if (null === $this->tokenStorage) {
return;
}
$token = $this->tokenStorage->getToken();
if (null === $token) {
return;
}
/**
* @var NotificationRepository notificationRepo
*/
if (null === ($notificationRepo = $this->entityManager->getRepository("App:Notification"))) {
return;
}
/**
* @var User $User
*/
$User = $token->getUser();
if (null === $User) {
return;
}
$this->twig->addGlobal(
'user_notifications_list',
$notificationRepo->listForUser($User)
->readed(false)
->limit(5)
->order(['createdAt' => 'DESC'])
->getResult()
);
$this->twig->addGlobal(
'user_notifications_count',
$notificationRepo->listForUser($User)
->readed(false)
->limit(5)
->order(['createdAt' => 'DESC'])
->getCount()
);
}
public static function getSubscribedEvents()
{
return [
'kernel.controller' => 'onKernelController',
];
}
}

View File

@@ -0,0 +1,64 @@
<?php
namespace App\EventSubscriber;
use Gedmo\Loggable\LoggableListener;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
class VisionLoggerSubscriber implements EventSubscriberInterface
{
private AuthorizationCheckerInterface $authorizationChecker;
private TokenStorageInterface $tokenStorage;
private LoggableListener $loggableListener;
public function __construct(
LoggableListener $loggableListener,
TokenStorageInterface $tokenStorage = null,
AuthorizationCheckerInterface $authorizationChecker = null
) {
$this->loggableListener = $loggableListener;
$this->tokenStorage = $tokenStorage;
$this->authorizationChecker = $authorizationChecker;
}
/**
* @internal
*/
public function onKernelRequest(RequestEvent $event)
{
if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
return;
}
if (null === $this->tokenStorage || null === $this->authorizationChecker) {
return;
}
$token = $this->tokenStorage->getToken();
if (null !== $token && $this->authorizationChecker->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
/**
* @var User $User
*/
$User = $token->getUser();
$this->loggableListener->setUsername($User->getFullname() . ', ' . $User->getMainGroup()->getName());
}
}
public static function getSubscribedEvents()
{
return array(
KernelEvents::REQUEST => 'onKernelRequest',
);
}
}

View File

@@ -0,0 +1,43 @@
<?php
namespace App\Form;
use App\Entity\Group;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Vich\UploaderBundle\Form\Type\VichImageType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
class AdminGroupType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name', null, ['label' => 'form_label_name'])
->add('shortName', null, ['label' => 'form_label_shortname'])
->add('imageFile', VichImageType::class, [
'required' => false,
'label' => 'form_label_group_logo',
'allow_delete' => true,
'delete_label' => 'form_label_remove_image',
'download_label' => 'form_label_download_image',
'download_uri' => false,
'image_uri' => false,
'asset_helper' => true,
])
->add('motd', null, ['label' => 'form_label_motd','attr' => ['style' => 'height: 400px;']])
->add('submit', SubmitType::class, [
'label' => 'form_button_submit',
'attr' => ['class' => 'btn-primary'],
])
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Group::class,
]);
}
}

View File

@@ -0,0 +1,36 @@
<?php
namespace App\Form;
use App\Entity\Rank;
use App\Form\Type\PermissionsType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
class AdminRankType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name', null, ['label' => 'form_label_name'])
->add('shortname', null, ['label' => 'form_label_shortname'])
->add('power', null, ['label' => 'form_label_power', 'help' => 'form_help_power'])
->add('permissions', PermissionsType::class)
->add('submit', SubmitType::class, [
'label' => 'form_button_submit',
'attr' => ['class' => 'btn-primary'],
])
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Rank::class,
]);
}
}

View File

@@ -0,0 +1,33 @@
<?php
namespace App\Form;
use App\Entity\SubGroup;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
class AdminSubGroupType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name', null, ['label' => 'form_label_name'])
->add('shortname', null, ['label' => 'form_label_shortname'])
->add('submit', SubmitType::class, [
'label' => 'form_button_submit',
'attr' => ['class' => 'btn-primary'],
])
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => SubGroup::class,
]);
}
}

106
src/Form/AdminUserType.php Normal file
View File

@@ -0,0 +1,106 @@
<?php
namespace App\Form;
use App\Entity\Rank;
use App\Entity\User;
use App\Entity\SubGroup;
use App\Form\Type\PhoneType;
use App\Form\Type\LastnameType;
use App\Form\Type\FirstnameType;
use App\Repository\RankRepository;
use App\Repository\SubGroupRepository;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
class AdminUserType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
/**
* @var User $User
*/
$User = $builder->getData();
$UserGroup = $User->getMainGroup();
$builder
->add('email', null, ['label' => 'form_label_email'])
->add('firstname', FirstnameType::class)
->add('lastname', LastnameType::class)
->add('phone', PhoneType::class)
->add('mainRank', EntityType::class, [
'class' => Rank::class,
'query_builder' => function (RankRepository $RankRepository) {
return $RankRepository->createQueryBuilder('r')
->orderBy('r.power', 'DESC');
},
'choice_label' => 'name',
'label' => 'form_label_group_and_rank',
'required' => false,
'group_by' => function ($choice, $key, $value) {
return $choice->getMainGroup()->getName();
},
]);
if (!$UserGroup->getSubGroups()->isEmpty()) {
$builder
->add('subGroups', EntityType::class, [
'class' => SubGroup::class,
'query_builder' => function (SubGroupRepository $SubGroupRepository) use ($UserGroup) {
return $SubGroupRepository->createQueryBuilder('sg')
->where('sg.mainGroup =' . $UserGroup->getId())
;
},
'choice_label' => 'name',
'label' => 'form_label_subgroups',
'required' => false,
'multiple' => true,
'expanded' => true
]);
}
$builder
->add('roles', ChoiceType::class, [
'choices' => [
'form_choice_admin' => 'ROLE_ADMIN'
],
'expanded' => true,
'multiple' => true,
'label' => 'form_label_roles',
])
->add('isVerified', CheckboxType::class, [
'label' => 'form_label_checkbox_isverified',
'help' => 'form_help_checkbox_isverified',
'required' => false
])
->add('isDesactivated', CheckboxType::class, [
'label' => 'form_label_checkbox_isdesactivated',
'help' => 'form_help_checkbox_isdesactivated',
'required' => false
])
->add('adminMode', CheckboxType::class, [
'label' => 'form_label_checkbox_adminmode',
'help' => 'form_help_checkbox_adminmode',
'required' => false
])
->add('submit', SubmitType::class, [
'label' => 'form_button_submit',
'attr' => ['class' => 'btn-primary'],
])
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => User::class,
]);
}
}

27
src/Form/AnnounceType.php Normal file
View File

@@ -0,0 +1,27 @@
<?php
namespace App\Form;
use App\Entity\Announce;
use App\Form\Type\ContentType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class AnnounceType extends DocumentType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
parent::buildForm($builder, $options);
$builder
->add('content', ContentType::class)
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Announce::class,
]);
}
}

View File

@@ -0,0 +1,46 @@
<?php
namespace App\Form;
use App\Entity\User;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
class AuthenticateType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('email', EmailType::class, [
'label' => false,
'attr' => ['placeholder' => 'form_label_email'],
])
->add('password', PasswordType::class, [
'label' => false,
'attr' => ['placeholder' => 'form_label_password'],
])
->add('submit', SubmitType::class, [
'label' => 'form_button_login',
'attr' => ['class' => 'btn-primary'],
])
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => User::class,
'csrf_field_name' => '_csrf_token',
'csrf_token_id' => 'authenticate'
]);
}
public function getBlockPrefix()
{
return ''; // return an empty string here
}
}

25
src/Form/BraceletType.php Normal file
View File

@@ -0,0 +1,25 @@
<?php
namespace App\Form;
use App\Entity\Bracelet;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class BraceletType extends DocumentType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
parent::buildForm($builder, $options);
$builder
->add('removingDate', null, ['label' => 'form_label_removing_date'])
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Bracelet::class,
]);
}
}

View File

@@ -0,0 +1,27 @@
<?php
namespace App\Form;
use App\Form\DocumentType;
use App\Entity\Certificate;
use App\Form\Type\ContentType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class CertificateType extends DocumentType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
parent::buildForm($builder, $options);
$builder
->add('content', ContentType::class) ;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Certificate::class,
]);
}
}

View File

@@ -0,0 +1,56 @@
<?php
namespace App\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
class ChangePasswordFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('plainPassword', RepeatedType::class, [
'type' => PasswordType::class,
'first_options' => [
'attr' => ['autocomplete' => 'new-password'],
'constraints' => [
new NotBlank([
'message' => 'form_constraint_please_enter_password',
]),
new Length([
'min' => 6,
'minMessage' => 'form_constraint_password_min_lenght_6_cars',
// max length allowed by Symfony for security reasons
'max' => 4096,
]),
],
'label' => 'New password',
],
'second_options' => [
'attr' => ['autocomplete' => 'new-password'],
'label' => 'Repeat Password',
],
'invalid_message' => 'form_constraint_password_mismatch',
// Instead of being set onto the object directly,
// this is read and encoded in the controller
'mapped' => false,
])
->add('submit', SubmitType::class, [
'label' => 'form_button_submit',
'attr' => ['class' => 'btn-primary'],
])
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([]);
}
}

31
src/Form/CommentType.php Normal file
View File

@@ -0,0 +1,31 @@
<?php
namespace App\Form;
use App\Entity\Comment;
use App\Form\Type\ContentType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
class CommentType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('content', ContentType::class)
->add('submit', SubmitType::class, [
'label' => 'form_button_submit',
'attr' => ['class' => 'btn-primary'],
])
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Comment::class,
]);
}
}

View File

@@ -0,0 +1,40 @@
<?php
namespace App\Form;
use App\Entity\Complaint;
use App\Form\DocumentType;
use App\Form\Type\ContentType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
class ComplaintType extends DocumentType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
parent::buildForm($builder, $options);
$builder
->add('versus', null, ['label' => 'form_label_versus', 'help' => 'form_help_versus'])
->add('content', ContentType::class)
->add('status', ChoiceType::class, [
'choices' => [
'form_choice_complaint_status_inprogress' => 'form_choice_complaint_status_inprogress',
'form_choice_complaint_status_waiting' => 'form_choice_complaint_status_waiting',
'form_choice_complaint_status_ended' => 'form_choice_complaint_status_ended',
'form_choice_complaint_status_discontinued' => 'form_choice_complaint_status_discontinued',
],
'label' => 'form_label_complaint_status',
'priority' => -800
])
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Complaint::class,
]);
}
}

42
src/Form/CriminalType.php Normal file
View File

@@ -0,0 +1,42 @@
<?php
namespace App\Form;
use App\Entity\Criminal;
use App\Form\DocumentType;
use App\Form\Type\ContentType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class CriminalType extends DocumentType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
parent::buildForm($builder, $options);
$builder
->add('article', null, ['label' => 'form_label_article', 'help' => 'form_help_article'])
->add('amountMoney', null, ['label' => 'form_label_amount', 'help' => 'form_help_amount'])
->add('amountTime', null, ['label' => 'form_label_time', 'help' => 'form_help_time'])
->add(
'accessorySentence',
ContentType::class,
['label' => 'form_label_accessorySentence',
'help' => 'form_help_accessorySentence',
'required' => false,
'attr' => ['style' => 'height: 200px;']
]
)
->add('content', ContentType::class, ['label' => 'form_label_informations', 'required' => false ])
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Criminal::class,
]);
}
}

224
src/Form/DirectoryType.php Normal file
View File

@@ -0,0 +1,224 @@
<?php
namespace App\Form;
use App\Entity\Directory;
use App\Form\Type\PhoneType;
use App\Form\Type\GenderType;
use App\Form\Type\HeightType;
use App\Form\Type\WeightType;
use App\Form\Type\AddressType;
use App\Form\Type\ContentType;
use App\Form\Type\GangListType;
use App\Form\Type\LastnameType;
use App\Form\Type\FirstnameType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Form\FormBuilderInterface;
use Vich\UploaderBundle\Form\Type\VichImageType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\BirthdayType;
class DirectoryType extends AbstractType
{
private $security;
public function __construct(Security $security)
{
$this->security = $security;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
/**
* @var User $user
*/
$user = $this->security->getUser();
$userPermissions = array_map('strtolower', $user->getMainRank()->getPermissions());
$builder
->add('firstname', FirstnameType::class)
->add('lastname', LastnameType::class)
->add('gender', GenderType::class)
->add(
'birthdate',
BirthdayType::class,
[
'label' => 'form_label_birthday',
'placeholder' => [
'year' => 'Year', 'month' => 'Month', 'day' => 'Day',
],
'required' => false
]
)
->add('phone', PhoneType::class)
->add('height', HeightType::class)
->add('weight', WeightType::class)
->add('address', AddressType::class, ['required' => false])
;
if ($user->getAdminMode() || in_array('general_legal_view', $userPermissions)) {
$builder
->add('gang', GangListType::class)
->add('wanted', null, ['label' => 'form_label_wanted'])
->add('wantedReason', null, ['label' => 'form_label_wantedReason', 'help' => 'form_help_wantedReason'])
;
}
if ($user->getAdminMode() || in_array('general_medical_view', $userPermissions)) {
$builder
->add('dead', null, ['label' => 'form_label_dead', 'help' => 'form_help_wanted'])
->add(
'medicalFamilyHistory',
ContentType::class,
['label' => 'form_label_medical_family_history',
'help' => 'form_help_medical_family_history',
'required' => false,
'attr' => ['style' => 'height: 400px;']
]
)
->add(
'medicalHistory',
ContentType::class,
['label' => 'form_label_medical_history', 'help' => 'form_help_medical_history',
'required' => false,
'attr' => ['style' => 'height: 400px;']
]
)
->add(
'medicalAllergies',
ContentType::class,
['label' => 'form_label_medical_allergies', 'help' => 'form_help_medical_allergies',
'required' => false,
'attr' => ['style' => 'height: 400px;']
]
)
->add(
'medicalBloodGroup',
null,
['label' => 'form_label_medical_blood_group', 'help' => 'form_help_medical_blood_group',
'required' => false
]
)
->add(
'medicalDrugs',
ContentType::class,
['label' => 'form_label_medical_drugs', 'help' => 'form_help_medical_drugs',
'required' => false,
'attr' => ['style' => 'height: 400px;']
]
)
->add(
'medicalAlcohol',
ContentType::class,
['label' => 'form_label_medical_alcohol', 'help' => 'form_help_medical_alcohol',
'required' => false,
'attr' => ['style' => 'height: 400px;']
]
)
->add(
'medicalTreatment',
ContentType::class,
['label' => 'form_label_medical_treatment','help' => 'form_help_medical_treatment',
'required' => false,
'attr' => ['style' => 'height: 400px;']
]
);
}
if ($user->getAdminMode() || in_array('general_legal_view', $userPermissions)) {
$builder->add('faceImageFile', VichImageType::class, [
'required' => false,
'allow_delete' => false,
'download_uri' => false,
'image_uri' => false,
'asset_helper' => true,
'label' => 'form_label_upload_facepicture'
])
->add('backImageFile', VichImageType::class, [
'required' => false,
'allow_delete' => false,
'download_uri' => false,
'image_uri' => false,
'asset_helper' => true,
'label' => 'form_label_upload_backpicture'
])
->add('leftImageFile', VichImageType::class, [
'required' => false,
'allow_delete' => false,
'download_uri' => false,
'image_uri' => false,
'asset_helper' => true,
'label' => 'form_label_upload_leftpicture'
])
->add('rightImageFile', VichImageType::class, [
'required' => false,
'allow_delete' => false,
'download_uri' => false,
'image_uri' => false,
'asset_helper' => true,
'label' => 'form_label_upload_rightpicture'
]);
}
$builder
->add('idCardImageFile', VichImageType::class, [
'required' => false,
'allow_delete' => false,
'download_uri' => false,
'image_uri' => false,
'asset_helper' => true,
'label' => 'form_label_upload_idcard'
])
->add('carLicenceImageFile', VichImageType::class, [
'required' => false,
'allow_delete' => false,
'download_uri' => false,
'image_uri' => false,
'asset_helper' => true,
'label' => 'form_label_upload_carlicence'
])
->add('motorcycleLicenceImageFile', VichImageType::class, [
'required' => false,
'allow_delete' => false,
'download_uri' => false,
'image_uri' => false,
'asset_helper' => true,
'label' => 'form_label_upload_motorcyclelicence'
])
->add('truckLicenceImageFile', VichImageType::class, [
'required' => false,
'allow_delete' => false,
'download_uri' => false,
'image_uri' => false,
'asset_helper' => true,
'label' => 'form_label_upload_trucklicence'
])
->add('boatLicenceImageFile', VichImageType::class, [
'required' => false,
'allow_delete' => false,
'download_uri' => false,
'image_uri' => false,
'asset_helper' => true,
'label' => 'form_label_upload_boatlicence'
])
->add('submit', SubmitType::class, [
'label' => 'form_button_submit',
'attr' => ['class' => 'btn-primary'],
])
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Directory::class,
]);
}
}

90
src/Form/DocumentType.php Normal file
View File

@@ -0,0 +1,90 @@
<?php
namespace App\Form;
use App\Entity\Document;
use App\Form\Type\AllowedGroupsType;
use Symfony\Component\Form\AbstractType;
use App\Form\Type\UserGroupSubGroupsType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
class DocumentType extends AbstractType
{
private TokenStorageInterface $TokenStorage;
public function __construct(TokenStorageInterface $TokenStorage)
{
$this->TokenStorage = $TokenStorage;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
/**
* @var Document $Document
*/
$Document = $builder->getData();
/**
* @var User $User
*/
$User = $this->TokenStorage->getToken()->getUser();
$builder
->add('title', null, [
'label' => 'form_label_title',
'priority' => 999
]);
if (!$Document->getIsPublic()) {
if ($Document->getMainGroup() == $User->getMainGroup()) {
$builder
->add(
'allowedGroups',
AllowedGroupsType::class,
[
'priority' => -900,
]
)
->add(
'allowedSubGroups',
UserGroupSubGroupsType::class,
[
'priority' => -900
]
);
}
}
$builder
->add(
'allowShare',
null,
[
'priority' => -900,
'label' => 'form_label_allowShare'
]
)
->add('submit', SubmitType::class, [
'label' => 'form_button_submit',
'priority' => -900,
'attr' => ['class' => 'btn-primary'],
])
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Document::class,
]);
}
}

79
src/Form/EmployeeType.php Normal file
View File

@@ -0,0 +1,79 @@
<?php
namespace App\Form;
use App\Entity\Rank;
use App\Entity\SubGroup;
use App\Entity\User;
use App\Form\Type\PhoneType;
use App\Repository\RankRepository;
use App\Repository\SubGroupRepository;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
class EmployeeType extends AbstractType
{
private TranslatorInterface $translator;
public function __construct(TranslatorInterface $translator)
{
$this->translator = $translator;
}
public function buildForm(FormBuilderInterface $builder, array $options): void
{
/**
* @var User $User
*/
$User = $builder->getData();
$UserGroup = $User->getMainGroup();
$builder
->add('phone', PhoneType::class)
->add('mainRank', EntityType::class, [
'class' => Rank::class,
'query_builder' => function (RankRepository $RankRepository) use ($UserGroup) {
return $RankRepository->createQueryBuilder('r')
->where('r.mainGroup =' . $UserGroup->getId())
->orderBy('r.power', 'DESC');
},
'choice_label' => 'name',
'label' => 'form_label_rank',
'placeholder' => $this->translator->trans('form_placeholder_group_and_rank'),
'required' => false,
'expanded' => true
])
->add('subGroups', EntityType::class, [
'class' => SubGroup::class,
'query_builder' => function (SubGroupRepository $SubGroupRepository) use ($UserGroup) {
return $SubGroupRepository->createQueryBuilder('sg')
->where('sg.mainGroup =' . $UserGroup->getId())
;
},
'choice_label' => 'name',
'label' => 'form_label_subgroups',
'required' => false,
'multiple' => true,
'expanded' => true
])
->add('submit', SubmitType::class, [
'label' => 'form_button_submit',
'attr' => ['class' => 'btn-primary'],
])
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => User::class,
]);
}
}

28
src/Form/FolderType.php Normal file
View File

@@ -0,0 +1,28 @@
<?php
namespace App\Form;
use App\Entity\Folder;
use App\Form\DocumentType;
use App\Form\Type\ContentType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class FolderType extends DocumentType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
parent::buildForm($builder, $options);
$builder
->add('content', ContentType::class, ['required' => false])
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Folder::class,
]);
}
}

34
src/Form/GangType.php Normal file
View File

@@ -0,0 +1,34 @@
<?php
namespace App\Form;
use App\Entity\Gang;
use App\Form\DocumentType;
use App\Form\Type\ContentType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class GangType extends DocumentType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
parent::buildForm($builder, $options);
$builder
->add(
'content',
ContentType::class,
['label' => 'form_label_informations',
'required' => false,
]
)
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Gang::class,
]);
}
}

View File

@@ -0,0 +1,28 @@
<?php
namespace App\Form;
use App\Form\DocumentType;
use App\Entity\Infringement;
use App\Form\Type\ContentType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class InfringementType extends DocumentType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
parent::buildForm($builder, $options);
$builder
->add('content', ContentType::class)
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Infringement::class,
]);
}
}

33
src/Form/JailType.php Normal file
View File

@@ -0,0 +1,33 @@
<?php
namespace App\Form;
use App\Entity\Jail;
use App\Form\DocumentType;
use App\Form\Type\ContentType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
class JailType extends DocumentType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
parent::buildForm($builder, $options);
$builder
->add('arrestedAt', null, ['label' => 'form_label_arrested_at', 'help' => 'form_help_arrested_at'])
->add('jailedAt', null, ['label' => 'form_label_jailed_at', 'help' => 'form_help_jailed_at'])
->add('lawyer', CheckboxType::class, ['label' => 'form_label_asked_for_lawyer', 'required' => false])
->add('medic', CheckboxType::class, ['label' => 'form_label_asked_for_medic', 'required' => false])
->add('content', ContentType::class)
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Jail::class,
]);
}
}

View File

@@ -0,0 +1,31 @@
<?php
namespace App\Form;
use App\Form\DocumentType;
use App\Form\Type\VehicleType;
use App\Entity\LicenceWithdrawal;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class LicenceWithdrawalType extends DocumentType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
parent::buildForm($builder, $options);
$builder
->add('type', VehicleType::class)
->add('until', null, ['label' => 'form_label_until', 'help' => 'form_help_until'])
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => LicenceWithdrawal::class,
]);
}
}

View File

@@ -0,0 +1,31 @@
<?php
namespace App\Form;
use App\Entity\User;
use App\Form\Type\RepeatedPasswordType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
class MePasswordType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('plainPassword', RepeatedPasswordType::class)
->add('submit', SubmitType::class, [
'label' => 'form_button_change_password',
'attr' => ['class' => 'btn-primary'],
])
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => User::class,
]);
}
}

52
src/Form/MeType.php Normal file
View File

@@ -0,0 +1,52 @@
<?php
namespace App\Form;
use App\Entity\User;
use App\Form\Type\PhoneType;
use App\Form\Type\LastnameType;
use App\Form\Type\FirstnameType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
class MeType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('firstname', FirstnameType::class, ['disabled' => true, 'help' => 'form_help_cant_edit_firstname'])
->add('lastname', LastnameType::class, ['disabled' => true, 'help' => 'form_help_cant_edit_lastname'])
->add('email', EmailType::class, [
'label' => false,
'attr' => ['placeholder' => 'form_placeholder_email'],
])
->add('phone', PhoneType::class)
->add('locale', ChoiceType::class, [
'choices' => [
'form_choice_default' => null,
'form_choice_english' => 'en',
'form_choice_french' => 'fr'
],
'expanded' => false,
'multiple' => false,
'label' => 'form_label_language',
])
->add('submit', SubmitType::class, [
'label' => 'form_button_update',
'attr' => ['class' => 'btn-primary'],
])
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => User::class,
]);
}
}

28
src/Form/MedicalType.php Normal file
View File

@@ -0,0 +1,28 @@
<?php
namespace App\Form;
use App\Entity\Medical;
use App\Form\DocumentType;
use App\Form\Type\ContentType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class MedicalType extends DocumentType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
parent::buildForm($builder, $options);
$builder
->add('content', ContentType::class)
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Medical::class,
]);
}
}

30
src/Form/MotdType.php Normal file
View File

@@ -0,0 +1,30 @@
<?php
namespace App\Form;
use App\Entity\Group;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
class MotdType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('motd', null, ['label' => false,'attr' => ['style' => 'height: 400px;']])
->add('submit', SubmitType::class, [
'label' => 'form_button_update_motd',
'attr' => ['class' => 'btn-primary'],
])
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Group::class,
]);
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace App\Form;
use App\Entity\User;
use App\Form\Type\GroupType;
use App\Form\Type\LastnameType;
use App\Form\Type\FirstnameType;
use App\Form\Type\RepeatedPasswordType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
class RegistrationFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('email', EmailType::class, [
'label' => false,
'attr' => ['placeholder' => 'form_placeholder_email'],
])
->add('firstName', FirstnameType::class)
->add('lastName', LastnameType::class)
->add('plainPassword', RepeatedPasswordType::class)
->add('mainGroup', GroupType::class)
->add('submit', SubmitType::class, [
'label' => 'form_button_register',
'attr' => ['class' => 'btn-primary'],
])
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => User::class,
]);
}
}

28
src/Form/ReportType.php Normal file
View File

@@ -0,0 +1,28 @@
<?php
namespace App\Form;
use App\Entity\Report;
use App\Form\DocumentType;
use App\Form\Type\ContentType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class ReportType extends DocumentType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
parent::buildForm($builder, $options);
$builder
->add('content', ContentType::class)
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Report::class,
]);
}
}

View File

@@ -0,0 +1,37 @@
<?php
namespace App\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
class ResetPasswordRequestFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('email', EmailType::class, [
'attr' => ['autocomplete' => 'email'],
'label' => 'form_label_email',
'constraints' => [
new NotBlank([
'message' => 'form_constraint_please_enter_email',
]),
],
])
->add('submit', SubmitType::class, [
'label' => 'form_button_submit',
'attr' => ['class' => 'btn-primary'],
])
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([]);
}
}

28
src/Form/SanctionType.php Normal file
View File

@@ -0,0 +1,28 @@
<?php
namespace App\Form;
use App\Entity\Sanction;
use App\Form\DocumentType;
use App\Form\Type\ContentType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class SanctionType extends DocumentType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
parent::buildForm($builder, $options);
$builder
->add('content', ContentType::class)
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Sanction::class,
]);
}
}

View File

@@ -0,0 +1,31 @@
<?php
namespace App\Form;
use App\Form\Type\SearchType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class SearchBarType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('subject', SearchType::class)
->setMethod('GET')
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'csrf_protection' => false
]);
}
public function getBlockPrefix()
{
return ''; // return an empty string here
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace App\Form;
use App\Form\DocumentType;
use App\Entity\Stolenvehicle;
use App\Form\Type\ContentType;
use App\Form\Type\VehicleType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class StolenvehicleType extends DocumentType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
parent::buildForm($builder, $options);
$builder
->add('type', VehicleType::class)
->add('numberplate', null, ['label' => 'form_label_numberplate'])
->add('model', null, ['label' => 'form_label_model'])
->add('color', null, ['label' => 'form_label_color'])
->add('content', ContentType::class, ['label' => 'form_label_informations', 'required' => false])
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Stolenvehicle::class,
]);
}
}

28
src/Form/TemplateType.php Normal file
View File

@@ -0,0 +1,28 @@
<?php
namespace App\Form;
use App\Entity\Template;
use App\Form\DocumentType;
use App\Form\Type\ContentType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class TemplateType extends DocumentType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
parent::buildForm($builder, $options);
$builder
->add('content', ContentType::class)
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Template::class,
]);
}
}

60
src/Form/TestType.php Normal file
View File

@@ -0,0 +1,60 @@
<?php
namespace App\Form;
use App\Entity\Document;
use App\Entity\User;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
class TestType extends AbstractType
{
private TokenStorageInterface $TokenStorage;
public function __construct(TokenStorageInterface $TokenStorage)
{
$this->TokenStorage = $TokenStorage;
}
public function buildForm(FormBuilderInterface $builder, array $options): void
{
/**
* @var User $user
*/
$User = $this->TokenStorage->getToken()->getUser();
dd($User);
$builder
->add('title', null, [
'label' => 'form_label_title',
'priority' => 999
]);
$builder
->add(
'allowShare',
null,
[
'priority' => -900,
'label' => 'form_label_allowShare'
]
)
->add('submit', SubmitType::class, [
'label' => 'form_button_submit',
'priority' => -900,
'attr' => ['class' => 'btn-primary'],
])
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Document::class,
]);
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace App\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
class AddressType extends AbstractType
{
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'attr' => ['style' => 'height: 200px;'],
'label' => 'form_label_address'
]);
}
public function getParent(): string
{
return TextareaType::class;
}
}

View File

@@ -0,0 +1,33 @@
<?php
namespace App\Form\Type;
use App\Entity\Group;
use App\Repository\GroupRepository;
use Symfony\Component\Form\AbstractType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\OptionsResolver\OptionsResolver;
class AllowedGroupsType extends AbstractType
{
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'class' => Group::class,
'query_builder' => function (GroupRepository $GroupRepository) {
return $GroupRepository->createQueryBuilder('r')
->orderBy('r.name', 'ASC');
},
'multiple' => true,
'expanded' => true,
'choice_label' => 'name',
'label' => 'form_label_allowedgroups',
'help' => 'form_help_allowedgroups',
]);
}
public function getParent(): string
{
return EntityType::class;
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace App\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
class ContentType extends AbstractType
{
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'attr' => ['style' => 'height: 600px;'],
'label' => 'form_label_content'
]);
}
public function getParent(): string
{
return TextareaType::class;
}
}

View File

@@ -0,0 +1,24 @@
<?php
namespace App\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\TextType;
class FirstnameType extends AbstractType
{
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'attr' => ['placeholder' => 'form_placeholder_firstname'],
'help' => 'form_help_firstname',
'label' => false
]);
}
public function getParent(): string
{
return TextType::class;
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace App\Form\Type;
use App\Entity\Gang;
use App\Repository\GangRepository;
use Symfony\Component\Form\AbstractType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\OptionsResolver\OptionsResolver;
class GangListType extends AbstractType
{
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'class' => Gang::class,
'query_builder' => function (GangRepository $GangRepository) {
return $GangRepository->createQueryBuilder('g')
->orderBy('g.title', 'ASC');
},
'choice_label' => 'title',
'placeholder' => 'form_placeholder_gang',
'help' => 'form_help_gang',
'label' => false,
'required' => false
]);
}
public function getParent(): string
{
return EntityType::class;
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace App\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\TextType;
class GenderType extends AbstractType
{
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'attr' => ['placeholder' => 'form_placeholder_gender'],
'help' => 'form_help_gender',
'label' => false,
'required' => true
]);
}
public function getParent(): string
{
return TextType::class;
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace App\Form\Type;
use App\Entity\Group;
use App\Repository\GroupRepository;
use Symfony\Component\Form\AbstractType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\OptionsResolver\OptionsResolver;
class GroupType extends AbstractType
{
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'class' => Group::class,
'query_builder' => function (GroupRepository $GroupRepository) {
return $GroupRepository->createQueryBuilder('r')
->orderBy('r.name', 'ASC');
},
'choice_label' => 'name',
'placeholder' => 'form_placeholder_group',
'help' => 'form_help_group',
'label' => false,
'required' => true
]);
}
public function getParent(): string
{
return EntityType::class;
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace App\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\TextType;
class HeightType extends AbstractType
{
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'attr' => ['placeholder' => 'form_placeholder_height'],
'help' => 'form_help_height',
'label' => false,
'required' => false
]);
}
public function getParent(): string
{
return TextType::class;
}
}

View File

@@ -0,0 +1,24 @@
<?php
namespace App\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\TextType;
class LastnameType extends AbstractType
{
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'attr' => ['placeholder' => 'form_placeholder_lastname'],
'help' => 'form_help_lastname',
'label' => false
]);
}
public function getParent(): string
{
return TextType::class;
}
}

View File

@@ -0,0 +1,48 @@
<?php
namespace App\Form\Type;
use App\PermissionsList;
use Symfony\Component\Form\AbstractType;
use Symfony\Contracts\Cache\ItemInterface;
use Symfony\Contracts\Cache\CacheInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
class PermissionsType extends AbstractType
{
private CacheInterface $cache;
public function __construct(CacheInterface $CacheInterface)
{
$this->cache = $CacheInterface;
}
public function configureOptions(OptionsResolver $resolver): void
{
if ($_ENV['APP_ENV'] === 'dev') {
$permissionList = new PermissionsList();
$permissions = $permissionList->getPermissionList();
} else {
$permissions = $this->cache->get('vision_permissions', function (ItemInterface $item) {
$permissionList = new PermissionsList();
return $permissionList->getPermissionList();
});
}
$resolver->setDefaults([
'choices' => $permissions,
'expanded' => true,
'multiple' => true,
'label' => 'form_label_permissions',
'attr' => ['class' => 'form-switch'],
]);
}
public function getParent(): string
{
return ChoiceType::class;
}
}

View File

@@ -0,0 +1,29 @@
<?php
namespace App\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Validator\Constraints\Regex;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\TelType;
class PhoneType extends AbstractType
{
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'constraints' => [
new Regex('/^[0-9]*$/', 'form_constraint_digit_only')
],
'attr' => ['placeholder' => 'form_placeholder_phone'],
'help' => 'form_help_phone',
'label' => false,
'required' => false
]);
}
public function getParent(): string
{
return TelType::class;
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace App\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
class RepeatedPasswordType extends AbstractType
{
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'type' => PasswordType::class,
'mapped' => false,
'invalid_message' => 'form_constraint_password_mismatch',
'options' => ['attr' => ['class' => 'password-field']],
'required' => true,
'first_options' => ['label' => false, 'attr' => ['placeholder' => 'form_placeholder_password']],
'second_options' => ['label' => false, 'attr' => ['placeholder' => 'form_placeholder_password_repeat']],
'constraints' => [
new NotBlank([
'message' => 'form_constraint_please_enter_password',
]),
new Length([
'min' => 6,
'minMessage' => 'form_constraint_password_min_lenght_6_cars',
// max length allowed by Symfony for security reasons
'max' => 4096,
]),
]
]);
}
public function getParent(): string
{
return RepeatedType::class;
}
}

View File

@@ -0,0 +1,24 @@
<?php
namespace App\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\TextType;
class SearchType extends AbstractType
{
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'label' => false,
'required' => false,
'help' => 'form_help_search'
]);
}
public function getParent(): string
{
return TextType::class;
}
}

View File

@@ -0,0 +1,43 @@
<?php
namespace App\Form\Type;
use App\Entity\SubGroup;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Security\Core\Security;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\OptionsResolver\OptionsResolver;
class SubGroupsType extends AbstractType
{
private $security;
public function __construct(Security $security)
{
$this->security = $security;
}
public function configureOptions(OptionsResolver $resolver): void
{
/**
* @var User $user
*/
$user = $this->security->getUser();
$resolver->setDefaults([
'class' => SubGroup::class,
'multiple' => true,
'expanded' => true,
'choice_label' => 'name',
'label' => 'form_label_allowedsubgroups',
'help' => 'form_help_allowedsubgroups',
]);
}
public function getParent(): string
{
return EntityType::class;
}
}

View File

@@ -0,0 +1,44 @@
<?php
namespace App\Form\Type;
use App\Entity\SubGroup;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Security\Core\Security;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\OptionsResolver\OptionsResolver;
class UserGroupSubGroupsType extends AbstractType
{
private $security;
public function __construct(Security $security)
{
$this->security = $security;
}
public function configureOptions(OptionsResolver $resolver): void
{
/**
* @var User $user
*/
$user = $this->security->getUser();
$resolver->setDefaults([
'class' => SubGroup::class,
'choices' => $user->getmainGroup()->getSubGroups(),
'multiple' => true,
'expanded' => true,
'choice_label' => 'name',
'label' => 'form_label_allowedsubgroups',
'help' => 'form_help_allowedsubgroups',
]);
}
public function getParent(): string
{
return EntityType::class;
}
}

View File

@@ -0,0 +1,44 @@
<?php
namespace App\Form\Type;
use App\Entity\SubGroup;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Security\Core\Security;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\OptionsResolver\OptionsResolver;
class UserSubGroupsType extends AbstractType
{
private $security;
public function __construct(Security $security)
{
$this->security = $security;
}
public function configureOptions(OptionsResolver $resolver): void
{
/**
* @var User $user
*/
$user = $this->security->getUser();
$resolver->setDefaults([
'class' => SubGroup::class,
'choices' => $user->getSubGroups(),
'multiple' => true,
'expanded' => true,
'choice_label' => 'name',
'label' => 'form_label_allowedsubgroups',
'help' => 'form_help_allowedsubgroups',
]);
}
public function getParent(): string
{
return EntityType::class;
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\TextType;
class UsernameType extends AbstractType
{
public function configureOptions(OptionsResolver $resolver): void
{
}
public function getParent(): string
{
return TextType::class;
}
}

View File

@@ -0,0 +1,32 @@
<?php
namespace App\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
class VehicleType extends AbstractType
{
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'choices' => [
'form_choice_car' => 'form_choice_car',
'form_choice_motorcycle' => 'form_choice_motorcycle',
'form_choice_plane' => 'form_choice_plane',
'form_choice_boat' => 'form_choice_boat',
'form_choice_helicopter' => 'form_choice_helicopter',
'form_choice_bike' => 'form_choice_bike',
'form_choice_truck' => 'form_choice_truck',
'form_choice_other' => 'form_choice_other'
],
'label' => 'form_label_vehicle_type',
]);
}
public function getParent(): string
{
return ChoiceType::class;
}
}

Some files were not shown because too many files have changed in this diff Show More