<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
namespace App\Controller\Utils;
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\DependencyInjection\ContainerInterface;
//
//use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\Form\Extension\Core\Type\TextType;
//use Symfony\Component\Form\Extension\Core\Type\HiddenType;
//use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
//use Symfony\Component\Form\Extension\Core\Type\IntegerType;
//use Symfony\Component\Form\Extension\Core\Type\DateType;
//use Symfony\Component\Form\Extension\Core\Type\EmailType;
//use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Validator\Constraints\File;
//use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\HttpFoundation\RequestStack;
//use Symfony\Component\Form\Extension\Core\Type\TextareaType;
//use Symfony\Component\Finder\Finder;
//use Symfony\Component\Security\Core\User\UserInterface;
//use Symfony\Component\HttpFoundation\File\UploadedFile;
use Doctrine\ORM\EntityManagerInterface;
//use App\Bundle\Model\Utility;
//use Symfony\Component\Security\Core\Encoder\MessageDigestPasswordEncode;
//use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
//
use App\Service\UtilityServices;
use App\Service\PasswordServices;
use App\Form\Type\UserType;
//use App\Form\Type\RegistrationFormType;
use App\Entity\User;
//
//use Ramsey\Uuid\Uuid;
use Symfony\Component\Uid\Uuid;
use Symfony\Component\Uid\NilUuid;
//
//use SunCat\MobileDetectBundle\mobiledetectlib\MobileDetect as MD;
//use SunCat\MobileDetectBundle\DeviceDetector\MobileDetector;
//use App\Controller\EntityManagerInterface;
//use Symfony\Component\HttpKernel\Exception\HttpException;
//use SunCat\MobileDetectBundle\MobileDetectBundle\MobileDetect;
/**
* Description of adminController
*
* @author efaneuf2
*/
class adminController extends AbstractController {
private $em;
private $params;
private $mobileDetector;
private $websiterooturl;
private $requestStack;
private $baseUrl;
private $baseURLUC;
public function __construct(ParameterBagInterface $params, EntityManagerInterface $em, RequestStack $requestStack, string $projectDir) {
//$this->mobileDetector = $mobileDetector;
$this->params = $params;
$this->em = $em;
//dd($params);
$this->requestStack = $requestStack;
$request = $this->requestStack->getCurrentRequest();
$this->baseUrl = $request->getSchemeAndHttpHost();
$this->baseURLUC = strtoupper(str_replace('https://', '', $this->baseUrl));
$this->websiterooturl = $projectDir;
}
/**
* @Route("/admin/addUserByList", name="adduserbylist")
*/
public function addUserbylist(Request $request, UserPasswordEncoderInterface $passwordEncoder) {
if (!$this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) {
return new RedirectResponse('/login');
}
// fetch a list file.
// Columns (comma seperated)<br>
// 1 firstname middle name,<br>
// 2 isTeacher (0 or 1),<br>
// 3 isDeceased (0 or 1),<br>
// 4 death date,<br>
// 5 birthday (blank if not known),<br>
$defaultData = ['message' => 'Type your message here'];
$Repository = $this->getDoctrine()->getRepository(User::class);
$form = $this->createFormBuilder($defaultData)
->add('theFilename', FileType::class, [
'label' => 'User List (TXT file)',
// unmapped means that this field is not associated to any entity property
'mapped' => false,
// make it optional so you don't have to re-upload the PDF file
// every time you edit the Product details
'required' => false,
// unmapped fields can't define their validation using annotations
// in the associated entity, so you can use the PHP constraint classes
'constraints' => [
new File([
'maxSize' => '1024k',
'mimeTypes' => [
'text/plain',
],
'mimeTypesMessage' => 'Please upload a valid TXT document',
])
],
])
->add('send', SubmitType::class)
->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
// this will be the special name that is moved up to the server.
// We really do not need the PC name. We are going to immeadiatly
// process this files rows anyway
$txtfile = $form->get('theFilename')->getData();
if ($txtfile) {
$path_parts = pathinfo($txtfile->getClientOriginalName());
//echo $path_parts['dirname'], "<br>";
//echo $path_parts['basename'], "<br>";
//echo $path_parts['extension'], "<br>";
//echo $path_parts['filename'], "<br>";
//echo $txtfile, "<br>";
$handle = fopen($txtfile, "r");
if ($handle) {
while (($line = fgets($handle)) !== false) {
$cleanline = trim($line);
if ($cleanline != '') {
$lineAr = explode(",", $line);
// if sizeof the array is not 5 items, issue fail
$sz = sizeof($lineAr);
if ($sz < 5) {
echo "file has invalid format ($sz columns found)<br>";
die();
} else {
//echo "Name: " . $lineAr[0] . "<br>";
// split name into 2 or 3 parts
$nmPartsAR = explode(" ", $lineAr[0]);
// if (sizeof($nmPartsAR) == 2) {
// echo "First Name:" . $nmPartsAR[0] . "<br>";
// echo "Last Name:" . $nmPartsAR[1] . "<br>";
// } elseif (sizeof($nmPartsAR) == 3) {
// echo "First Name:" . $nmPartsAR[0] . "<br>";
// echo "Middle Name:" . $nmPartsAR[1] . "<br>";
// echo "Last Name:" . $nmPartsAR[2] . "<br>";
// } else {
// echo "Failed to split name<br>";
// }
//echo "Is A Teacher:" . (($lineAr[1] == 1) ? 'YES' : 'NO') . "<br>";
//echo "Is Deceased:" . (($lineAr[2] == 1) ? 'YES' : 'NO') . "<br>";
//if ($lineAr[2] == 1) {
// echo "When Died:" . $lineAr[3] . "<br>";
//}
//echo "Birthday:" . $lineAr[4] . "<br><br>";
// check database and see if this user is already there. If not add them
//$User->setRoles(['ROLE_USER']); // set the basic access always
if (sizeof($nmPartsAR) == 2) {
$SearchUser = $Repository->findUserbyName(strtolower($nmPartsAR[0]), strtolower($nmPartsAR[1]));
} elseif (sizeof($nmPartsAR) == 3) {
$SearchUser = $Repository->findUserbyName(strtolower($nmPartsAR[0]), strtolower($nmPartsAR[2]));
}
if ($SearchUser) {
//dd($SearchUser);
echo "This user is already in the database<hr><br>";
} else {
//echo "We need to add this user<hr><br>Adding them now<br>";
if (sizeof($nmPartsAR) == 2) {
$Repository->SetUser($nmPartsAR[0], "", $nmPartsAR[1], $lineAr[1], $lineAr[2], $lineAr[3], $passwordEncoder);
} elseif (sizeof($nmPartsAR) == 3) {
$Repository->SetUser($nmPartsAR[0], $nmPartsAR[1], $nmPartsAR[2], $lineAr[1], $lineAr[2], $lineAr[3], $passwordEncoder);
}
}
//echo $line."<br>";
}
} //else {
// echo "Found blank line<br>";
// }
}
fclose($handle);
} else {
// error opening the file.
echo "ERROR<br>";
}
//die();
}
$Users = $Repository->findAllUsersByName();
return $this->render('admin/users.html.twig', ['users' => $Users]);
}
return $this->render('admin/userFlatFileLoader.html.twig', ['form' => $form->createView()]);
}
/**
* @Route("/forgotpassword", name="forgotpassword")
*/
public function forgotPassword(
//SessionInterface $session,
PasswordServices $pwdgen,
//AuthorizationCheckerInterface $authChecker,
UtilityServices $utils,
UserPasswordEncoderInterface $passwordEncoder,
Request $request) {
$User = new User();
$form = $this->createForm(UserType::class, $User,
[
'UtilityServices' => $utils,
'generateStrongPasswordSvc' => $pwdgen,
'editmode' => true,
'editlabel' => 'Add User',
'em' => $this->get('doctrine')->getManager(),
'formstyle' => 'long',
'nextuserid' => 0
]
)
->add('username', TextType::class, ['label' => 'username or email '])
->add('save', SubmitType::class, ['label' => 'Get New Password'])
;
// $form->get('allowEmail')->setData(true);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
// is the username or password registered with us
// YES
// generate a unique ID to send to user
// save this unique ID into a column in the user account we located
// create email
//NO
// do nothing
return $this->render('security/forgotPasswordMsgSent.html.twig');
}
return $this->render('security/forgotPassword.html.twig', ['form' => $form->createView()]);
}
/**
* @Route("/", name="homepage")
*/
public function defaultScreen(Request $request): Response {
// $name = $request->query->get('hello')
//$mobileDetector = $this->get('mobile_detect.mobile_detector');
//$mobileDetector = $md;
//$mobileDetector->isMobile();
//$mobileDetector->isTablet();
return $this->render('default.html.twig');
}
/**
* @Route("/about", name="about")
*/
public function about(Request $request): Response {
return $this->render('about.html.twig');
}
/**
* @Route("/maintenance", name="maintenance")
*/
public function maintenance(Request $request): Response {
return $this->render('maintenanceMode.html.twig');
}
/**
* @Route("/tos", name="tos")
*/
public function tos(Request $request): Response {
return $this->render('TOS.html.twig', [
'SCN' => 'SJC',
'FCN' => 'SJC Creations',
'WSURL' => $this->websiterooturl,
'SWSN' => $this->baseURLUC,
'CONTACTEMAIL' => 'summerlinearl AT gmail.com',
'SITEALIAS' => $this->baseURLUC,
'EFFDATE' => 'April 1st, 2020'
]);
}
/**
* @Route("/copyright", name="copyright")
*/
public function copyright(Request $request): Response {
return $this->render('copyright.html.twig', [
'SCN' => 'SJC',
'FCN' => 'SJC Creations',
'WSURL' => $this->websiterooturl,
'SWSN' => $this->baseURLUC,
'CONTACTEMAIL' => 'summerlinearl AT gmail.com',
'SITEALIAS' => $this->baseURLUC,
'EFFDATE' => 'April 1st, 2020'
]);
}
/**
* @Route("/privacy", name="privacy")
*/
public function privacy(Request $request): Response {
return $this->render('privacy.html.twig', [
'SCN' => 'SJC',
'FCN' => 'SJC Creations',
'WSURL' => $this->websiterooturl,
'SWSN' => $this->baseURLUC,
'CONTACTEMAIL' => 'summerlinearl AT gmail.com',
'SITEALIAS' => $this->baseURLUC,
'EFFDATE' => 'April 1st, 2020'
]);
}
/**
* @Route("/admin/addUser", name="adduser")
*/
public function addUser(
//SessionInterface $session,
PasswordServices $pwdgen,
//AuthorizationCheckerInterface $authChecker,
UtilityServices $utils,
UserPasswordEncoderInterface $passwordEncoder,
Request $request
) {
if (!$this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) {
return new RedirectResponse('/login');
}
$Repository = $this->getDoctrine()->getRepository(User::class);
$User = new User();
// these 3 items are set this way by default in the User class
$User->setRoles(['ROLE_USER']); // set the basic access always
$nextUserID = $Repository->getNextUserID();
//$uuid = Uuid::v4();
//$User->setId($uuid->toBase32());
//dd($User);
$form = $this->createForm(UserType::class, $User,
[
'UtilityServices' => $utils,
'generateStrongPasswordSvc' => $pwdgen,
'editmode' => true,
'editlabel' => 'Add User',
'em' => $this->get('doctrine')->getManager(),
'formstyle' => 'long',
'nextuserid' => $nextUserID
]
)
->add('password', RepeatedType::class, [
'required' => true,
'invalid_message' => 'The password fields must match.',
'type' => PasswordType::class,
'first_options' => ['label' => 'Password'],
'second_options' => [
'label' => 'Confirm Password']
]
)
->add('save', SubmitType::class, ['label' => 'Save'])
;
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
if (!empty(trim($form->get('password')->getData()))) {
$new_password = $form->get('password')->getData();
$User->setPassword(
$passwordEncoder->encodePassword($User, $new_password)
);
}
//$User = $this->get('security.token_storage')->getToken()->getUser();
//$UserId = $User->getId();
$uuid = Uuid::v4();
$uuid_rfc4122 = $uuid->toRfc4122(); // string(36) "d9e7a184-5d5b-11ea-a62a-3499710062d0"
$uuid_binary = $uuid->toBinary(); // string(16) "\xd9\xe7\xa1\x84\x5d\x5b\x11\xea\xa6\x2a\x34\x99\x71\x00\x62\xd0"
$uuid_base32 = $uuid->toBase32(); // string(26) "6SWYGR8QAV27NACAHMK5RG0RPG"
//$uuid_base58 = $uuid->toBase58(); // string(22) "TuetYWNHhmuSQ3xPoVLv9M"
//dd($uuidbinday);
$User->setId($uuid_base32);
//dd($uuid_base32);
$User->setCreatedatuserid($uuid_base32);
$User->setUpdatedatuserid($uuid_base32);
$currentdate = new \DateTime('now');
$User->setCreatedate($currentdate);
$User->setModificationdate($currentdate);
$User->setRoles2(implode(",", $form->get('roles')->getData()));
if (!$User->getRoles2()) {
$User->setRoles2('ROLE_USER');
}
$this->em->persist($User);
$this->em->flush();
//$Repository = $this->getDoctrine()->getRepository(user::class);
//$Users = $Repository->findAll();
$Users = $Repository->findAllUsersByName();
return $this->render('admin/users.html.twig', ['users' => $Users]);
}
return $this->render('admin/userAdd.html.twig', ['form' => $form->createView(), 'editmode' => false]);
}
/**
* @Route("/edituser/{id}", name="edituser")
*/
public function editUser(
//SessionInterface $session,
PasswordServices $pwdgen,
//AuthorizationCheckerInterface $authChecker,
UtilityServices $utils,
Request $request,
UserPasswordEncoderInterface $passwordEncoder,
$id): Response {
if (!$this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) {
return new RedirectResponse('/login');
}
//$currentdate = new \DateTime('now');
$Repository = $this->getDoctrine()->getRepository(User::class);
// convert the 32 bit binary number in the database to the
// uuid format we normally like to see
$uuid = Uuid::fromString($id);
$uuid_rfc4122 = $uuid->toRfc4122(); // string(36) "d9e7a184-5d5b-11ea-a62a-3499710062d0"
$uuid_binary = $uuid->toBinary(); // string(16) "\xd9\xe7\xa1\x84\x5d\x5b\x11\xea\xa6\x2a\x34\x99\x71\x00\x62\xd0"
$uuid_base32 = $uuid->toBase32(); // string(26) "6SWYGR8QAV27NACAHMK5RG0RPG"
//$uuid_base58 = $uuid->toBase58(); // string(22) "TuetYWNHhmuSQ3xPoVLv9M"
//dd($uuidbinday);
// 34656139-3739-3566-6335-643834313038
// 4ea9795fc5d84108
//echo $id . "<br>";
//dd($uuid_binary);
// need to convert rfc4122 to binary to do the test
$User = $Repository->find($uuid_binary);
// we need, on EDIT, to set the password fields to blank
//dd($User);
$uuid_next = $Repository->getNextUserID();
//$nextUserID = $uuid_next->toBase32();
//dd($nextUserID);
$isActive = $User->getIsActive();
//dd($isActive);
if (!$User) {
throw $this->createNotFoundException('No User found for ID ' . $id);
}
$form = $this->createForm(UserType::class, $User,
[
'UtilityServices' => $utils,
'generateStrongPasswordSvc' => $pwdgen,
'editmode' => true,
'editlabel' => 'Add User',
'em' => $this->get('doctrine')->getManager(),
'formstyle' => 'long',
'nextuserid' => $uuid_next
]
)
->add('password2', RepeatedType::class, [
'required' => false,
'mapped' => false,
'invalid_message' => 'The password fields must match.',
'type' => PasswordType::class,
'first_options' => [
'label' => 'Password',
'always_empty' => true,
'attr' => [
"autocomplete" => "off",
"disabled" => "disabled",
"style" => [
"background-color" => "lightgray!Important"
]
]
],
'second_options' => [
'label' => 'Confirm Password',
'always_empty' => true,
'attr' => [
"autocomplete" => "off",
"disabled" => "disabled",
"style" => [
"background-color" => "lightgray!Important"
]
]
],
'attr' => [
"style" => [
"background-color" => "lightgray!Important"
]
],
])
->add('save', SubmitType::class, array('label' => 'Save'));
// Remove the password field when editing the user
// Otherwise it must be entered each time the user is edited
// We can change the password via a special edit-user-password page
$form->remove('password');
$form->handleRequest($request);
//$errorStr = $form->getErrors();
if ($form->isSubmitted() && $form->isValid()) {
try {
// if the user passes in a new password, change it. Otherwise just ignore the password field
if (!empty(trim($form->get('password2')->getData()))) {
$new_password = $form->get('password2')->getData();
$User->setPassword(
$passwordEncoder->encodePassword($User, $new_password)
);
}
$so = $form->get('SignificantOtherID')->getData();
if ($so) {
$User->setSignificantOtherID($so->getID());
} else {
//$User->setSignificantOtherID(null);
}
//dd($User);
$mp = $form->get('mobilephone')->getData();
if ($mp) {
$User->setMobilephone($mp);
} else {
$User->setMobilephone(' ');
}
$loggedInuser = $this->get('security.token_storage')->getToken()->getUser();
$loggedinUserId = $loggedInuser->getId();
//$User->setCreatedatuserid($uuid_base32);
$User->setUpdatedatuserid($loggedinUserId);
$currentdate = new \DateTime('now');
//$User->setCreatedate($currentdate);
$User->setLasteditdate($currentdate);
$User->setModificationdate($currentdate);
if (!$this->get('security.authorization_checker')->isGranted('ROLE_ADMIN') AND
!$this->get('security.authorization_checker')->isGranted('ROLE_ASSTADMIN')) {
if ($isActive == true) {
$User->setIsActive(true);
} else {
$User->setIsActive(false);
}
//echo "IsActive: ".$isActive."<br><br><br>";
//dd($User);
}
$this->em->persist($User);
$this->em->flush();
} catch (Exception $e) {
$error = (string) $form->getErrors(true, false);
$errstring = var_export($this->getErrorMessages($form), true);
return $this->render('failure.html.twig', array(
'error' => $error,
' catch' => $e->getMessage(),
'allerrors' => $errstring));
}
// submit button pressed and any validations we had have passed the test.
// it has flushed the data back to the database so insert this form entry
// so we will now show the main page displaying our new entry at the top
//$Users = $Repository->findAll();
//$Users = $Repository->findBy([], ['lastname' => 'ASC', 'firstname' => 'ASC']);
$Users = $Repository->findAllUsersByName();
return $this->render('admin/users.html.twig', ['users' => $Users]);
} else if ($form->isSubmitted()) {
//submit button was pressed, but there is something wrong with the entry on the form
$errors = (string) $form->getErrors(true, false);
$errstring = var_export($this->getErrorMessages($form), true);
return $this->render('failure.html.twig', array(
'errors' => $errors,
'allerrors' => $errstring));
}
// Display the entry form
// this form should display all users, let us edit details on a user,
// return with which user and save the details
return $this->render('admin/userEdit.html.twig', ['user' => $User, 'form' => $form->createView(), 'editmode' => true]);
}
/**
* @Route("/delete/participant/{id}", name="delete_participant")
*/
public function delUser(
SessionInterface $session,
PasswordServices $pwdgen,
//AuthorizationCheckerInterface $authChecker,
UtilityServices $utils,
UserPasswordEncoderInterface $passwordEncoder,
Request $request,
$id) {
if (!$this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) {
return new RedirectResponse('/login');
}
$Repository = $this->getDoctrine()->getRepository(User::class);
$User = $Repository->find($id);
$nextUserID = $Repository->getNextUserID();
if (!$User) {
throw $this - createNotFoundException('No User found for ID ' . $id);
}
$form = $this->createForm(UserType::class, $User,
[
'UtilityServices' => $utils,
'generateStrongPasswordSvc' => $pwdgen,
'editmode' => true,
'editlabel' => 'Add User',
'em' => $this->get('doctrine')->getManager(),
'formstyle' => 'long',
'nextuserid' => $nextUserID
]
)
->add('save', SubmitType::class, [
'label' => 'Delete',
'attr' => array(
'onClick' => 'return confirm("Are you sure?");',
)
])
->add('cancel', SubmitType::class, ['label' => 'cancel'])
;
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
if ($form->getClickedButton() === $form->get('cancel')) {
return $this->redirectToRoute('listparticipants');
} else {
$this->em->remove($User);
$this->em->flush();
return $this->redirectToRoute('listparticipants');
}
}
return $this->render('admin/userDel.html.twig', ['form' => $form->createView()]);
}
/**
* @Route("/finduserbyemail", name="find_user_by_email")
*/
public function findUserByEmail(
SessionInterface $session,
PasswordServices $pwdgen,
//AuthorizationCheckerInterface $authChecker,
UtilityServices $utils,
UserPasswordEncoderInterface $passwordEncoder,
Request $request,
) {
if (!$this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) {
return new RedirectResponse('/login');
}
$defaultData = ['message' => 'Type your message here'];
$form = $this->createFormBuilder($defaultData)
->add('emails', TextType::class, ['mapped' => false])
->add('save', SubmitType::class, ['label' => 'Find Them',])
->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
//$data = $form->getData();
$emails = $form->get('emails')->getData();
$Repository = $this->getDoctrine()->getRepository(User::class);
$User = $Repository->findUserByEmail($emails);
return $this->render('admin/showusersemail.html.twig', ['users' => $User]);
} elseif ($form->isSubmitted() && !$form->isValid()) {
return $this->render('admin/showusersemail_failure.html.twig');
}
return $this->render('admin/finduserbyemail.html.twig', ['form' => $form->createView()]);
}
/**
* @Route("/listparticipants", name="listparticipants")
*/
public function getUsers(Request $request): Response {
if (!$this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) {
return new RedirectResponse('/login');
}
// https://symfony.com/doc/current/doctrine.html
//$currentdate = new \DateTime('now');
$Repository = $this->getDoctrine()->getRepository(User::class);
//$Users = $Repository->findBy([], ['lastname' => 'ASC', 'firstname' => 'ASC']);
$Users = $Repository->findAllUsersByName();
//dd($Users);
return $this->render('admin/users.html.twig', ['users' => $Users]);
}
/**
* @Route("/listparticipantsInactiveFirst", name="listparticipants_inactive_first")
*/
public function getUsersInactiveFirst(Request $request): Response {
if (!$this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) {
return new RedirectResponse('/login');
}
// https://symfony.com/doc/current/doctrine.html
//$currentdate = new \DateTime('now');
$Repository = $this->getDoctrine()->getRepository(User::class);
//$Users = $Repository->findBy([], ['lastname' => 'ASC', 'firstname' => 'ASC']);
$Users = $Repository->findAllUsersByNameInactiveFirst();
//dd($Users);
return $this->render('admin/users.html.twig', ['users' => $Users]);
}
/**
* @Route("/listparticipantsAllowEmailFirst", name="listparticipants_allow_email_first")
*/
public function getUsersAllowEmailFirst(Request $request): Response {
if (!$this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) {
return new RedirectResponse('/login');
}
// https://symfony.com/doc/current/doctrine.html
//$currentdate = new \DateTime('now');
$Repository = $this->getDoctrine()->getRepository(User::class);
//$Users = $Repository->findBy([], ['lastname' => 'ASC', 'firstname' => 'ASC']);
$Users = $Repository->findAllUsersByNameAllowEmailFirst();
//dd($Users);
return $this->render('admin/users.html.twig', ['users' => $Users]);
}
/**
* @Route("/contactus", name="contactus")
*/
public function contactus() {
return $this->render('security/contactus.html.twig');
}
private function getErrorMessages(\Symfony\Component\Form\Form $form) {
$errors = array();
if ($form->count() > 0) {
foreach ($form->all() as $child) {
/**
* @var \Symfony\Component\Form\Form $child
*/
if (!$child->isValid()) {
$errors[$child->getName()] = $this->getErrorMessages($child);
}
}
} else {
/**
* @var \Symfony\Component\Form\FormError $error
*/
foreach ($form->getErrors() as $key => $error) {
$errors[] = $error->getMessage();
}
}
return $errors;
}
}