Passed
Push — master ( 401bc9...64718d )
by Anthony
01:46
created

AccountsController::archiveAccount()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 9
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 16
rs 9.4285
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
}