Skip to content

Commit

Permalink
add deltee via dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
holzi1005 committed Nov 21, 2024
1 parent 19c9518 commit 6e54a82
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/Controller/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Filesystem\Filesystem;

class AdminController extends AbstractController
{
public function __construct(
private EntityManagerInterface $entityManager,
private Filesystem $filesystem,
private FileRepository $fileRepository,
)
{
$this->filesystem = new Filesystem();
}

#[Route('/filemanager', name: 'app_dashboard')]
Expand Down Expand Up @@ -56,6 +59,28 @@ public function downloadAction($id)
$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $file->getFileName());

return $response;
}
}

#[Route('/filemanager/delete/{id}', name: 'app_dashboard_delete')]
public function deleteAction($id)
{

$file = $this->fileRepository->findOneBy(
array(
'fileId' => $id,
'permission' => $this->getUser()->getEmail()
)
);

$filePath = $this->getParameter('upload_directory') . '/' . $file->getFileId();

if ($this->filesystem->exists($filePath)) {
$this->filesystem->remove($filePath);
}

$this->entityManager->remove($file);
$this->entityManager->flush();
return $this->redirectToRoute('app_dashboard');
}

}
8 changes: 8 additions & 0 deletions templates/dashboard/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<th scope="col">Beschreibung</th>
<th scope="col">Datum</th>
<th scope="col">Download</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
Expand All @@ -41,6 +42,13 @@
<td>{{ d.description }}</td>
<td>{{ d.createdAt|date('d.m.Y H:i') }}</td>
<td><a href={{path('app_dashboard_download',{'id':d.fileId})}}>{{d.fileName}}</a></td>
<td>
<a href={{path('app_dashboard_delete',{'id':d.fileId})}}>
<svg xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" width="20" height="20" viewBox="0 0 128 128">
<path d="M 49 1 C 47.34 1 46 2.34 46 4 C 46 5.66 47.34 7 49 7 L 79 7 C 80.66 7 82 5.66 82 4 C 82 2.34 80.66 1 79 1 L 49 1 z M 24 15 C 16.83 15 11 20.83 11 28 C 11 35.17 16.83 41 24 41 L 101 41 L 101 104 C 101 113.37 93.37 121 84 121 L 44 121 C 34.63 121 27 113.37 27 104 L 27 52 C 27 50.34 25.66 49 24 49 C 22.34 49 21 50.34 21 52 L 21 104 C 21 116.68 31.32 127 44 127 L 84 127 C 96.68 127 107 116.68 107 104 L 107 40.640625 C 112.72 39.280625 117 34.14 117 28 C 117 20.83 111.17 15 104 15 L 24 15 z M 24 21 L 104 21 C 107.86 21 111 24.14 111 28 C 111 31.86 107.86 35 104 35 L 24 35 C 20.14 35 17 31.86 17 28 C 17 24.14 20.14 21 24 21 z M 50 55 C 48.34 55 47 56.34 47 58 L 47 104 C 47 105.66 48.34 107 50 107 C 51.66 107 53 105.66 53 104 L 53 58 C 53 56.34 51.66 55 50 55 z M 78 55 C 76.34 55 75 56.34 75 58 L 75 104 C 75 105.66 76.34 107 78 107 C 79.66 107 81 105.66 81 104 L 81 58 C 81 56.34 79.66 55 78 55 z"></path>
</svg>
</a>
</td>
</tr>
{% endfor %}

Expand Down

0 comments on commit 6e54a82

Please sign in to comment.