1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PiouPiou\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 archived or not 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:Account")->findAllUserArchived($current_account); |
23
|
|
|
$users_archived = $em->getRepository("RibsAdminBundle:Account")->findAllUserArchived($current_account, true); |
24
|
|
|
|
25
|
|
|
return $this->render('@RibsAdmin/accounts/list-all-accounts.html.twig', [ |
26
|
|
|
"users" => $users, |
27
|
|
|
"users_archived" => $users_archived |
28
|
|
|
]); |
29
|
|
|
} |
30
|
|
|
//-------------------------------------------- END DISPLAY VIEWS -----------------------------------------------------------// |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @Route("/account/archive/{guid}/{activate}", name="ribsadmin_account_archive") |
34
|
|
|
* @param string $guid |
35
|
|
|
* @return RedirectResponse function that will disable or activate a user |
36
|
|
|
*/ |
37
|
|
|
public function archiveAccount(string $guid, bool $activate = false): RedirectResponse |
38
|
|
|
{ |
39
|
|
|
$em = $this->getDoctrine()->getManager(); |
40
|
|
|
|
41
|
|
|
$user = $em->getRepository("RibsAdminBundle:User")->findOneBy(["guid" => $guid]); |
42
|
|
|
|
43
|
|
|
if ($user) { |
44
|
|
|
if ($activate === true) { |
45
|
|
|
$user->setArchived(false); |
46
|
|
|
$word = "activated"; |
47
|
|
|
} else { |
48
|
|
|
$user->setArchived(true); |
49
|
|
|
$word = "disabled"; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
$em->persist($user); |
53
|
|
|
$em->flush(); |
54
|
|
|
|
55
|
|
|
$this->addFlash("success-flash", "The user " . $user->getFirstname() . " " . $user->getLastname() . |
56
|
|
|
" was " . $word . " sucessfuly"); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
return $this->redirectToRoute("ribsadmin_accounts"); |
60
|
|
|
} |
61
|
|
|
} |