-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.php
142 lines (108 loc) · 3.75 KB
/
model.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
require_once('database_connector.php');
class model{
public $db;
public function __construct(){
$database = new database_connector();
$this->db = $database->neww_database_connection();
}
public function retrive_all_players(){
$query = '
SELECT p.id , p."first-name" , p."last-name" , p.age , p.price , t.name as team
FROM "player" p , "contract" c , "team" t
WHERE c."team-id" = t.id AND c."player-id" = p.id;
';
return $this->db->query($query);
}
public function retrive_searched_players(){
$query = '
SELECT p.id , p."first-name" , p."last-name" , p.age , p.price , t.name as team
FROM "player" p , "contract" c , "team" t
WHERE c."team-id" = t.id AND c."player-id" = p.id
';
if($_POST['first-name']){
$first_name = $_POST['first-name'];
$query .= "
AND p.\"first-name\" = '$first_name'
";
}
if($_POST['last-name']){
$last_name = $_POST['last-name'];
$query .= "
AND p.\"last-name\" = '$last_name'
";
}
if($_POST['min-age']){
$min_age = $_POST['min-age'];
$query .= "
AND p.\"age\" > $min_age
";
}
if($_POST['max-age']){
$max_age = $_POST['max-age'];
$query .= "
AND p.\"age\" < $max_age
";
}
if($_POST['min-price']){
$min_price = $_POST['min-price'];
$query .= "
AND p.\"price\" > $min_price
";
}
if($_POST['max-price']){
$max_price = $_POST['max-price'];
$query .= "
AND p.\"price\" < $max_price
";
}
if($_POST['team']){
$team = $_POST['team'];
$query .= "
AND t.\"name\" = '$team'
";
}
$query .= ';';
setcookie( 'search_query' , $query , time() + 100 , "/" );
return $this->db->query($query);
}
public function retrive_all_teams(){
$query = '
SELECT t.id , t.name , t.coach , t.captain , t.budget , s.name as stadium
FROM "team" t , "stadium" s
WHERE t.id = s.id;
';
return $this->db->query($query);
}
public function retrive_all_stadiums(){
$query = '
SELECT * FROM "stadium";
';
return $this->db->query($query);
}
public function retrive_all_matches(){
$query = '
SELECT
m.id ,
t1.name AS "home-team" ,
t2.name AS "away-team" ,
m."home-goals" ,
m."away-goals" ,
r."last-name" AS referee ,
s.name AS stadium ,
m."total-attendance"
FROM
"match" m ,
"team" t1 ,
"team" t2 ,
"referee" r ,
"stadium" s
WHERE
m."home-id" = t1.id AND
m."away-id" = t2.id AND
m."referee-id" = r.id AND
m."stadium-id" = s.id;
';
return $this->db->query($query);
}
}