Completed
Push — master ( 8dc9c7...c3fd32 )
by Jan
05:27
created

PartListsController::showFootprint()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
c 0
b 0
f 0
nc 2
nop 3
dl 0
loc 12
rs 10
1
<?php
2
/**
3
 * part-db version 0.1
4
 * Copyright (C) 2005 Christoph Lechner
5
 * http://www.cl-projects.de/.
6
 *
7
 * part-db version 0.2+
8
 * Copyright (C) 2009 K. Jacobs and others (see authors.php)
9
 * http://code.google.com/p/part-db/
10
 *
11
 * Part-DB Version 0.4+
12
 * Copyright (C) 2016 - 2019 Jan Böhmer
13
 * https://github.com/jbtronics
14
 *
15
 * This program is free software; you can redistribute it and/or
16
 * modify it under the terms of the GNU General Public License
17
 * as published by the Free Software Foundation; either version 2
18
 * of the License, or (at your option) any later version.
19
 *
20
 * This program is distributed in the hope that it will be useful,
21
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 * GNU General Public License for more details.
24
 *
25
 * You should have received a copy of the GNU General Public License
26
 * along with this program; if not, write to the Free Software
27
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
28
 */
29
30
namespace App\Controller;
31
32
use App\DataTables\PartsDataTable;
33
use App\Entity\Parts\Category;
34
use App\Entity\Parts\Footprint;
35
use App\Entity\Parts\Manufacturer;
36
use Omines\DataTablesBundle\DataTableFactory;
37
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
38
use Symfony\Component\HttpFoundation\Request;
39
use Symfony\Component\Routing\Annotation\Route;
40
41
class PartListsController extends AbstractController
42
{
43
    /**
44
     * @Route("/category/{id}/parts", name="part_list_category")
45
     *
46
     * @param $id int The id of the category
47
     *
48
     * @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\Response
49
     */
50
    public function showCategory(Category $category, Request $request, DataTableFactory $dataTable)
51
    {
52
        $table = $dataTable->createFromType(PartsDataTable::class, ['category' => $category])
53
                    ->handleRequest($request);
54
55
        if ($table->isCallback()) {
56
            return $table->getResponse();
57
        }
58
59
        return $this->render('Parts/lists/category_list.html.twig', [
60
            'datatable' => $table,
61
            'entity' => $category
62
        ]);
63
    }
64
65
    /**
66
     * @Route("/footprint/{id}/parts", name="part_list_footprint")
67
     *
68
     * @param $id int The id of the category
69
     *
70
     * @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\Response
71
     */
72
    public function showFootprint(Footprint $footprint, Request $request, DataTableFactory $dataTable)
73
    {
74
        $table = $dataTable->createFromType(PartsDataTable::class, ['footprint' => $footprint])
75
            ->handleRequest($request);
76
77
        if ($table->isCallback()) {
78
            return $table->getResponse();
79
        }
80
81
        return $this->render('Parts/lists/footprint_list.html.twig', [
82
            'datatable' => $table,
83
            'entity' => $footprint
84
        ]);
85
    }
86
87
    /**
88
     * @Route("/manufacturer/{id}/parts", name="part_list_manufacturer")
89
     *
90
     * @param $id int The id of the category
91
     *
92
     * @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\Response
93
     */
94
    public function showManufacturer(Manufacturer $manufacturer, Request $request, DataTableFactory $dataTable)
95
    {
96
        $table = $dataTable->createFromType(PartsDataTable::class, ['manufacturer' => $manufacturer])
97
            ->handleRequest($request);
98
99
        if ($table->isCallback()) {
100
            return $table->getResponse();
101
        }
102
103
        return $this->render('Parts/lists/manufacturer_list.html.twig', [
104
            'datatable' => $table,
105
            'entity' => $manufacturer
106
        ]);
107
    }
108
109
    /**
110
     * @Route("/parts/by_tag/{tag}", name="part_list_tags")
111
     * @param string $tag
112
     * @param Request $request
113
     * @param DataTableFactory $dataTable
114
     * @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\Response
115
     */
116
    public function showTag(string $tag, Request $request, DataTableFactory $dataTable)
117
    {
118
        $table = $dataTable->createFromType(PartsDataTable::class, ['tag' => $tag])
119
            ->handleRequest($request);
120
121
        if ($table->isCallback()) {
122
            return $table->getResponse();
123
        }
124
125
        return $this->render('parts_list.html.twig', ['datatable' => $table]);
126
    }
127
128
    /**
129
     * @Route("/parts/search/{keyword}", name="parts_search")
130
     */
131
    public function showSearch(Request $request, DataTableFactory $dataTable, string $keyword = "")
132
    {
133
        $search = $keyword;
134
135
        $table = $dataTable->createFromType(PartsDataTable::class, ['search' => $search])
136
            ->handleRequest($request);
137
138
        if ($table->isCallback()) {
139
            return $table->getResponse();
140
        }
141
142
        return $this->render('parts_list.html.twig', ['datatable' => $table]);
143
    }
144
145
    /**
146
     * @Route("/parts", name="parts_show_all")
147
     *
148
     * @param Request          $request
149
     * @param DataTableFactory $dataTable
150
     *
151
     * @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\Response
152
     */
153
    public function showAll(Request $request, DataTableFactory $dataTable)
154
    {
155
        $table = $dataTable->createFromType(PartsDataTable::class)
156
            ->handleRequest($request);
157
158
        if ($table->isCallback()) {
159
            return $table->getResponse();
160
        }
161
162
        return $this->render('parts_list.html.twig', ['datatable' => $table]);
163
    }
164
}
165