1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Oc\Controller\Backend; |
6
|
|
|
|
7
|
|
|
use Doctrine\DBAL\Connection; |
8
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
9
|
|
|
use Form\CachesFormType; |
10
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
11
|
|
|
use Symfony\Component\HttpFoundation\Request; |
12
|
|
|
use Symfony\Component\HttpFoundation\Response; |
13
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
14
|
|
|
|
15
|
|
|
class CachesController extends AbstractController |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @Route("/caches", name="caches_index") |
19
|
|
|
*/ |
20
|
|
|
public function index(Connection $connection, Request $request): Response |
21
|
|
|
{ |
22
|
|
|
// declare variable to avoid render-error when $request is empty // there is surely a better method.. |
23
|
|
|
$fetched_caches = '0'; |
24
|
|
|
|
25
|
|
|
// create input field for caches_by_searchfield |
26
|
|
|
$form = $this->createForm(CachesFormType::class); |
27
|
|
|
|
28
|
|
|
// see: https://symfonycasts.com/screencast/symfony-forms/form-submit |
29
|
|
|
// handles the request (submit-button of the form), but only if there is a POST request |
30
|
|
|
$form->handleRequest($request); |
31
|
|
|
// if is true only if there is a request submitted and it is valid |
32
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
33
|
|
|
// read content of form input field |
34
|
|
|
$input_data = $form->getData(); |
35
|
|
|
|
36
|
|
|
// send request to DB |
37
|
|
|
$fetched_caches = $this->search_by_searchfield($connection, $input_data["content_caches_searchfield"]); |
38
|
|
|
|
39
|
|
|
// dd($input_data["content_caches_searchfield"]); |
40
|
|
|
// dd($fetched_caches); |
41
|
|
|
// die(); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
// load all caches from database and hand over to twig page |
45
|
|
|
// just for initial test to learn how it works.. leave it here for later check up |
46
|
|
|
// $caches = $connection->fetchAll('SELECT * FROM caches'); |
47
|
|
|
|
48
|
|
|
return $this->render('backend/caches/index.html.twig', ['cachesForm' => $form->createView(), 'caches_by_searchfield' => $fetched_caches]); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @Route("/caches/caches_by_searchfield", name="create_form_caches_by_searchfield") |
53
|
|
|
*/ |
54
|
|
|
public function create_form_caches_by_searchfield(EntityManagerInterface $em) |
|
|
|
|
55
|
|
|
{ |
56
|
|
|
$form = $this->createForm(CachesFormType::class); |
57
|
|
|
|
58
|
|
|
return $this->render('backend/caches/index.html.twig', ['cachesForm' => $form->createView()]); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @Route("/cache/{wp_oc}", name="cache_by_wp_oc") |
63
|
|
|
*/ |
64
|
|
|
public function search_by_cache_id(Connection $connection, string $wp_oc): Response |
65
|
|
|
{ |
66
|
|
|
$wp_oc = strtoupper($wp_oc); |
67
|
|
|
|
68
|
|
|
// search in database for wp_oc with the given {wp_oc} |
69
|
|
|
$fetched_cache = $connection->fetchAll('SELECT * FROM caches WHERE wp_oc = "' . $wp_oc . '"'); |
70
|
|
|
|
71
|
|
|
// if search for wp_oc gave no result, search for wp_gc |
72
|
|
|
if (!$fetched_cache) { |
|
|
|
|
73
|
|
|
$fetched_cache = $connection->fetchAll('SELECT * FROM caches WHERE wp_gc = "' . $wp_oc . '"'); |
74
|
|
|
|
75
|
|
|
// if search for wp_gc also gave no result, search for wp_nc |
76
|
|
|
if (!$fetched_cache) |
|
|
|
|
77
|
|
|
$fetched_cache = $connection->fetchAll('SELECT * FROM caches WHERE wp_nc = "' . $wp_oc . '"'); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
// if (!$fetched_cache) |
81
|
|
|
// print_r("nope, nix da"); |
82
|
|
|
// else |
83
|
|
|
// print_r($fetched_cache); |
84
|
|
|
// die(); |
85
|
|
|
|
86
|
|
|
return $this->render('backend/caches/index.html.twig', ['cache_by_id' => $fetched_cache]); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
// /** |
90
|
|
|
// * @Route("/caches/list", name="caches_by_searchfield", methods="POST") |
91
|
|
|
// */ |
92
|
|
|
function search_by_searchfield(Connection $connection, string $searchtext) |
93
|
|
|
{ |
94
|
|
|
|
95
|
|
|
if ($searchtext != "") { |
96
|
|
|
$sql_string = ' |
97
|
|
|
SELECT * FROM caches |
98
|
|
|
WHERE wp_oc = "' . $searchtext . '" |
99
|
|
|
OR wp_gc = "' . $searchtext . '" |
100
|
|
|
OR wp_nc = "' . $searchtext . '" |
101
|
|
|
OR name LIKE "%' . $searchtext . '%" |
102
|
|
|
'; |
103
|
|
|
|
104
|
|
|
$fetched_caches = $connection->fetchAll($sql_string); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
// print_r("searchtext: " . $searchtext . " /// "); |
108
|
|
|
// print_r("sql_string: " . $sql_string . " /// "); |
109
|
|
|
// print_r("fetched_caches: "); |
110
|
|
|
// dd($fetched_caches); |
111
|
|
|
// die(); |
112
|
|
|
|
113
|
|
|
return $fetched_caches; |
|
|
|
|
114
|
|
|
|
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.