1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace App\Controller\User; |
6
|
|
|
|
7
|
|
|
use App\Controller\BaseController; |
8
|
|
|
use App\Entity\Property; |
9
|
|
|
use App\Entity\User; |
10
|
|
|
use App\Form\Type\PropertyType; |
11
|
|
|
use App\Service\Admin\PropertyService as AdminPropertyService; |
12
|
|
|
use App\Service\User\PropertyService; |
13
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted; |
14
|
|
|
use Symfony\Component\HttpFoundation\Request; |
15
|
|
|
use Symfony\Component\HttpFoundation\Response; |
16
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
17
|
|
|
|
18
|
|
|
final class PropertyController extends BaseController |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @Route("/user/property", defaults={"page": "1"}, methods={"GET"}, name="user_property") |
22
|
|
|
*/ |
23
|
|
|
public function index(Request $request, PropertyService $service): Response |
24
|
|
|
{ |
25
|
|
|
$properties = $service->getUserProperties($request); |
26
|
|
|
|
27
|
|
|
return $this->render('user/property/index.html.twig', [ |
28
|
|
|
'properties' => $properties, |
29
|
|
|
'site' => $this->site($request), |
30
|
|
|
]); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @Route("/user/property/new", name="user_property_new") |
35
|
|
|
*/ |
36
|
|
|
public function new(Request $request, AdminPropertyService $service): Response |
37
|
|
|
{ |
38
|
|
|
/** |
39
|
|
|
* @var User $user |
40
|
|
|
*/ |
41
|
|
|
$user = $this->getUser(); |
42
|
|
|
$property = new Property(); |
43
|
|
|
$property->setAuthor($user); |
44
|
|
|
$form = $this->createForm(PropertyType::class, $property); |
45
|
|
|
$form->handleRequest($request); |
46
|
|
|
|
47
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
48
|
|
|
$service->create($property); |
49
|
|
|
|
50
|
|
|
return $this->redirectToRoute('user_photo_edit', ['id' => $property->getId()]); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
return $this->render('user/property/new.html.twig', [ |
54
|
|
|
'property' => $property, |
55
|
|
|
'form' => $form->createView(), |
56
|
|
|
'site' => $this->site($request), |
57
|
|
|
]); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Displays a form to edit an existing Property entity. |
62
|
|
|
* |
63
|
|
|
* @Route("/user/property/{id<\d+>}/edit",methods={"GET", "POST"}, name="user_property_edit") |
64
|
|
|
* @IsGranted("PROPERTY_EDIT", subject="property", message="You cannot change this property.") |
65
|
|
|
*/ |
66
|
|
|
public function edit(Request $request, Property $property, AdminPropertyService $service): Response |
67
|
|
|
{ |
68
|
|
|
$form = $this->createForm(PropertyType::class, $property); |
69
|
|
|
$form->handleRequest($request); |
70
|
|
|
|
71
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
72
|
|
|
$service->update($property); |
73
|
|
|
|
74
|
|
|
return $this->redirectToRoute('user_photo_edit', ['id' => $property->getId()]); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
return $this->render('user/property/edit.html.twig', [ |
78
|
|
|
'form' => $form->createView(), |
79
|
|
|
'site' => $this->site($request), |
80
|
|
|
]); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|