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
|
<?php
/**
* Created by PhpStorm.
* User: brolaugh
* Date: 2/25/16
* Time: 9:22 PM
*/
namespace App\database;
class Select extends dbSetup
{
public function __destruct() {
parent::__destruct();
}
public function getTaskWithStatus($taskID)
{
$stmt = $this->getDb()->prepare("SELECT * FROM task_with_status WHERE id = ?");
$stmt->bind_param('i', $taskID);
$stmt->execute();
$res = $stmt->get_result();
$retval = $res->fetch_object();
$stmt->close();
return $retval;
}
public function getLastTask(){
$stmt = $this->getDb()->prepare("SELECT * FROM last_task_with_status");
$stmt->execute();
$res = $stmt->get_result();
$retval = $res->fetch_object();
$stmt->close();
return $retval;
}
/**
* @return object array
*/
public function getAllTasksWithStatus()
{
$stmt = $this->getDb()->prepare("SELECT * FROM task_with_status ORDER BY stamp desc");
$stmt->execute();
$res = $stmt->get_result();
$a = array();
while ($row = $res->fetch_object()) {
array_push($a, $row);
}
$stmt->close();
return $a;
}
public function getAllStatusLevels()
{
$stmt = $this->getDb()->prepare("SELECT * FROM status_level");
$stmt->execute();
$res = $stmt->get_result();
$a = array();
while ($row = $res->fetch_object()) {
array_push($a, $row);
}
$stmt->close();
return $a;
}
/**
* @param int array $taskID
*/
public function getTasksWithFollowingStatus($taskID=array(1)){
$query = "SELECT task_with_status.id as id, title, description, user, level, stamp, task_with_status.style_class as style_class, status_level.id as level_id FROM `task_with_status` LEFT JOIN status_level ON task_with_status.level=status_level.plain_text ";
$param = "";
$secondParam = $taskID;
if (count($taskID) > 0) {
$query .= " WHERE status_level.id IN(";
for ($i = 0; $i < count($taskID); $i++) {
if ($i != (count($taskID) - 1)){
$query .= "?,";
$param .= "i";
}
else{
$query .= "?";
$param .= "i";
}
}
$query .= ") ORDER BY stamp desc";
}
array_unshift($secondParam, $param);
$stmt = $this->getDb()->prepare($query);
call_user_func_array(array($stmt, "bind_param"), $this->makeValuesReferenced($secondParam));
$stmt->execute();
$res = $stmt->get_result();
$a = array();
while($row = $res->fetch_object()){
$a[] = $row;
}
return $a;
}
public function getTaskStatusHistory($taskID){
$stmt = $this->getDb()->prepare("SELECT user, stamp, plain_text, style_class FROM task_history WHERE task = ?");
$stmt->bind_param('i', $taskID);
$stmt->execute();
$res = $stmt->get_result();
$a = [];
while($row = $res->fetch_object){
$a[] = $row;
}
return $a;
}
}
|