Completed
Push — master ( f40214...4c5b5b )
by Jan
03:55
created

PartListsController::showCategory()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
nc 2
nop 3
dl 0
loc 10
rs 10
c 2
b 0
f 0
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 Omines\DataTablesBundle\DataTableFactory;
35
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
36
use Symfony\Component\HttpFoundation\Request;
37
use Symfony\Component\Routing\Annotation\Route;
38
39
class PartListsController extends AbstractController
40
{
41
    /**
42
     * @Route("/category/{id}/parts")
43
     *
44
     * @param $id int The id of the category
45
     *
46
     * @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\Response
47
     */
48
    public function showCategory(Category $category, Request $request, DataTableFactory $dataTable)
49
    {
50
        $table = $dataTable->createFromType(PartsDataTable::class, ['category' => $category])
51
                    ->handleRequest($request);
52
53
        if ($table->isCallback()) {
54
            return $table->getResponse();
55
        }
56
57
        return $this->render('parts_list.html.twig', ['datatable' => $table]);
58
    }
59
60
    /**
61
     * @Route("/parts/by_tag/{tag}", name="part_list_tags")
62
     * @param string $tag
63
     * @param Request $request
64
     * @param DataTableFactory $dataTable
65
     * @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\Response
66
     */
67
    public function showTag(string $tag, Request $request, DataTableFactory $dataTable)
68
    {
69
        $table = $dataTable->createFromType(PartsDataTable::class, ['tag' => $tag])
70
            ->handleRequest($request);
71
72
        if ($table->isCallback()) {
73
            return $table->getResponse();
74
        }
75
76
        return $this->render('parts_list.html.twig', ['datatable' => $table]);
77
    }
78
79
    /**
80
     * @Route("/parts/search/{keyword}", name="parts_search")
81
     */
82
    public function showSearch(Request $request, DataTableFactory $dataTable, string $keyword = "")
83
    {
84
        $search = $keyword;
85
        dump($search);
86
87
        $table = $dataTable->createFromType(PartsDataTable::class, ['search' => $search])
88
            ->handleRequest($request);
89
90
        if ($table->isCallback()) {
91
            return $table->getResponse();
92
        }
93
94
        return $this->render('parts_list.html.twig', ['datatable' => $table]);
95
    }
96
97
    /**
98
     * @Route("/parts", name="parts_show_all")
99
     *
100
     * @param Request          $request
101
     * @param DataTableFactory $dataTable
102
     *
103
     * @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\Response
104
     */
105
    public function showAll(Request $request, DataTableFactory $dataTable)
106
    {
107
        $table = $dataTable->createFromType(PartsDataTable::class)
108
            ->handleRequest($request);
109
110
        if ($table->isCallback()) {
111
            return $table->getResponse();
112
        }
113
114
        return $this->render('parts_list.html.twig', ['datatable' => $table]);
115
    }
116
}
117