|
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
|
|
|
if (!$user->isVerified()) { |
|
43
|
|
|
return $this->redirectToRoute('user_property'); |
|
44
|
|
|
} |
|
45
|
|
|
$property = new Property(); |
|
46
|
|
|
$property->setAuthor($user); |
|
47
|
|
|
$form = $this->createForm(PropertyType::class, $property); |
|
48
|
|
|
$form->handleRequest($request); |
|
49
|
|
|
|
|
50
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
|
51
|
|
|
$service->create($property); |
|
52
|
|
|
|
|
53
|
|
|
return $this->redirectToRoute('user_photo_edit', ['id' => $property->getId()]); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
return $this->render('user/property/new.html.twig', [ |
|
57
|
|
|
'property' => $property, |
|
58
|
|
|
'form' => $form->createView(), |
|
59
|
|
|
'site' => $this->site($request), |
|
60
|
|
|
]); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Displays a form to edit an existing Property entity. |
|
65
|
|
|
* |
|
66
|
|
|
* @Route("/user/property/{id<\d+>}/edit",methods={"GET", "POST"}, name="user_property_edit") |
|
67
|
|
|
* @IsGranted("PROPERTY_EDIT", subject="property", message="You cannot change this property.") |
|
68
|
|
|
*/ |
|
69
|
|
|
public function edit(Request $request, Property $property, AdminPropertyService $service): Response |
|
70
|
|
|
{ |
|
71
|
|
|
$form = $this->createForm(PropertyType::class, $property); |
|
72
|
|
|
$form->handleRequest($request); |
|
73
|
|
|
|
|
74
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
|
75
|
|
|
$service->update($property); |
|
76
|
|
|
|
|
77
|
|
|
return $this->redirectToRoute('user_photo_edit', ['id' => $property->getId()]); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
return $this->render('user/property/edit.html.twig', [ |
|
81
|
|
|
'form' => $form->createView(), |
|
82
|
|
|
'site' => $this->site($request), |
|
83
|
|
|
]); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|