2019-03-05 23:52:45 +01:00
|
|
|
<?php
|
2020-01-05 15:46:58 +01:00
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2019-03-05 23:52:45 +01:00
|
|
|
/**
|
2019-11-09 00:47:20 +01:00
|
|
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
2019-03-05 23:52:45 +01:00
|
|
|
*
|
2019-11-01 13:40:30 +01:00
|
|
|
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
|
2019-03-05 23:52:45 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Controller;
|
|
|
|
|
|
|
|
use App\DataTables\PartsDataTable;
|
2019-09-05 22:27:18 +02:00
|
|
|
use App\Entity\Parts\Category;
|
2019-09-08 13:59:35 +02:00
|
|
|
use App\Entity\Parts\Footprint;
|
|
|
|
use App\Entity\Parts\Manufacturer;
|
2019-09-08 17:30:58 +02:00
|
|
|
use App\Entity\Parts\Storelocation;
|
|
|
|
use App\Entity\Parts\Supplier;
|
2019-03-05 23:52:45 +01:00
|
|
|
use Omines\DataTablesBundle\DataTableFactory;
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
2020-01-05 22:49:00 +01:00
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
2019-03-05 23:52:45 +01:00
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
2020-01-05 22:49:00 +01:00
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
2019-03-05 23:52:45 +01:00
|
|
|
use Symfony\Component\Routing\Annotation\Route;
|
|
|
|
|
|
|
|
class PartListsController extends AbstractController
|
|
|
|
{
|
|
|
|
/**
|
2019-09-08 13:59:35 +02:00
|
|
|
* @Route("/category/{id}/parts", name="part_list_category")
|
2019-03-20 23:16:07 +01:00
|
|
|
*
|
2020-02-02 14:05:36 +01:00
|
|
|
* @param Category $category
|
|
|
|
* @param Request $request
|
|
|
|
* @param DataTableFactory $dataTable
|
2020-01-05 22:49:00 +01:00
|
|
|
* @return JsonResponse|Response
|
2019-03-05 23:52:45 +01:00
|
|
|
*/
|
2019-09-05 22:27:18 +02:00
|
|
|
public function showCategory(Category $category, Request $request, DataTableFactory $dataTable)
|
2019-03-05 23:52:45 +01:00
|
|
|
{
|
2019-09-05 22:27:18 +02:00
|
|
|
$table = $dataTable->createFromType(PartsDataTable::class, ['category' => $category])
|
2019-09-08 14:32:44 +02:00
|
|
|
->handleRequest($request);
|
2019-03-05 23:52:45 +01:00
|
|
|
|
|
|
|
if ($table->isCallback()) {
|
|
|
|
return $table->getResponse();
|
|
|
|
}
|
|
|
|
|
2019-09-08 13:37:11 +02:00
|
|
|
return $this->render('Parts/lists/category_list.html.twig', [
|
|
|
|
'datatable' => $table,
|
2019-11-09 00:47:20 +01:00
|
|
|
'entity' => $category,
|
2019-09-08 13:37:11 +02:00
|
|
|
]);
|
2019-03-05 23:52:45 +01:00
|
|
|
}
|
|
|
|
|
2019-09-08 13:59:35 +02:00
|
|
|
/**
|
|
|
|
* @Route("/footprint/{id}/parts", name="part_list_footprint")
|
|
|
|
*
|
2020-02-02 14:05:36 +01:00
|
|
|
* @param Footprint $footprint
|
|
|
|
* @param Request $request
|
|
|
|
* @param DataTableFactory $dataTable
|
2020-01-05 22:49:00 +01:00
|
|
|
* @return JsonResponse|Response
|
2019-09-08 13:59:35 +02:00
|
|
|
*/
|
|
|
|
public function showFootprint(Footprint $footprint, Request $request, DataTableFactory $dataTable)
|
|
|
|
{
|
|
|
|
$table = $dataTable->createFromType(PartsDataTable::class, ['footprint' => $footprint])
|
|
|
|
->handleRequest($request);
|
|
|
|
|
|
|
|
if ($table->isCallback()) {
|
|
|
|
return $table->getResponse();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->render('Parts/lists/footprint_list.html.twig', [
|
|
|
|
'datatable' => $table,
|
2019-11-09 00:47:20 +01:00
|
|
|
'entity' => $footprint,
|
2019-09-08 13:59:35 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Route("/manufacturer/{id}/parts", name="part_list_manufacturer")
|
|
|
|
*
|
2020-02-02 14:05:36 +01:00
|
|
|
* @param Manufacturer $manufacturer
|
|
|
|
* @param Request $request
|
|
|
|
* @param DataTableFactory $dataTable
|
2020-01-05 22:49:00 +01:00
|
|
|
* @return JsonResponse|Response
|
2019-09-08 13:59:35 +02:00
|
|
|
*/
|
|
|
|
public function showManufacturer(Manufacturer $manufacturer, Request $request, DataTableFactory $dataTable)
|
|
|
|
{
|
|
|
|
$table = $dataTable->createFromType(PartsDataTable::class, ['manufacturer' => $manufacturer])
|
|
|
|
->handleRequest($request);
|
|
|
|
|
|
|
|
if ($table->isCallback()) {
|
|
|
|
return $table->getResponse();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->render('Parts/lists/manufacturer_list.html.twig', [
|
|
|
|
'datatable' => $table,
|
2019-11-09 00:47:20 +01:00
|
|
|
'entity' => $manufacturer,
|
2019-09-08 13:59:35 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2019-09-08 17:30:58 +02:00
|
|
|
/**
|
|
|
|
* @Route("/store_location/{id}/parts", name="part_list_store_location")
|
|
|
|
*
|
2020-02-02 14:05:36 +01:00
|
|
|
* @param Storelocation $storelocation
|
|
|
|
* @param Request $request
|
|
|
|
* @param DataTableFactory $dataTable
|
2020-01-05 22:49:00 +01:00
|
|
|
* @return JsonResponse|Response
|
2019-09-08 17:30:58 +02:00
|
|
|
*/
|
|
|
|
public function showStorelocation(Storelocation $storelocation, Request $request, DataTableFactory $dataTable)
|
|
|
|
{
|
|
|
|
$table = $dataTable->createFromType(PartsDataTable::class, ['storelocation' => $storelocation])
|
|
|
|
->handleRequest($request);
|
|
|
|
|
|
|
|
if ($table->isCallback()) {
|
|
|
|
return $table->getResponse();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->render('Parts/lists/store_location_list.html.twig', [
|
|
|
|
'datatable' => $table,
|
2019-11-09 00:47:20 +01:00
|
|
|
'entity' => $storelocation,
|
2019-09-08 17:30:58 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Route("/supplier/{id}/parts", name="part_list_supplier")
|
|
|
|
*
|
2020-02-02 14:05:36 +01:00
|
|
|
* @param Supplier $supplier
|
|
|
|
* @param Request $request
|
|
|
|
* @param DataTableFactory $dataTable
|
2020-01-05 22:49:00 +01:00
|
|
|
* @return JsonResponse|Response
|
2019-09-08 17:30:58 +02:00
|
|
|
*/
|
|
|
|
public function showSupplier(Supplier $supplier, Request $request, DataTableFactory $dataTable)
|
|
|
|
{
|
|
|
|
$table = $dataTable->createFromType(PartsDataTable::class, ['supplier' => $supplier])
|
|
|
|
->handleRequest($request);
|
|
|
|
|
|
|
|
if ($table->isCallback()) {
|
|
|
|
return $table->getResponse();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->render('Parts/lists/supplier_list.html.twig', [
|
|
|
|
'datatable' => $table,
|
2019-11-09 00:47:20 +01:00
|
|
|
'entity' => $supplier,
|
2019-09-08 17:30:58 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2019-09-05 22:27:18 +02:00
|
|
|
/**
|
|
|
|
* @Route("/parts/by_tag/{tag}", name="part_list_tags")
|
2019-11-09 00:47:20 +01:00
|
|
|
*
|
2020-02-02 14:05:36 +01:00
|
|
|
* @param string $tag
|
|
|
|
* @param Request $request
|
|
|
|
* @param DataTableFactory $dataTable
|
2020-01-05 22:49:00 +01:00
|
|
|
* @return JsonResponse|Response
|
2019-09-05 22:27:18 +02:00
|
|
|
*/
|
|
|
|
public function showTag(string $tag, Request $request, DataTableFactory $dataTable)
|
|
|
|
{
|
|
|
|
$table = $dataTable->createFromType(PartsDataTable::class, ['tag' => $tag])
|
|
|
|
->handleRequest($request);
|
|
|
|
|
|
|
|
if ($table->isCallback()) {
|
|
|
|
return $table->getResponse();
|
|
|
|
}
|
|
|
|
|
2019-09-08 14:32:44 +02:00
|
|
|
return $this->render('Parts/lists/tags_list.html.twig', [
|
|
|
|
'tag' => $tag,
|
2019-11-09 00:47:20 +01:00
|
|
|
'datatable' => $table,
|
2019-09-08 14:32:44 +02:00
|
|
|
]);
|
2019-09-05 22:27:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-01-04 22:37:30 +01:00
|
|
|
* @Route("/parts/search", name="parts_search")
|
2020-02-02 14:05:36 +01:00
|
|
|
* @param Request $request
|
|
|
|
* @param DataTableFactory $dataTable
|
|
|
|
* @return JsonResponse|Response
|
2019-09-05 22:27:18 +02:00
|
|
|
*/
|
2020-01-04 22:37:30 +01:00
|
|
|
public function showSearch(Request $request, DataTableFactory $dataTable)
|
2019-09-05 22:27:18 +02:00
|
|
|
{
|
2020-01-04 22:37:30 +01:00
|
|
|
$search = $request->get('keyword', '');
|
2019-09-05 22:27:18 +02:00
|
|
|
|
|
|
|
$table = $dataTable->createFromType(PartsDataTable::class, ['search' => $search])
|
|
|
|
->handleRequest($request);
|
|
|
|
|
|
|
|
if ($table->isCallback()) {
|
|
|
|
return $table->getResponse();
|
|
|
|
}
|
|
|
|
|
2019-09-08 14:32:44 +02:00
|
|
|
return $this->render('Parts/lists/search_list.html.twig', [
|
2020-01-05 15:46:58 +01:00
|
|
|
'datatable' => $table,
|
|
|
|
'keyword' => $search,
|
|
|
|
]);
|
2019-09-05 22:27:18 +02:00
|
|
|
}
|
|
|
|
|
2019-03-06 00:02:33 +01:00
|
|
|
/**
|
2019-03-26 15:57:51 +01:00
|
|
|
* @Route("/parts", name="parts_show_all")
|
2019-03-06 00:02:33 +01:00
|
|
|
*
|
2020-02-02 14:05:36 +01:00
|
|
|
* @param Request $request
|
|
|
|
* @param DataTableFactory $dataTable
|
2020-01-05 22:49:00 +01:00
|
|
|
* @return JsonResponse|Response
|
2019-03-06 00:02:33 +01:00
|
|
|
*/
|
|
|
|
public function showAll(Request $request, DataTableFactory $dataTable)
|
|
|
|
{
|
|
|
|
$table = $dataTable->createFromType(PartsDataTable::class)
|
|
|
|
->handleRequest($request);
|
|
|
|
|
|
|
|
if ($table->isCallback()) {
|
|
|
|
return $table->getResponse();
|
|
|
|
}
|
|
|
|
|
2019-09-08 14:32:44 +02:00
|
|
|
return $this->render('Parts/lists/all_list.html.twig', ['datatable' => $table]);
|
2019-03-06 00:02:33 +01:00
|
|
|
}
|
2019-03-20 23:16:07 +01:00
|
|
|
}
|