|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace AppBundle\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use AppBundle\Entity\Estate; |
|
6
|
|
|
use AppBundle\Entity\File; |
|
7
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
|
8
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
|
9
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
10
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; |
|
11
|
|
|
use AppBundle\Form\EstateType; |
|
12
|
|
|
use Symfony\Component\Form\Extension\Core\Type\SubmitType; |
|
13
|
|
|
use Gedmo\Uploadable\FileInfo\FileInfoArray; |
|
14
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @Route("/admin") |
|
18
|
|
|
*/ |
|
19
|
|
|
class AdminController extends Controller |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @Route("/", name="admin_index") |
|
23
|
|
|
*/ |
|
24
|
|
|
public function indexAction(Request $request) |
|
25
|
|
|
{ |
|
26
|
|
|
// replace this example code with whatever you need |
|
27
|
|
|
return $this->render('AppBundle::admin/index.html.twig', array( |
|
28
|
|
|
'base_dir' => realpath($this->getParameter('kernel.root_dir') . '/..'), |
|
29
|
|
|
)); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @Route("/newestate", name="admin_new_estate") |
|
34
|
|
|
* @Method({"GET", "POST"}) |
|
35
|
|
|
*/ |
|
36
|
|
|
public function newEstateAction(Request $request) |
|
37
|
|
|
{ |
|
38
|
|
|
$entityManager = $this->getDoctrine()->getManager(); |
|
39
|
|
|
$estate = new Estate(); |
|
40
|
|
|
//$this->denyAccessUnlessGranted('create', $estate); |
|
|
|
|
|
|
41
|
|
|
$form = $this->createForm(EstateType::class, $estate)->add('saveAndCreateNew', SubmitType::class); |
|
42
|
|
|
$form->handleRequest($request); |
|
43
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
|
44
|
|
|
$uploadableManager = $this->container->get('stof_doctrine_extensions.uploadable.manager'); |
|
45
|
|
|
$files = $request->files->get('app_bundle_estate_type'); |
|
46
|
|
|
if ($files['imageFile'][0] !== null) { |
|
47
|
|
|
foreach ($files['imageFile'] as $imageData) { |
|
48
|
|
|
$image = new File(); |
|
49
|
|
|
$uploadableManager->markEntityToUpload($image, $imageData); |
|
50
|
|
|
$image->setEstate($estate); |
|
51
|
|
|
$estate->addFile($image); |
|
52
|
|
|
$entityManager->persist($image); |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
$entityManager->persist($estate); |
|
56
|
|
|
$entityManager->flush(); |
|
57
|
|
|
$nextAction = $form->get('saveAndCreateNew')->isClicked() |
|
|
|
|
|
|
58
|
|
|
? 'admin_new_estate' |
|
59
|
|
|
: 'admin_index'; |
|
60
|
|
|
return $this->redirectToRoute($nextAction); |
|
61
|
|
|
} |
|
62
|
|
|
return $this->render('@App/admin/newestate.html.twig', array( |
|
63
|
|
|
'estate' => $estate, |
|
64
|
|
|
'form' => $form->createView(), |
|
65
|
|
|
)); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.