1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ribs\RibsAdminBundle\Controller; |
4
|
|
|
|
5
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
6
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
7
|
|
|
use Symfony\Component\HttpFoundation\Response; |
8
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
9
|
|
|
|
10
|
|
|
class AccountsController extends Controller |
11
|
|
|
{ |
12
|
|
|
//-------------------------------------------- DISPLAY VIEWS ---------------------------------------------------------------// |
13
|
|
|
/** |
14
|
|
|
* @Route("/accounts", name="ribsadmin_accounts") |
15
|
|
|
* @return Response function that return a list of all users that are not archived and different of current accout |
16
|
|
|
*/ |
17
|
|
|
public function AccountsListAction(): Response |
18
|
|
|
{ |
19
|
|
|
$em = $this->getDoctrine()->getManager(); |
20
|
|
|
$current_account = $this->getUser()->getUser(); |
21
|
|
|
|
22
|
|
|
$users = $em->getRepository("RibsAdminBundle:FosUser")->findAllUserNoArchived($current_account); |
23
|
|
|
|
24
|
|
|
return $this->render('@RibsAdmin/accounts/list-all-accounts.html.twig', [ |
25
|
|
|
"users" => $users |
26
|
|
|
]); |
27
|
|
|
} |
28
|
|
|
//-------------------------------------------- END DISPLAY VIEWS -----------------------------------------------------------// |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @Route("/account/archive/{guid}", name="ribsadmin_account_archive") |
32
|
|
|
* @param string $guid |
33
|
|
|
* @return RedirectResponse function that will archive a user |
34
|
|
|
*/ |
35
|
|
|
public function archiveAccount(string $guid): RedirectResponse |
36
|
|
|
{ |
37
|
|
|
$em = $this->getDoctrine()->getManager(); |
38
|
|
|
|
39
|
|
|
$user = $em->getRepository("RibsAdminBundle:User")->findOneBy(["guid" => $guid]); |
40
|
|
|
|
41
|
|
|
if ($user) { |
42
|
|
|
$user->setArchived(true); |
43
|
|
|
$em->persist($user); |
44
|
|
|
$em->flush(); |
45
|
|
|
|
46
|
|
|
$this->addFlash("success-flash", "The user " . $user->getFirstname() . " " . $user->getLastname() . |
47
|
|
|
" was archived sucessfuly"); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
return $this->redirectToRoute("ribsadmin_accounts"); |
51
|
|
|
} |
52
|
|
|
} |