Newer
Older
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
<?php
class DB
{
private static $db;
function __construct()
{
try
{
self::$db = new PDO(
"mysql:host=localhost;dbname=roadmap",
"root",
"",
array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8'"));
self::createTables();
}
catch(PDOException $e)
{
die($e);
}
}
function createTables()
{
$statement = self::$db->prepare("CREATE TABLE IF NOT EXISTS `roadmaps` ( `ID` int(10) unsigned NOT NULL AUTO_INCREMENT, `Projectname` text COLLATE utf8_general_ci NOT NULL, PRIMARY KEY (`ID`))ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci AUTO_INCREMENT=1;");
$statement->execute();
$statement = self::$db->prepare("CREATE TABLE IF NOT EXISTS `milestones` (".
"`ID` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,".
"`RoadmapID` int(10) UNSIGNED NOT NULL,".
"`VersionCode` int(10) UNSIGNED NOT NULL,".
"`VersionName` text COLLATE utf8_general_ci NOT NULL,".
"`Title` text COLLATE utf8_general_ci NOT NULL,".
"`DueDate` date NOT NULL,".
"`CompletionDate` date NOT NULL,".
"`Status` int(11) NOT NULL,".
"PRIMARY KEY (`ID`)".
") ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci AUTO_INCREMENT=1;");
$statement->execute();
$statement = self::$db->prepare("CREATE TABLE IF NOT EXISTS `tasks` (".
"`ID` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,".
"`MilestoneID` int(10) UNSIGNED NOT NULL,".
"`Title` text CHARACTER SET utf8 NOT NULL,".
"`Description` text CHARACTER SET utf8 NOT NULL,".
"`Status` int(11) NOT NULL,".
"PRIMARY KEY (`ID`)".
") ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci AUTO_INCREMENT=1;");
$statement->execute();
$statement = self::$db->prepare("CREATE TABLE IF NOT EXISTS `subtasks` (".
"`ID` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,".
"`TaskID` int(10) UNSIGNED NOT NULL,".
"`Title` text CHARACTER SET utf8 NOT NULL,".
"`Description` text CHARACTER SET utf8 NOT NULL,".
"`Status` int(11) NOT NULL,".
"PRIMARY KEY (`ID`)".
") ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci AUTO_INCREMENT=1;");
$statement->execute();
}
//========================================
//---------------- insert ----------------
//========================================
function insertRoadmap($projectName)
{
$statement = self::$db->prepare("INSERT INTO roadmaps VALUES('', :projectName);");
$statement->bindParam("projectName", $projectName);
return $statement->execute();
}
function insertMilestone($roadmapID, $versionCode, $versionName, $title, $dueDate)
{
$completionDate = "2000-01-01";
$status = "0";
$statement = self::$db->prepare("INSERT INTO milestones VALUES('', :roadmapID, :versionCode, :versionName, :title, :dueDate, :completionDate, :status);");
$statement->bindParam("roadmapID", $roadmapID);
$statement->bindParam("versionCode", $versionCode);
$statement->bindParam("versionName", $versionName);
$statement->bindParam("title", $title);
$statement->bindParam("dueDate", $dueDate);
$statement->bindParam("completionDate", $completionDate);
$statement->bindParam("status", $status);
return $statement->execute();
}
function insertTask($milestoneID, $title, $description)
{
$status = "0";
$statement = self::$db->prepare("INSERT INTO tasks VALUES('', :milestoneID, :title, :description, :status);");
$statement->bindParam("milestoneID", $milestoneID);
$statement->bindParam("title", $title);
$statement->bindParam("description", $description);
$statement->bindParam("status", $status);
return $statement->execute();
}
function insertSubtask($taskID, $title, $description)
{
$status = "0";
$statement = self::$db->prepare("INSERT INTO subtasks VALUES('', :taskID, :title, :description, :status);");
$statement->bindParam("taskID", $taskID);
$statement->bindParam("title", $title);
$statement->bindParam("description", $description);
$statement->bindParam("status", $status);
return $statement->execute();
}
//========================================
//---------------- finish ----------------
//========================================
function finishMilestone($milestoneID)
{
$statement = self::$db->prepare("UPDATE milestones SET status='1' WHERE ID = :milestoneID;");
$statement->bindParam("milestoneID", $milestoneID);
return $statement->execute();
}
function finishTask($taskID)
{
$statement = self::$db->prepare("UPDATE tasks SET status='1' WHERE ID = :taskID;");
$statement->bindParam("taskID", $taskID);
return $statement->execute();
}
function finishSubTask($subtaskID)
{
$statement = self::$db->prepare("UPDATE subtasks SET status='1' WHERE ID = :subtaskID;");
$statement->bindParam("subtaskID", $subtaskID);
return $statement->execute();
}
//========================================
//---------------- update ----------------
//========================================
function updateRoadmap($roadmapID, $projectName)
{
$statement = self::$db->prepare("UPDATE roadmaps SET Projectname = :projectName WHERE ID = :roadmapID;");
$statement->bindParam("roadmapID", $roadmapID);
$statement->bindParam("projectName", $projectName);
return $statement->execute();
}
function updateMilestone($milestoneID, $roadmapID, $versionCode, $versionName, $title, $dueDate, $completionDate, $status)
{
$statement = self::$db->prepare("UPDATE milestones SET RoadmapID = :roadmapID, VersionCode = :versionCode, VersionName = :versionName, Title = :title, DueDate = :dueDate, CompletionDate = :completionDate, Status = :status WHERE ID = :milestoneID;");
$statement->bindParam("milestoneID", $milestoneID);
$statement->bindParam("roadmapID", $roadmapID);
$statement->bindParam("versionCode", $versionCode);
$statement->bindParam("versionName", $versionName);
$statement->bindParam("title", $title);
$statement->bindParam("dueDate", $dueDate);
$statement->bindParam("completionDate", $completionDate);
$statement->bindParam("status", $status);
return $statement->execute();
}
function updateTask($taskID, $milestoneID, $title, $description, $status)
{
$statement = self::$db->prepare("UPDATE tasks SET MilestoneID = :milestoneID, Title = :title, Description = :description, Status = :status WHERE ID = :taskID;");
$statement->bindParam("taskID", $taskID);
$statement->bindParam("milestoneID", $milestoneID);
$statement->bindParam("title", $title);
$statement->bindParam("description", $description);
$statement->bindParam("status", $status);
return $statement->execute();
}
function updateSubtask($subtaskID, $taskID, $title, $description, $status)
{
$statement = self::$db->prepare("UPDATE subtasks SET TaskID = :taskID, Title = :title, Description = :description, Status = :status WHERE ID = :subtaskID;");
$statement->bindParam("subtaskID", $subtaskID);
$statement->bindParam("taskID", $taskID);
$statement->bindParam("milestoneID", $milestoneID);
$statement->bindParam("title", $title);
$statement->bindParam("description", $description);
$statement->bindParam("status", $status);
return $statement->execute();
}
//========================================
//----------------- get ------------------
//========================================
function getRoadmap($roadmapID)
{
$statement = self::$db->prepare("SELECT Projectname FROM roadmaps WHERE roadmaps.ID=:roadmapID;");
$statement->bindParam("roadmapID", $roadmapID);
$statement->execute();
return $statement->fetch();
}
function getMilestones($roadmapID)
{
$statement = self::$db->prepare("SELECT * FROM milestones WHERE milestones.roadmapID=:roadmapID;");
$statement->bindParam("roadmapID", $roadmapID);
$statement->execute();
return $statement->fetchAll();
}
function getTasks($milestoneID)
{
$statement = self::$db->prepare("SELECT * FROM tasks WHERE tasks.milestoneID=:milestoneID;");
$statement->bindParam("milestoneID", $milestoneID);
$statement->execute();
return $statement->fetchAll();
}
function getSubtasks($taskID)
{
$statement = self::$db->prepare("SELECT * FROM subtasks WHERE subtasks.taskID=:taskID;");
$statement->bindParam("taskID", $taskID);
$statement->execute();
return $statement->fetchAll();
}
}
$db = new DB();
$db->createTables();
$objects = $db->getMilestones(1);
foreach ($objects as $object)
{
var_dump($object);
echo "<br> <br>";
}