forked from SindreSvendby/tournament-scheduler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tournament_scheduler_loader.php
142 lines (124 loc) · 5.69 KB
/
tournament_scheduler_loader.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
class TournamentSchedulerLoader extends MvcPluginLoader
{
var $db_version = '5.4.2';
var $tables = array();
function activate()
{
// This call needs to be made to activate this app within WP MVC
$this->activate_app(__FILE__);
// Perform any databases modifications related to plugin activation here, if necessary
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
$tournament_scheduler_db_version = 'tournament_scheduler_db_version';
$installed_ver = get_option($tournament_scheduler_db_version);
if ($installed_ver !== $this->db_version) {
$this->updateDatabaseSchema();
if($installed_ver == null) {
add_option($tournament_scheduler_db_version, $this->db_version);
} else {
update_option($tournament_scheduler_db_version, $this->db_version);
}
}
}
public function updateDatabaseSchema()
{
global $wpdb;
$sql = "CREATE TABLE {$wpdb->prefix}tournament_responsibles (
id mediumint(9) NOT NULL PRIMARY KEY AUTO_INCREMENT,
name tinytext NOT NULL,
phone tinytext NOT NULL,
url_to_picture tinytext,
mail tinytext,
UNIQUE KEY id (id)
) DEFAULT CHARACTER SET utf8;";
dbDelta($sql);
$sql = "CREATE TABLE {$wpdb->prefix}locations (
id mediumint(9) NOT NULL PRIMARY KEY AUTO_INCREMENT,
name tinytext NOT NULL,
x mediumint(9),
y mediumint(9),
UNIQUE KEY id (id)
) DEFAULT CHARACTER SET utf8;";
dbDelta($sql);
$sql = "CREATE TABLE {$wpdb->prefix}series (
id mediumint(9) NOT NULL PRIMARY KEY AUTO_INCREMENT,
name tinytext NOT NULL,
rankingleague_id mediumint(9) NOT NULL,
details text,
UNIQUE KEY id (id)
) DEFAULT CHARACTER SET utf8;";
dbDelta($sql);
$sql = "CREATE TABLE {$wpdb->prefix}rankingleagues (
id mediumint(9) NOT NULL PRIMARY KEY AUTO_INCREMENT,
name tinytext NOT NULL,
details text,
UNIQUE KEY id (id)
) DEFAULT CHARACTER SET utf8;";
dbDelta($sql);
$sql = "CREATE TABLE {$wpdb->prefix}teams (
id mediumint(9) NOT NULL PRIMARY KEY AUTO_INCREMENT,
name mediumint(9) NOT NULL,
UNIQUE KEY id (id)
) DEFAULT CHARACTER SET utf8;";
dbDelta($sql);
$sql = "CREATE TABLE {$wpdb->prefix}playersinteam (
id mediumint(9) NOT NULL PRIMARY KEY AUTO_INCREMENT,
team_id mediumint(9) NOT NULL,
player_id mediumint(9) NOT NULL,
UNIQUE KEY id (id),
UNIQUE KEY (team_id, player_id)
) DEFAULT CHARACTER SET utf8;";
dbDelta($sql);
$sql = "CREATE TABLE {$wpdb->prefix}matches (
id mediumint(9) NOT NULL PRIMARY KEY AUTO_INCREMENT,
tournament_id mediumint(9) NOT NULL,
team1_id mediumint(9) NOT NULL,
team2_id mediumint(9) NOT NULL,
winner_id mediumint(9),
team1_sett1 int,
team1_sett2 int,
team1_sett3 int,
team2_sett1 int,
team2_sett2 int,
team2_sett3 int,
walkover boolean default false,
walkover_comment text,
description text,
UNIQUE KEY id (id)
) DEFAULT CHARACTER SET utf8;";
dbDelta($sql);
$sql = "CREATE TABLE {$wpdb->prefix}results (
id mediumint(9) NOT NULL PRIMARY KEY AUTO_INCREMENT,
tournament_id mediumint(9) NOT NULL,
team_id mediumint(9) NOT NULL,
points mediumint(9) NOT NULL,
place mediumint(9) NOT NULL,
signedUpBy mediumint(9),
signedUpDate time default CURRENT_TIMESTAMP,
comment text,
UNIQUE KEY id (id)
) DEFAULT CHARACTER SET utf8;";
dbDelta($sql);
$sql = "CREATE TABLE {$wpdb->prefix}tournaments (
id mediumint(9) NOT NULL PRIMARY KEY AUTO_INCREMENT,
name tinytext NOT NULL,
serie_id mediumint(9) NOT NULL,
date datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
location_id mediumint(9) NOT NULL,
details text,
final_seeding text,
price int(11) NOT NULL,
tournament_responsible_id mediumint(9) NOT NULL,
maximum_teams int(11) NOT NULL,
UNIQUE KEY id (id)
) DEFAULT CHARACTER SET utf8;";
dbDelta($sql);
}
function deactivate()
{
// This call needs to be made to deactivate this app within WP MVC
$this->deactivate_app(__FILE__);
// Perform any databases modifications related to plugin deactivation here, if necessary
}
}
?>