1
1
<?php
2
2
3
- class WelcomeController
3
+ class GGamesController
4
4
{
5
5
/* Die Welcome Seite oder Startseite */
6
6
public function index ()
@@ -12,36 +12,23 @@ public function index()
12
12
13
13
/* Der Shop */
14
14
public function store (){
15
- session_start ();
16
15
17
- /* Alle Spiele */
18
- $ pdo = connectDatabase ();
19
- $ pdo ->setAttribute (PDO ::ATTR_ERRMODE , PDO ::ERRMODE_EXCEPTION );
16
+ $ games = new Games ();
20
17
21
- $ statement = $ pdo ->prepare ("SELECT * FROM video_game " );
22
- $ statement ->execute ();
23
- $ games = $ statement ->fetchAll ();
18
+ // Initialize the session
19
+ session_start ();
24
20
21
+ /* Alle Spiele */
22
+ $ getAllGames = $ games -> getAllGames ();
23
+ $ getAllGames = $ getAllGames -> fetchAll ();
24
+
25
25
/* Gekaufte Spiele */
26
- $ pdo = connectDatabase ();
27
- $ pdo ->setAttribute (PDO ::ATTR_ERRMODE , PDO ::ERRMODE_EXCEPTION );
28
-
29
- $ statement = $ pdo ->prepare ("SELECT video_game.name, video_game.id, video_game.entwickler, video_game.img, video_game.price FROM video_game
30
- INNER JOIN kaeufe ON kaeufe.fk_video_gameId = video_game.id
31
- INNER JOIN users ON users.id = kaeufe.fk_usersId WHERE users.id = :id " );
32
- $ statement ->bindParam (':id ' , $ _SESSION ['id ' ]);
33
- $ statement ->execute ();
34
- $ gamesBought = $ statement ->fetchAll ();
26
+ $ getAllBoughtGames = $ games -> getAllBoughtGames ();
27
+ $ getAllBoughtGames = $ getAllBoughtGames -> fetchAll ();
35
28
36
29
/* Nicht Gekaufte Spiele */
37
- $ pdo = connectDatabase ();
38
- $ pdo ->setAttribute (PDO ::ATTR_ERRMODE , PDO ::ERRMODE_EXCEPTION );
39
-
40
- $ statement = $ pdo ->prepare ("SELECT video_game.id, video_game.name, video_game.entwickler, video_game.img, video_game.price FROM video_game
41
- WHERE video_game.id NOT IN (SELECT kaeufe.fk_video_gameId FROM kaeufe WHERE kaeufe.fk_usersId = :id) " );
42
- $ statement ->bindParam (':id ' , $ _SESSION ['id ' ]);
43
- $ statement ->execute ();
44
- $ gamesNotBought = $ statement ->fetchAll ();
30
+ $ getAllNotBoughtGames = $ games -> getNotBoughtGames ();
31
+ $ getAllNotBoughtGames = $ getAllNotBoughtGames -> fetchAll ();
45
32
46
33
require 'app/Views/store.view.php ' ;
47
34
}
@@ -66,7 +53,7 @@ public function addGame(){
66
53
67
54
$ games ->createGame ($ name , $ entwickler , $ img , $ price );
68
55
69
- header ('Location: http://localhost/GGames/shop/ store ' );
56
+ header ('Location: http://localhost/GGames/store ' );
70
57
}
71
58
}
72
59
@@ -85,7 +72,7 @@ public function deleteGame(){
85
72
86
73
$ games ->removeGame ($ id );
87
74
88
- header ('Location: http://localhost/GGames/shop/ store ' );
75
+ header ('Location: http://localhost/GGames/store ' );
89
76
90
77
require 'app/Views/store.view.php ' ;
91
78
}
@@ -99,10 +86,6 @@ public function editGame(){
99
86
100
87
$ id = $ _GET ['id ' ];
101
88
102
- $ title = '' ;
103
- $ pdo = connectDatabase ();
104
- $ pdo ->setAttribute (PDO ::ATTR_ERRMODE , PDO ::ERRMODE_EXCEPTION );
105
-
106
89
if ($ _SERVER ['REQUEST_METHOD ' ] === 'POST ' ) {
107
90
$ name = $ _POST ['name ' ];
108
91
$ entwickler = $ _POST ['entwickler ' ];
@@ -111,7 +94,7 @@ public function editGame(){
111
94
112
95
$ games ->changeGame ($ name , $ entwickler , $ img , $ price , $ id );
113
96
114
- header ('Location: http://localhost/GGames/shop/ store ' );
97
+ header ('Location: http://localhost/GGames/store ' );
115
98
}else {
116
99
$ statement = $ pdo ->prepare ('SELECT * FROM video_game WHERE id = :id ' );
117
100
$ statement ->bindParam (':id ' , $ id );
@@ -130,39 +113,26 @@ public function buyGame(){
130
113
131
114
$ id = $ _GET ['id ' ];
132
115
133
- $ title = '' ;
134
- $ pdo = connectDatabase ();
135
-
136
116
$ games ->getGame ($ _SESSION ['id ' ], $ id );
137
117
138
- header ('Location: http://localhost/GGames/shop/ store ' );
118
+ header ('Location: http://localhost/GGames/store ' );
139
119
140
120
require 'app/Views/store.view.php ' ;
141
121
}
142
122
143
123
public function konto (){
144
- session_start ();
124
+ $ games = new Games ();
145
125
146
- /* Alle Spiele */
147
- $ pdo = connectDatabase ();
148
- $ pdo ->setAttribute (PDO ::ATTR_ERRMODE , PDO ::ERRMODE_EXCEPTION );
126
+ // Initialize the session
127
+ session_start ();
149
128
150
- $ statement = $ pdo ->prepare ("SELECT * FROM users WHERE email = :email " );
151
- $ statement ->bindParam (':email ' , $ _SESSION ['email ' ]);
152
- $ statement ->execute ();
153
- $ konto = $ statement ->fetchAll ();
129
+ /* Alle Informationen des Nutzers holen */
130
+ $ konto = $ games -> getAllDataFromUser ();
131
+ $ konto = $ konto -> fetchAll ();
154
132
155
133
/* Spiele gekauft */
156
- $ pdo = connectDatabase ();
157
- $ pdo ->setAttribute (PDO ::ATTR_ERRMODE , PDO ::ERRMODE_EXCEPTION );
158
-
159
- $ statement = $ pdo ->prepare ("SELECT video_game.name, video_game.entwickler, video_game.img, video_game.price FROM video_game
160
- INNER JOIN kaeufe ON kaeufe.fk_video_gameId = video_game.id
161
- INNER JOIN users ON users.id = kaeufe.fk_usersId WHERE users.id = :fk_usersId " );
162
- $ statement ->bindParam (':fk_usersId ' , $ _SESSION ['id ' ]);
163
- $ statement ->execute ();
164
- $ kaeufe = $ statement ->fetchAll ();
165
-
134
+ $ kaeufe = $ games -> getAllBoughtGames ();
135
+ $ kaeufe = $ kaeufe -> fetchAll ();
166
136
167
137
require 'app/Views/konto.view.php ' ;
168
138
}
@@ -175,22 +145,17 @@ public function editKonto(){
175
145
176
146
$ id = $ _GET ['id ' ];
177
147
178
- $ title = '' ;
179
- $ pdo = connectDatabase ();
180
- $ pdo ->setAttribute (PDO ::ATTR_ERRMODE , PDO ::ERRMODE_EXCEPTION );
181
-
182
148
if ($ _SERVER ['REQUEST_METHOD ' ] === 'POST ' ) {
183
149
$ email = $ _POST ['email ' ];
184
150
$ username = $ _POST ['username ' ];
185
151
186
152
$ games ->changeKonto ($ email , $ username , $ id );
187
153
188
- header ('Location: http://localhost/GGames/shop/ logout ' );
154
+ header ('Location: http://localhost/GGames/logout ' );
189
155
}else {
190
- $ statement = $ pdo ->prepare ('SELECT * FROM users WHERE id = :id ' );
191
- $ statement ->bindParam (':id ' , $ id );
192
- $ statement ->execute ();
193
- $ konto = $ statement ->fetchAll ();
156
+
157
+ $ konto = $ games -> getAllDataFromUser ();
158
+ $ konto = $ konto -> fetchAll ();
194
159
}
195
160
require 'app/Views/editKonto.view.php ' ;
196
161
}
@@ -210,5 +175,4 @@ public function config(){
210
175
public function register (){
211
176
require 'app/Views/register.view.php ' ;
212
177
}
213
- }
214
-
178
+ }
0 commit comments