1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AppBundle\Controller\FieldNotes; |
4
|
|
|
|
5
|
|
|
use AppBundle\Controller\AbstractController; |
6
|
|
|
use AppBundle\Form\UploadFieldNotesType; |
7
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
8
|
|
|
use Symfony\Component\HttpFoundation\Request; |
9
|
|
|
|
10
|
|
|
class FieldNotesController extends AbstractController |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @Route("/field-notes/", name="field-notes") |
14
|
|
|
* |
15
|
|
|
* |
16
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request |
17
|
|
|
* |
18
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
19
|
|
|
*/ |
20
|
|
|
public function indexAction(Request $request) |
21
|
|
|
{ |
22
|
|
|
$this->denyAccessUnlessGranted('ROLE_USER', null, 'Unable to access this page!'); |
23
|
|
|
$user = $this->getUser(); |
24
|
|
|
|
25
|
|
|
$repository = $this->getDoctrine()->getRepository('AppBundle:FieldNote'); |
26
|
|
|
$fieldNotes = $repository->findBy(['user' => $user->getId()], ['date' => 'ASC']); |
27
|
|
|
|
28
|
|
|
$form = $this->createForm(UploadFieldNotesType::class); |
29
|
|
|
$form->handleRequest($request); |
30
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
31
|
|
|
/** @var \Symfony\Component\HttpFoundation\File\UploadedFile $file */ |
32
|
|
|
$file = $form->getData()[UploadFieldNotesType::FIELD_FILE]; |
33
|
|
|
$fieldNoteService = $this->get('app.service.field_note'); |
34
|
|
|
try { |
35
|
|
|
$fieldNoteService->importFromFile($file->getRealPath(), $user->getId()); |
36
|
|
|
} catch (\Exception $e) { |
37
|
|
|
$this->addErrorMessage($e->getMessage()); |
38
|
|
|
|
39
|
|
|
return $this->redirectToRoute('field-notes'); |
40
|
|
|
} |
41
|
|
|
if ($fieldNoteService->hasErrors()) { |
42
|
|
|
foreach ($fieldNoteService->getErrors() as $error) { |
43
|
|
|
$this->addErrorMessage($error); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
return $this->redirectToRoute('field-notes'); |
47
|
|
|
} |
48
|
|
|
$this->addSuccessMessage($this->get('translator')->trans('Field Notes successfully uploaded.')); |
49
|
|
|
|
50
|
|
|
return $this->redirectToRoute('field-notes'); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
$this->setMenu(MNU_MYPROFILE_FIELD_NOTES); |
54
|
|
|
$this->setTitle($this->get('translator')->trans('Field Notes')); |
55
|
|
|
|
56
|
|
|
return $this->render('field-notes/index.html.twig', [ |
57
|
|
|
'user' => $user, |
58
|
|
|
'form' => $form->createView(), |
59
|
|
|
'fieldNotes' => $fieldNotes, |
60
|
|
|
]); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @Route("/field-notes/delete/{id}", name="field-notes.delete") |
65
|
|
|
* @param int $id |
66
|
|
|
* |
67
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse; |
|
|
|
|
68
|
|
|
*/ |
69
|
|
|
public function deleteAction($id) |
70
|
|
|
{ |
71
|
|
|
$this->denyAccessUnlessGranted('ROLE_USER', null, 'Unable to access this page!'); |
72
|
|
|
$user = $this->getUser(); |
73
|
|
|
|
74
|
|
|
$repository = $this->getDoctrine()->getRepository('AppBundle:FieldNote'); |
75
|
|
|
$fieldNote = $repository->findOneBy(['user' => $user->getId(), 'id' => $id]); |
76
|
|
|
$em = $this->getDoctrine()->getEntityManager(); |
|
|
|
|
77
|
|
|
$em->remove($fieldNote); |
78
|
|
|
$em->flush(); |
79
|
|
|
$this->addSuccessMessage($this->get('translator')->trans('Field note deleted.')); |
80
|
|
|
|
81
|
|
|
return $this->redirectToRoute('field-notes'); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.